isomorphic-git 1.41.7 → 1.41.8

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
@@ -109,7 +109,7 @@ import git from 'isomorphic-git'
109
109
  // or
110
110
  import * as git from 'isomorphic-git'
111
111
  // or
112
- import {plugins, clone, commit, push} from 'isomorphic-git'
112
+ import {add, clone, commit, push} from 'isomorphic-git'
113
113
  ```
114
114
 
115
115
  View the full [Getting Started guide](https://isomorphic-git.github.io/docs/quickstart.html) on the docs website.
package/index.cjs CHANGED
@@ -2365,6 +2365,38 @@ class GitRefManager {
2365
2365
  throw new NotFoundError(ref)
2366
2366
  }
2367
2367
 
2368
+ /**
2369
+ * Checks whether a ref names the branch HEAD points at in a repository where
2370
+ * that branch has no commits yet.
2371
+ *
2372
+ * A repository created by `git init` has a HEAD pointing at a branch that
2373
+ * does not exist on disk. Resolving that branch fails the same way resolving
2374
+ * a misspelled ref does, so callers that want to treat the two differently
2375
+ * need this to tell them apart.
2376
+ *
2377
+ * @param {Object} args
2378
+ * @param {FSClient} args.fs - A file system implementation.
2379
+ * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
2380
+ * @param {string} args.ref - The ref to check.
2381
+ * @returns {Promise<boolean>} - True if the ref names an unborn branch.
2382
+ */
2383
+ static async isUnbornBranch({ fs, gitdir, ref }) {
2384
+ let target;
2385
+ try {
2386
+ // depth 2 stops at the symbolic target instead of following it to an oid.
2387
+ target = await GitRefManager.resolve({
2388
+ fs,
2389
+ gitdir,
2390
+ ref: 'HEAD',
2391
+ depth: 2,
2392
+ });
2393
+ } catch (_) {
2394
+ return false
2395
+ }
2396
+ if (!target.startsWith('refs/heads/')) return false
2397
+ return ref === 'HEAD' || refpaths(ref).includes(target)
2398
+ }
2399
+
2368
2400
  /**
2369
2401
  * Checks if a ref exists.
2370
2402
  *
@@ -4544,9 +4576,16 @@ class GitWalkerRepo {
4544
4576
  try {
4545
4577
  oid = await GitRefManager.resolve({ fs, gitdir, ref });
4546
4578
  } catch (e) {
4547
- if (e instanceof NotFoundError) {
4548
- // Handle fresh branches with no commits
4579
+ // Only a branch that has no commits yet gets the empty tree. Anything
4580
+ // else that fails to resolve is a ref the caller got wrong, and
4581
+ // swallowing it here would walk an empty tree instead of saying so.
4582
+ if (
4583
+ e instanceof NotFoundError &&
4584
+ (await GitRefManager.isUnbornBranch({ fs, gitdir, ref }))
4585
+ ) {
4549
4586
  oid = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
4587
+ } else {
4588
+ throw e
4550
4589
  }
4551
4590
  }
4552
4591
  const tree = await resolveTree({ fs, cache: this.cache, gitdir, oid });
@@ -9728,8 +9767,8 @@ function filterCapabilities(server, client) {
9728
9767
 
9729
9768
  const pkg = {
9730
9769
  name: 'isomorphic-git',
9731
- version: '1.41.7',
9732
- agent: 'git/isomorphic-git@1.41.7',
9770
+ version: '1.41.8',
9771
+ agent: 'git/isomorphic-git@1.41.8',
9733
9772
  };
9734
9773
 
9735
9774
  class FIFO {
package/index.js CHANGED
@@ -2358,6 +2358,38 @@ class GitRefManager {
2358
2358
  throw new NotFoundError(ref)
2359
2359
  }
2360
2360
 
2361
+ /**
2362
+ * Checks whether a ref names the branch HEAD points at in a repository where
2363
+ * that branch has no commits yet.
2364
+ *
2365
+ * A repository created by `git init` has a HEAD pointing at a branch that
2366
+ * does not exist on disk. Resolving that branch fails the same way resolving
2367
+ * a misspelled ref does, so callers that want to treat the two differently
2368
+ * need this to tell them apart.
2369
+ *
2370
+ * @param {Object} args
2371
+ * @param {FSClient} args.fs - A file system implementation.
2372
+ * @param {string} [args.gitdir=join(dir, '.git')] - [required] The [git directory](dir-vs-gitdir.md) path
2373
+ * @param {string} args.ref - The ref to check.
2374
+ * @returns {Promise<boolean>} - True if the ref names an unborn branch.
2375
+ */
2376
+ static async isUnbornBranch({ fs, gitdir, ref }) {
2377
+ let target;
2378
+ try {
2379
+ // depth 2 stops at the symbolic target instead of following it to an oid.
2380
+ target = await GitRefManager.resolve({
2381
+ fs,
2382
+ gitdir,
2383
+ ref: 'HEAD',
2384
+ depth: 2,
2385
+ });
2386
+ } catch (_) {
2387
+ return false
2388
+ }
2389
+ if (!target.startsWith('refs/heads/')) return false
2390
+ return ref === 'HEAD' || refpaths(ref).includes(target)
2391
+ }
2392
+
2361
2393
  /**
2362
2394
  * Checks if a ref exists.
2363
2395
  *
@@ -4531,9 +4563,16 @@ class GitWalkerRepo {
4531
4563
  try {
4532
4564
  oid = await GitRefManager.resolve({ fs, gitdir, ref });
4533
4565
  } catch (e) {
4534
- if (e instanceof NotFoundError) {
4535
- // Handle fresh branches with no commits
4566
+ // Only a branch that has no commits yet gets the empty tree. Anything
4567
+ // else that fails to resolve is a ref the caller got wrong, and
4568
+ // swallowing it here would walk an empty tree instead of saying so.
4569
+ if (
4570
+ e instanceof NotFoundError &&
4571
+ (await GitRefManager.isUnbornBranch({ fs, gitdir, ref }))
4572
+ ) {
4536
4573
  oid = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
4574
+ } else {
4575
+ throw e
4537
4576
  }
4538
4577
  }
4539
4578
  const tree = await resolveTree({ fs, cache: this.cache, gitdir, oid });
@@ -9715,8 +9754,8 @@ function filterCapabilities(server, client) {
9715
9754
 
9716
9755
  const pkg = {
9717
9756
  name: 'isomorphic-git',
9718
- version: '1.41.7',
9719
- agent: 'git/isomorphic-git@1.41.7',
9757
+ version: '1.41.8',
9758
+ agent: 'git/isomorphic-git@1.41.8',
9720
9759
  };
9721
9760
 
9722
9761
  class FIFO {