isomorphic-git 1.13.1 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -139,7 +139,7 @@ unless there is a major version bump.
139
139
  <!-- prettier-ignore-start -->
140
140
  <!-- markdownlint-disable -->
141
141
 
142
- <!-- autogenerated_by: __tests__/__helpers__/generate-docs.js -->
142
+ <!-- autogenerated_by: __tests__/__helpers__/generate-docs.cjs -->
143
143
 
144
144
  - [add](https://isomorphic-git.github.io/docs/add.html)
145
145
  - [addNote](https://isomorphic-git.github.io/docs/addNote.html)
@@ -340,6 +340,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
340
340
  <td align="center"><a href="https://github.com/mtlewis"><img src="https://avatars.githubusercontent.com/u/542836?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Mike Lewis</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=mtlewis" title="Documentation">📖</a></td>
341
341
  <td align="center"><a href="https://twitter.com/SamVerschueren"><img src="https://avatars.githubusercontent.com/u/1913805?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Sam Verschueren</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=SamVerschueren" title="Code">💻</a></td>
342
342
  <td align="center"><a href="http://vitorluizc.github.io/"><img src="https://avatars.githubusercontent.com/u/9027363?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Vitor Luiz Cavalcanti</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=VitorLuizC" title="Documentation">📖</a></td>
343
+ <td align="center"><a href="https://www.platformdemos.com/"><img src="https://avatars.githubusercontent.com/u/4261788?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Shane McLaughlin</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=mshanemc" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=mshanemc" title="Documentation">📖</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=mshanemc" title="Tests">⚠️</a></td>
343
344
  </tr>
344
345
  </table>
345
346
 
package/index.cjs CHANGED
@@ -871,7 +871,7 @@ class GitIndexManager {
871
871
  const filepath = `${gitdir}/index`;
872
872
  if (lock === null) lock = new AsyncLock({ maxPending: Infinity });
873
873
  let result;
874
- await lock.acquire(filepath, async function() {
874
+ await lock.acquire(filepath, async () => {
875
875
  // Acquire a file lock while we're reading the index
876
876
  // to make sure other processes aren't writing to it
877
877
  // simultaneously, which could result in a corrupted index.
@@ -891,6 +891,7 @@ class GitIndexManager {
891
891
  index._dirty = false;
892
892
  }
893
893
  });
894
+
894
895
  return result
895
896
  }
896
897
  }
@@ -4022,6 +4023,23 @@ function WORKDIR() {
4022
4023
 
4023
4024
  // @ts-check
4024
4025
 
4026
+ class MultipleGitError extends BaseError {
4027
+ /**
4028
+ * @param {Error[]} errors
4029
+ * @param {string} message
4030
+ */
4031
+ constructor(errors) {
4032
+ super(
4033
+ `There are multiple errors that were thrown by the method. Please refer to the "errors" property to see more`
4034
+ );
4035
+ this.code = this.name = MultipleGitError.code;
4036
+ this.data = { errors };
4037
+ this.errors = errors;
4038
+ }
4039
+ }
4040
+ /** @type {'MultipleGitError'} */
4041
+ MultipleGitError.code = 'MultipleGitError';
4042
+
4025
4043
  // I'm putting this in a Manager because I reckon it could benefit
4026
4044
  // from a LOT of cacheing.
4027
4045
  class GitIgnoreManager {
@@ -4412,12 +4430,6 @@ function assertParameter(name, value) {
4412
4430
  }
4413
4431
  }
4414
4432
 
4415
- function posixifyPathBuffer(buffer) {
4416
- let idx;
4417
- while (~(idx = buffer.indexOf(92))) buffer[idx] = 47;
4418
- return buffer
4419
- }
4420
-
4421
4433
  // @ts-check
4422
4434
 
4423
4435
  /**
@@ -4427,7 +4439,7 @@ function posixifyPathBuffer(buffer) {
4427
4439
  * @param {FsClient} args.fs - a file system implementation
4428
4440
  * @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
4429
4441
  * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
4430
- * @param {string} args.filepath - The path to the file to add to the index
4442
+ * @param {string|string[]} args.filepath - The path to the file to add to the index
4431
4443
  * @param {object} [args.cache] - a [cache](cache.md) object
4432
4444
  *
4433
4445
  * @returns {Promise<void>} Resolves successfully once the git index has been updated
@@ -4449,11 +4461,11 @@ async function add({
4449
4461
  assertParameter('fs', _fs);
4450
4462
  assertParameter('dir', dir);
4451
4463
  assertParameter('gitdir', gitdir);
4452
- assertParameter('filepath', filepath);
4464
+ assertParameter('filepaths', filepath);
4453
4465
 
4454
4466
  const fs = new FileSystem(_fs);
4455
- await GitIndexManager.acquire({ fs, gitdir, cache }, async function(index) {
4456
- await addToIndex({ dir, gitdir, fs, filepath, index });
4467
+ await GitIndexManager.acquire({ fs, gitdir, cache }, async index => {
4468
+ return addToIndex({ dir, gitdir, fs, filepath, index })
4457
4469
  });
4458
4470
  } catch (err) {
4459
4471
  err.caller = 'git.add';
@@ -4463,29 +4475,56 @@ async function add({
4463
4475
 
4464
4476
  async function addToIndex({ dir, gitdir, fs, filepath, index }) {
4465
4477
  // TODO: Should ignore UNLESS it's already in the index.
4466
- const ignored = await GitIgnoreManager.isIgnored({
4467
- fs,
4468
- dir,
4469
- gitdir,
4470
- filepath,
4478
+ filepath = Array.isArray(filepath) ? filepath : [filepath];
4479
+ const promises = filepath.map(async currentFilepath => {
4480
+ const ignored = await GitIgnoreManager.isIgnored({
4481
+ fs,
4482
+ dir,
4483
+ gitdir,
4484
+ filepath: currentFilepath,
4485
+ });
4486
+ if (ignored) return
4487
+ const stats = await fs.lstat(join(dir, currentFilepath));
4488
+ if (!stats) throw new NotFoundError(currentFilepath)
4489
+
4490
+ if (stats.isDirectory()) {
4491
+ const children = await fs.readdir(join(dir, currentFilepath));
4492
+ const promises = children.map(child =>
4493
+ addToIndex({
4494
+ dir,
4495
+ gitdir,
4496
+ fs,
4497
+ filepath: [join(currentFilepath, child)],
4498
+ index,
4499
+ })
4500
+ );
4501
+ await Promise.all(promises);
4502
+ } else {
4503
+ const object = stats.isSymbolicLink()
4504
+ ? await fs.readlink(join(dir, currentFilepath))
4505
+ : await fs.read(join(dir, currentFilepath));
4506
+ if (object === null) throw new NotFoundError(currentFilepath)
4507
+ const oid = await _writeObject({ fs, gitdir, type: 'blob', object });
4508
+ index.insert({ filepath: currentFilepath, stats, oid });
4509
+ }
4471
4510
  });
4472
- if (ignored) return
4473
- const stats = await fs.lstat(join(dir, filepath));
4474
- if (!stats) throw new NotFoundError(filepath)
4475
- if (stats.isDirectory()) {
4476
- const children = await fs.readdir(join(dir, filepath));
4477
- const promises = children.map(child =>
4478
- addToIndex({ dir, gitdir, fs, filepath: join(filepath, child), index })
4479
- );
4480
- await Promise.all(promises);
4481
- } else {
4482
- const object = stats.isSymbolicLink()
4483
- ? await fs.readlink(join(dir, filepath)).then(posixifyPathBuffer)
4484
- : await fs.read(join(dir, filepath));
4485
- if (object === null) throw new NotFoundError(filepath)
4486
- const oid = await _writeObject({ fs, gitdir, type: 'blob', object });
4487
- index.insert({ filepath, stats, oid });
4511
+
4512
+ const settledPromises = await Promise.allSettled(promises);
4513
+ const rejectedPromises = settledPromises
4514
+ .filter(settle => settle.status === 'rejected')
4515
+ .map(settle => settle.reason);
4516
+ if (rejectedPromises.length > 1) {
4517
+ throw new MultipleGitError(rejectedPromises)
4518
+ }
4519
+ if (rejectedPromises.length === 1) {
4520
+ throw rejectedPromises[0]
4488
4521
  }
4522
+
4523
+ const fulfilledPromises = settledPromises
4524
+ .filter(settle => settle.status === 'fulfilled' && settle.value)
4525
+ .map(settle => settle.value);
4526
+
4527
+ return fulfilledPromises
4489
4528
  }
4490
4529
 
4491
4530
  // @ts-check
@@ -5840,7 +5879,7 @@ async function analyze({
5840
5879
 
5841
5880
  // This is a kind of silly pattern but it worked so well for me in the past
5842
5881
  // and it makes intuitively demonstrating exhaustiveness so *easy*.
5843
- // This checks for the presense and/or absense of each of the 3 entries,
5882
+ // This checks for the presense and/or absence of each of the 3 entries,
5844
5883
  // converts that to a 3-bit binary representation, and then handles
5845
5884
  // every possible combination (2^3 or 8 cases) with a lookup table.
5846
5885
  const key = [!!stage, !!commit, !!workdir].map(Number).join('');
@@ -6873,8 +6912,8 @@ function filterCapabilities(server, client) {
6873
6912
 
6874
6913
  const pkg = {
6875
6914
  name: 'isomorphic-git',
6876
- version: '1.13.1',
6877
- agent: 'git/isomorphic-git@1.13.1',
6915
+ version: '1.14.0',
6916
+ agent: 'git/isomorphic-git@1.14.0',
6878
6917
  };
6879
6918
 
6880
6919
  class FIFO {
package/index.d.ts CHANGED
@@ -751,7 +751,7 @@ export function WORKDIR(): Walker;
751
751
  * @param {FsClient} args.fs - a file system implementation
752
752
  * @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
753
753
  * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
754
- * @param {string} args.filepath - The path to the file to add to the index
754
+ * @param {string|string[]} args.filepath - The path to the file to add to the index
755
755
  * @param {object} [args.cache] - a [cache](cache.md) object
756
756
  *
757
757
  * @returns {Promise<void>} Resolves successfully once the git index has been updated
@@ -766,7 +766,7 @@ export function add({ fs: _fs, dir, gitdir, filepath, cache, }: {
766
766
  fs: CallbackFsClient | PromiseFsClient;
767
767
  dir: string;
768
768
  gitdir?: string;
769
- filepath: string;
769
+ filepath: string | string[];
770
770
  cache?: any;
771
771
  }): Promise<void>;
772
772
  /**
package/index.js CHANGED
@@ -865,7 +865,7 @@ class GitIndexManager {
865
865
  const filepath = `${gitdir}/index`;
866
866
  if (lock === null) lock = new AsyncLock({ maxPending: Infinity });
867
867
  let result;
868
- await lock.acquire(filepath, async function() {
868
+ await lock.acquire(filepath, async () => {
869
869
  // Acquire a file lock while we're reading the index
870
870
  // to make sure other processes aren't writing to it
871
871
  // simultaneously, which could result in a corrupted index.
@@ -885,6 +885,7 @@ class GitIndexManager {
885
885
  index._dirty = false;
886
886
  }
887
887
  });
888
+
888
889
  return result
889
890
  }
890
891
  }
@@ -4016,6 +4017,23 @@ function WORKDIR() {
4016
4017
 
4017
4018
  // @ts-check
4018
4019
 
4020
+ class MultipleGitError extends BaseError {
4021
+ /**
4022
+ * @param {Error[]} errors
4023
+ * @param {string} message
4024
+ */
4025
+ constructor(errors) {
4026
+ super(
4027
+ `There are multiple errors that were thrown by the method. Please refer to the "errors" property to see more`
4028
+ );
4029
+ this.code = this.name = MultipleGitError.code;
4030
+ this.data = { errors };
4031
+ this.errors = errors;
4032
+ }
4033
+ }
4034
+ /** @type {'MultipleGitError'} */
4035
+ MultipleGitError.code = 'MultipleGitError';
4036
+
4019
4037
  // I'm putting this in a Manager because I reckon it could benefit
4020
4038
  // from a LOT of cacheing.
4021
4039
  class GitIgnoreManager {
@@ -4406,12 +4424,6 @@ function assertParameter(name, value) {
4406
4424
  }
4407
4425
  }
4408
4426
 
4409
- function posixifyPathBuffer(buffer) {
4410
- let idx;
4411
- while (~(idx = buffer.indexOf(92))) buffer[idx] = 47;
4412
- return buffer
4413
- }
4414
-
4415
4427
  // @ts-check
4416
4428
 
4417
4429
  /**
@@ -4421,7 +4433,7 @@ function posixifyPathBuffer(buffer) {
4421
4433
  * @param {FsClient} args.fs - a file system implementation
4422
4434
  * @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
4423
4435
  * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
4424
- * @param {string} args.filepath - The path to the file to add to the index
4436
+ * @param {string|string[]} args.filepath - The path to the file to add to the index
4425
4437
  * @param {object} [args.cache] - a [cache](cache.md) object
4426
4438
  *
4427
4439
  * @returns {Promise<void>} Resolves successfully once the git index has been updated
@@ -4443,11 +4455,11 @@ async function add({
4443
4455
  assertParameter('fs', _fs);
4444
4456
  assertParameter('dir', dir);
4445
4457
  assertParameter('gitdir', gitdir);
4446
- assertParameter('filepath', filepath);
4458
+ assertParameter('filepaths', filepath);
4447
4459
 
4448
4460
  const fs = new FileSystem(_fs);
4449
- await GitIndexManager.acquire({ fs, gitdir, cache }, async function(index) {
4450
- await addToIndex({ dir, gitdir, fs, filepath, index });
4461
+ await GitIndexManager.acquire({ fs, gitdir, cache }, async index => {
4462
+ return addToIndex({ dir, gitdir, fs, filepath, index })
4451
4463
  });
4452
4464
  } catch (err) {
4453
4465
  err.caller = 'git.add';
@@ -4457,29 +4469,56 @@ async function add({
4457
4469
 
4458
4470
  async function addToIndex({ dir, gitdir, fs, filepath, index }) {
4459
4471
  // TODO: Should ignore UNLESS it's already in the index.
4460
- const ignored = await GitIgnoreManager.isIgnored({
4461
- fs,
4462
- dir,
4463
- gitdir,
4464
- filepath,
4472
+ filepath = Array.isArray(filepath) ? filepath : [filepath];
4473
+ const promises = filepath.map(async currentFilepath => {
4474
+ const ignored = await GitIgnoreManager.isIgnored({
4475
+ fs,
4476
+ dir,
4477
+ gitdir,
4478
+ filepath: currentFilepath,
4479
+ });
4480
+ if (ignored) return
4481
+ const stats = await fs.lstat(join(dir, currentFilepath));
4482
+ if (!stats) throw new NotFoundError(currentFilepath)
4483
+
4484
+ if (stats.isDirectory()) {
4485
+ const children = await fs.readdir(join(dir, currentFilepath));
4486
+ const promises = children.map(child =>
4487
+ addToIndex({
4488
+ dir,
4489
+ gitdir,
4490
+ fs,
4491
+ filepath: [join(currentFilepath, child)],
4492
+ index,
4493
+ })
4494
+ );
4495
+ await Promise.all(promises);
4496
+ } else {
4497
+ const object = stats.isSymbolicLink()
4498
+ ? await fs.readlink(join(dir, currentFilepath))
4499
+ : await fs.read(join(dir, currentFilepath));
4500
+ if (object === null) throw new NotFoundError(currentFilepath)
4501
+ const oid = await _writeObject({ fs, gitdir, type: 'blob', object });
4502
+ index.insert({ filepath: currentFilepath, stats, oid });
4503
+ }
4465
4504
  });
4466
- if (ignored) return
4467
- const stats = await fs.lstat(join(dir, filepath));
4468
- if (!stats) throw new NotFoundError(filepath)
4469
- if (stats.isDirectory()) {
4470
- const children = await fs.readdir(join(dir, filepath));
4471
- const promises = children.map(child =>
4472
- addToIndex({ dir, gitdir, fs, filepath: join(filepath, child), index })
4473
- );
4474
- await Promise.all(promises);
4475
- } else {
4476
- const object = stats.isSymbolicLink()
4477
- ? await fs.readlink(join(dir, filepath)).then(posixifyPathBuffer)
4478
- : await fs.read(join(dir, filepath));
4479
- if (object === null) throw new NotFoundError(filepath)
4480
- const oid = await _writeObject({ fs, gitdir, type: 'blob', object });
4481
- index.insert({ filepath, stats, oid });
4505
+
4506
+ const settledPromises = await Promise.allSettled(promises);
4507
+ const rejectedPromises = settledPromises
4508
+ .filter(settle => settle.status === 'rejected')
4509
+ .map(settle => settle.reason);
4510
+ if (rejectedPromises.length > 1) {
4511
+ throw new MultipleGitError(rejectedPromises)
4512
+ }
4513
+ if (rejectedPromises.length === 1) {
4514
+ throw rejectedPromises[0]
4482
4515
  }
4516
+
4517
+ const fulfilledPromises = settledPromises
4518
+ .filter(settle => settle.status === 'fulfilled' && settle.value)
4519
+ .map(settle => settle.value);
4520
+
4521
+ return fulfilledPromises
4483
4522
  }
4484
4523
 
4485
4524
  // @ts-check
@@ -5834,7 +5873,7 @@ async function analyze({
5834
5873
 
5835
5874
  // This is a kind of silly pattern but it worked so well for me in the past
5836
5875
  // and it makes intuitively demonstrating exhaustiveness so *easy*.
5837
- // This checks for the presense and/or absense of each of the 3 entries,
5876
+ // This checks for the presense and/or absence of each of the 3 entries,
5838
5877
  // converts that to a 3-bit binary representation, and then handles
5839
5878
  // every possible combination (2^3 or 8 cases) with a lookup table.
5840
5879
  const key = [!!stage, !!commit, !!workdir].map(Number).join('');
@@ -6867,8 +6906,8 @@ function filterCapabilities(server, client) {
6867
6906
 
6868
6907
  const pkg = {
6869
6908
  name: 'isomorphic-git',
6870
- version: '1.13.1',
6871
- agent: 'git/isomorphic-git@1.13.1',
6909
+ version: '1.14.0',
6910
+ agent: 'git/isomorphic-git@1.14.0',
6872
6911
  };
6873
6912
 
6874
6913
  class FIFO {
@@ -751,7 +751,7 @@ export function WORKDIR(): Walker;
751
751
  * @param {FsClient} args.fs - a file system implementation
752
752
  * @param {string} args.dir - The [working tree](dir-vs-gitdir.md) directory path
753
753
  * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
754
- * @param {string} args.filepath - The path to the file to add to the index
754
+ * @param {string|string[]} args.filepath - The path to the file to add to the index
755
755
  * @param {object} [args.cache] - a [cache](cache.md) object
756
756
  *
757
757
  * @returns {Promise<void>} Resolves successfully once the git index has been updated
@@ -766,7 +766,7 @@ export function add({ fs: _fs, dir, gitdir, filepath, cache, }: {
766
766
  fs: CallbackFsClient | PromiseFsClient;
767
767
  dir: string;
768
768
  gitdir?: string;
769
- filepath: string;
769
+ filepath: string | string[];
770
770
  cache?: any;
771
771
  }): Promise<void>;
772
772
  /**