isomorphic-git 1.44.14 → 1.44.16

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.
@@ -712,57 +712,75 @@ function dirname(path) {
712
712
  }
713
713
 
714
714
  /*!
715
- * This code for `path.join` is directly copied from @zenfs/core/path for bundle size improvements.
716
- * SPDX-License-Identifier: LGPL-3.0-or-later
717
- * Copyright (c) James Prevett and other ZenFS contributors.
715
+ * The POSIX core below - `assertPath`, `normalizeStringPosix` and the body of
716
+ * `normalize` - comes from path-browserify, which extracted it from Node.js.
717
+ * Reformatted to this project's style (`const`/`let`, no semicolons); the
718
+ * algorithm is unchanged.
718
719
  *
719
- * Windows support added:
720
+ * SPDX-License-Identifier: MIT
721
+ * Copyright (c) 2013 James Halliday
722
+ * Copyright Joyent, Inc. and other Node contributors.
723
+ *
724
+ * @see https://github.com/browserify/path-browserify
725
+ *
726
+ * The Windows handling is this project's own, added in #2302. path-browserify
727
+ * is the POSIX part of `path` only, so `normalize` and `join` are wrapped with:
720
728
  * - Backslashes are normalised to forward slashes before processing.
721
729
  * - Drive-letter prefixes (e.g. "C:") are detected and preserved through
722
730
  * normalisation, so absolute Windows paths are handled correctly.
723
- * - An absolute argument passed to join() resets the accumulated path,
731
+ * - A drive-letter argument passed to join() resets the accumulated path,
724
732
  * matching Node behaviour and handling worktree gitdir paths properly.
725
733
  *
726
734
  * Limitation: UNC paths (e.g. \\server\share) are not supported. The leading
727
735
  * backslashes are normalised to forward slashes and then collapsed by
728
- * normalizeString, losing the UNC root. Git on Windows works with
736
+ * normalizeStringPosix, losing the UNC root. Git on Windows works with
729
737
  * drive-letter paths, so this is not expected to be a practical issue.
730
738
  */
731
739
 
732
- function normalizeString(path, aar) {
740
+ function assertPath(path) {
741
+ if (typeof path !== 'string') {
742
+ throw new TypeError(
743
+ 'Path must be a string. Received ' + JSON.stringify(path)
744
+ )
745
+ }
746
+ }
747
+
748
+ // Resolves . and .. elements in a path with directory names
749
+ function normalizeStringPosix(path, allowAboveRoot) {
733
750
  let res = '';
734
751
  let lastSegmentLength = 0;
735
752
  let lastSlash = -1;
736
753
  let dots = 0;
737
- let char = '\x00';
754
+ let code;
738
755
  for (let i = 0; i <= path.length; ++i) {
739
- if (i < path.length) char = path[i];
740
- else if (char === '/') break
741
- else char = '/';
742
-
743
- if (char === '/') {
756
+ if (i < path.length) code = path.charCodeAt(i);
757
+ else if (code === 47 /* / */) break
758
+ else code = 47; /* / */
759
+ if (code === 47 /* / */) {
744
760
  if (lastSlash === i - 1 || dots === 1) {
745
761
  // NOOP
746
- } else if (dots === 2) {
762
+ } else if (lastSlash !== i - 1 && dots === 2) {
747
763
  if (
748
764
  res.length < 2 ||
749
765
  lastSegmentLength !== 2 ||
750
- res.at(-1) !== '.' ||
751
- res.at(-2) !== '.'
766
+ res.charCodeAt(res.length - 1) !== 46 /* . */ ||
767
+ res.charCodeAt(res.length - 2) !== 46 /* . */
752
768
  ) {
753
769
  if (res.length > 2) {
754
770
  const lastSlashIndex = res.lastIndexOf('/');
755
- if (lastSlashIndex === -1) {
756
- res = '';
757
- lastSegmentLength = 0;
758
- } else {
759
- res = res.slice(0, lastSlashIndex);
760
- lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
771
+ if (lastSlashIndex !== res.length - 1) {
772
+ if (lastSlashIndex === -1) {
773
+ res = '';
774
+ lastSegmentLength = 0;
775
+ } else {
776
+ res = res.slice(0, lastSlashIndex);
777
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
778
+ }
779
+ lastSlash = i;
780
+ dots = 0;
781
+ continue
761
782
  }
762
- lastSlash = i;
763
- dots = 0;
764
- continue
765
- } else if (res.length !== 0) {
783
+ } else if (res.length === 2 || res.length === 1) {
766
784
  res = '';
767
785
  lastSegmentLength = 0;
768
786
  lastSlash = i;
@@ -770,8 +788,9 @@ function normalizeString(path, aar) {
770
788
  continue
771
789
  }
772
790
  }
773
- if (aar) {
774
- res += res.length > 0 ? '/..' : '..';
791
+ if (allowAboveRoot) {
792
+ if (res.length > 0) res += '/..';
793
+ else res = '..';
775
794
  lastSegmentLength = 2;
776
795
  }
777
796
  } else {
@@ -781,7 +800,7 @@ function normalizeString(path, aar) {
781
800
  }
782
801
  lastSlash = i;
783
802
  dots = 0;
784
- } else if (char === '.' && dots !== -1) {
803
+ } else if (code === 46 /* . */ && dots !== -1) {
785
804
  ++dots;
786
805
  } else {
787
806
  dots = -1;
@@ -799,7 +818,9 @@ function getWindowsDrivePrefix(path) {
799
818
  }
800
819
 
801
820
  function normalize(path) {
802
- if (!path.length) return '.'
821
+ assertPath(path);
822
+
823
+ if (path.length === 0) return '.'
803
824
 
804
825
  // Normalise backslashes to forward slashes before any other processing.
805
826
  path = path.replace(/\\/g, '/');
@@ -807,26 +828,19 @@ function normalize(path) {
807
828
  const drivePrefix = getWindowsDrivePrefix(path);
808
829
  // isAbsolute: Unix root ('/foo') OR Windows drive+slash ('C:/foo').
809
830
  const isAbsolute =
810
- path[0] === '/' || (drivePrefix !== null && path[2] === '/');
811
- const trailingSeparator = path.at(-1) === '/';
812
-
813
- // Strip the drive prefix before feeding into normalizeString so that the
814
- // core algorithm only ever sees a plain POSIX-style string.
815
- const pathBody = drivePrefix ? path.slice(2) : path;
816
-
817
- let normalized = normalizeString(pathBody, !isAbsolute);
831
+ path.charCodeAt(0) === 47 /* / */ ||
832
+ (drivePrefix !== null && path.charCodeAt(2) === 47); /* / */
833
+ const trailingSeparator = path.charCodeAt(path.length - 1) === 47; /* / */
834
+
835
+ // Strip the drive prefix before normalizing so that the core algorithm only
836
+ // ever sees a plain POSIX-style string.
837
+ let normalized = normalizeStringPosix(
838
+ drivePrefix ? path.slice(2) : path,
839
+ !isAbsolute
840
+ );
818
841
 
819
- if (!normalized.length) {
820
- const root = drivePrefix
821
- ? isAbsolute
822
- ? drivePrefix + '/'
823
- : drivePrefix
824
- : isAbsolute
825
- ? '/'
826
- : '.';
827
- return trailingSeparator && !isAbsolute ? root + '/' : root
828
- }
829
- if (trailingSeparator) normalized += '/';
842
+ if (normalized.length === 0 && !isAbsolute) normalized = '.';
843
+ if (normalized.length > 0 && trailingSeparator) normalized += '/';
830
844
 
831
845
  if (drivePrefix) {
832
846
  return isAbsolute
@@ -840,19 +854,21 @@ function join(...args) {
840
854
  if (args.length === 0) return '.'
841
855
  let joined;
842
856
  for (let i = 0; i < args.length; ++i) {
857
+ assertPath(args[i]);
843
858
  // Normalise separators before processing.
844
859
  const arg = args[i].replace(/\\/g, '/');
845
860
  if (arg.length === 0) continue
846
861
 
847
862
  // A Windows drive-letter path (e.g. "C:/worktrees/foo") cannot be
848
863
  // meaningfully appended to any base, so it resets the accumulator.
849
- // Unix absolute paths (leading '/') are NOT reset here — that would be
864
+ // Unix absolute paths (leading '/') are NOT reset here - that would be
850
865
  // path.resolve() semantics; path.join('foo', '/bar') must yield 'foo/bar'.
851
866
  if (/^[a-zA-Z]:\//.test(arg)) {
852
867
  joined = arg;
868
+ } else if (joined === undefined) {
869
+ joined = arg;
853
870
  } else {
854
- if (joined === undefined) joined = arg;
855
- else joined += '/' + arg;
871
+ joined += '/' + arg;
856
872
  }
857
873
  }
858
874
  if (joined === undefined) return '.'
@@ -1896,16 +1912,45 @@ class GitPackedRefs {
1896
1912
  }
1897
1913
 
1898
1914
  class GitRefSpec {
1899
- constructor({ remotePath, localPath, force, matchPrefix }) {
1915
+ constructor({
1916
+ remotePath,
1917
+ remoteSuffix = '',
1918
+ localPath,
1919
+ force,
1920
+ matchPrefix,
1921
+ negative = false,
1922
+ }) {
1900
1923
  Object.assign(this, {
1901
1924
  remotePath,
1925
+ remoteSuffix,
1902
1926
  localPath,
1903
1927
  force,
1904
1928
  matchPrefix,
1929
+ negative,
1905
1930
  });
1906
1931
  }
1907
1932
 
1908
1933
  static from(refspec) {
1934
+ // A negative refspec like `^refs/heads/tmp/*` excludes the refs it matches,
1935
+ // and a refspec without a destination like `refs/heads/main` doesn't store
1936
+ // the ref locally.
1937
+ if (refspec.startsWith('^') || !refspec.includes(':')) {
1938
+ const negative = refspec.startsWith('^');
1939
+ const [, forceMatch, remote] = refspec
1940
+ .slice(negative ? 1 : 0)
1941
+ .match(/^(\+?)(.*)$/);
1942
+ // The `*` of a pattern can be followed by the rest of the name, like
1943
+ // `refs/heads/*-tmp`.
1944
+ const star = remote.indexOf('*');
1945
+ return new GitRefSpec({
1946
+ remotePath: star === -1 ? remote : remote.slice(0, star),
1947
+ remoteSuffix: star === -1 ? '' : remote.slice(star + 1),
1948
+ localPath: null,
1949
+ force: forceMatch === '+',
1950
+ matchPrefix: star !== -1,
1951
+ negative,
1952
+ })
1953
+ }
1909
1954
  const [forceMatch, remotePath, remoteGlobMatch, localPath, localGlobMatch] =
1910
1955
  refspec.match(/^(\+?)(.*?)(\*?):(.*?)(\*?)$/).slice(1);
1911
1956
  const force = forceMatch === '+';
@@ -1925,7 +1970,19 @@ class GitRefSpec {
1925
1970
  // TODO: We need to run resolveRef on both paths to expand them to their full name.
1926
1971
  }
1927
1972
 
1973
+ matches(remoteBranch) {
1974
+ // Like canonical git, the `*` matches any part of the name, even an empty
1975
+ // one, as long as the prefix and the suffix don't overlap.
1976
+ return this.matchPrefix
1977
+ ? remoteBranch.length >=
1978
+ this.remotePath.length + this.remoteSuffix.length &&
1979
+ remoteBranch.startsWith(this.remotePath) &&
1980
+ remoteBranch.endsWith(this.remoteSuffix)
1981
+ : remoteBranch === this.remotePath
1982
+ }
1983
+
1928
1984
  translate(remoteBranch) {
1985
+ if (this.localPath === null) return null
1929
1986
  if (this.matchPrefix) {
1930
1987
  if (remoteBranch.startsWith(this.remotePath)) {
1931
1988
  return this.localPath + remoteBranch.replace(this.remotePath, '')
@@ -1937,6 +1994,7 @@ class GitRefSpec {
1937
1994
  }
1938
1995
 
1939
1996
  reverseTranslate(localBranch) {
1997
+ if (this.localPath === null) return null
1940
1998
  if (this.matchPrefix) {
1941
1999
  if (localBranch.startsWith(this.localPath)) {
1942
2000
  return this.remotePath + localBranch.replace(this.localPath, '')
@@ -1966,10 +2024,15 @@ class GitRefSpecSet {
1966
2024
  this.rules.push(rule);
1967
2025
  }
1968
2026
 
2027
+ isExcluded(remoteRef) {
2028
+ return this.rules.some(rule => rule.negative && rule.matches(remoteRef))
2029
+ }
2030
+
1969
2031
  translate(remoteRefs) {
1970
2032
  const result = [];
1971
2033
  for (const rule of this.rules) {
1972
2034
  for (const remoteRef of remoteRefs) {
2035
+ if (this.isExcluded(remoteRef)) continue
1973
2036
  const localRef = rule.translate(remoteRef);
1974
2037
  if (localRef) {
1975
2038
  result.push([remoteRef, localRef]);
@@ -1981,6 +2044,7 @@ class GitRefSpecSet {
1981
2044
 
1982
2045
  translateOne(remoteRef) {
1983
2046
  let result = null;
2047
+ if (this.isExcluded(remoteRef)) return result
1984
2048
  for (const rule of this.rules) {
1985
2049
  const localRef = rule.translate(remoteRef);
1986
2050
  if (localRef) {
@@ -1992,7 +2056,7 @@ class GitRefSpecSet {
1992
2056
 
1993
2057
  localNamespaces() {
1994
2058
  return this.rules
1995
- .filter(rule => rule.matchPrefix)
2059
+ .filter(rule => rule.matchPrefix && rule.localPath !== null)
1996
2060
  .map(rule => rule.localPath.replace(/\/$/, ''))
1997
2061
  }
1998
2062
  }
package/managers/index.js CHANGED
@@ -706,57 +706,75 @@ function dirname(path) {
706
706
  }
707
707
 
708
708
  /*!
709
- * This code for `path.join` is directly copied from @zenfs/core/path for bundle size improvements.
710
- * SPDX-License-Identifier: LGPL-3.0-or-later
711
- * Copyright (c) James Prevett and other ZenFS contributors.
709
+ * The POSIX core below - `assertPath`, `normalizeStringPosix` and the body of
710
+ * `normalize` - comes from path-browserify, which extracted it from Node.js.
711
+ * Reformatted to this project's style (`const`/`let`, no semicolons); the
712
+ * algorithm is unchanged.
712
713
  *
713
- * Windows support added:
714
+ * SPDX-License-Identifier: MIT
715
+ * Copyright (c) 2013 James Halliday
716
+ * Copyright Joyent, Inc. and other Node contributors.
717
+ *
718
+ * @see https://github.com/browserify/path-browserify
719
+ *
720
+ * The Windows handling is this project's own, added in #2302. path-browserify
721
+ * is the POSIX part of `path` only, so `normalize` and `join` are wrapped with:
714
722
  * - Backslashes are normalised to forward slashes before processing.
715
723
  * - Drive-letter prefixes (e.g. "C:") are detected and preserved through
716
724
  * normalisation, so absolute Windows paths are handled correctly.
717
- * - An absolute argument passed to join() resets the accumulated path,
725
+ * - A drive-letter argument passed to join() resets the accumulated path,
718
726
  * matching Node behaviour and handling worktree gitdir paths properly.
719
727
  *
720
728
  * Limitation: UNC paths (e.g. \\server\share) are not supported. The leading
721
729
  * backslashes are normalised to forward slashes and then collapsed by
722
- * normalizeString, losing the UNC root. Git on Windows works with
730
+ * normalizeStringPosix, losing the UNC root. Git on Windows works with
723
731
  * drive-letter paths, so this is not expected to be a practical issue.
724
732
  */
725
733
 
726
- function normalizeString(path, aar) {
734
+ function assertPath(path) {
735
+ if (typeof path !== 'string') {
736
+ throw new TypeError(
737
+ 'Path must be a string. Received ' + JSON.stringify(path)
738
+ )
739
+ }
740
+ }
741
+
742
+ // Resolves . and .. elements in a path with directory names
743
+ function normalizeStringPosix(path, allowAboveRoot) {
727
744
  let res = '';
728
745
  let lastSegmentLength = 0;
729
746
  let lastSlash = -1;
730
747
  let dots = 0;
731
- let char = '\x00';
748
+ let code;
732
749
  for (let i = 0; i <= path.length; ++i) {
733
- if (i < path.length) char = path[i];
734
- else if (char === '/') break
735
- else char = '/';
736
-
737
- if (char === '/') {
750
+ if (i < path.length) code = path.charCodeAt(i);
751
+ else if (code === 47 /* / */) break
752
+ else code = 47; /* / */
753
+ if (code === 47 /* / */) {
738
754
  if (lastSlash === i - 1 || dots === 1) {
739
755
  // NOOP
740
- } else if (dots === 2) {
756
+ } else if (lastSlash !== i - 1 && dots === 2) {
741
757
  if (
742
758
  res.length < 2 ||
743
759
  lastSegmentLength !== 2 ||
744
- res.at(-1) !== '.' ||
745
- res.at(-2) !== '.'
760
+ res.charCodeAt(res.length - 1) !== 46 /* . */ ||
761
+ res.charCodeAt(res.length - 2) !== 46 /* . */
746
762
  ) {
747
763
  if (res.length > 2) {
748
764
  const lastSlashIndex = res.lastIndexOf('/');
749
- if (lastSlashIndex === -1) {
750
- res = '';
751
- lastSegmentLength = 0;
752
- } else {
753
- res = res.slice(0, lastSlashIndex);
754
- lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
765
+ if (lastSlashIndex !== res.length - 1) {
766
+ if (lastSlashIndex === -1) {
767
+ res = '';
768
+ lastSegmentLength = 0;
769
+ } else {
770
+ res = res.slice(0, lastSlashIndex);
771
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
772
+ }
773
+ lastSlash = i;
774
+ dots = 0;
775
+ continue
755
776
  }
756
- lastSlash = i;
757
- dots = 0;
758
- continue
759
- } else if (res.length !== 0) {
777
+ } else if (res.length === 2 || res.length === 1) {
760
778
  res = '';
761
779
  lastSegmentLength = 0;
762
780
  lastSlash = i;
@@ -764,8 +782,9 @@ function normalizeString(path, aar) {
764
782
  continue
765
783
  }
766
784
  }
767
- if (aar) {
768
- res += res.length > 0 ? '/..' : '..';
785
+ if (allowAboveRoot) {
786
+ if (res.length > 0) res += '/..';
787
+ else res = '..';
769
788
  lastSegmentLength = 2;
770
789
  }
771
790
  } else {
@@ -775,7 +794,7 @@ function normalizeString(path, aar) {
775
794
  }
776
795
  lastSlash = i;
777
796
  dots = 0;
778
- } else if (char === '.' && dots !== -1) {
797
+ } else if (code === 46 /* . */ && dots !== -1) {
779
798
  ++dots;
780
799
  } else {
781
800
  dots = -1;
@@ -793,7 +812,9 @@ function getWindowsDrivePrefix(path) {
793
812
  }
794
813
 
795
814
  function normalize(path) {
796
- if (!path.length) return '.'
815
+ assertPath(path);
816
+
817
+ if (path.length === 0) return '.'
797
818
 
798
819
  // Normalise backslashes to forward slashes before any other processing.
799
820
  path = path.replace(/\\/g, '/');
@@ -801,26 +822,19 @@ function normalize(path) {
801
822
  const drivePrefix = getWindowsDrivePrefix(path);
802
823
  // isAbsolute: Unix root ('/foo') OR Windows drive+slash ('C:/foo').
803
824
  const isAbsolute =
804
- path[0] === '/' || (drivePrefix !== null && path[2] === '/');
805
- const trailingSeparator = path.at(-1) === '/';
806
-
807
- // Strip the drive prefix before feeding into normalizeString so that the
808
- // core algorithm only ever sees a plain POSIX-style string.
809
- const pathBody = drivePrefix ? path.slice(2) : path;
810
-
811
- let normalized = normalizeString(pathBody, !isAbsolute);
825
+ path.charCodeAt(0) === 47 /* / */ ||
826
+ (drivePrefix !== null && path.charCodeAt(2) === 47); /* / */
827
+ const trailingSeparator = path.charCodeAt(path.length - 1) === 47; /* / */
828
+
829
+ // Strip the drive prefix before normalizing so that the core algorithm only
830
+ // ever sees a plain POSIX-style string.
831
+ let normalized = normalizeStringPosix(
832
+ drivePrefix ? path.slice(2) : path,
833
+ !isAbsolute
834
+ );
812
835
 
813
- if (!normalized.length) {
814
- const root = drivePrefix
815
- ? isAbsolute
816
- ? drivePrefix + '/'
817
- : drivePrefix
818
- : isAbsolute
819
- ? '/'
820
- : '.';
821
- return trailingSeparator && !isAbsolute ? root + '/' : root
822
- }
823
- if (trailingSeparator) normalized += '/';
836
+ if (normalized.length === 0 && !isAbsolute) normalized = '.';
837
+ if (normalized.length > 0 && trailingSeparator) normalized += '/';
824
838
 
825
839
  if (drivePrefix) {
826
840
  return isAbsolute
@@ -834,19 +848,21 @@ function join(...args) {
834
848
  if (args.length === 0) return '.'
835
849
  let joined;
836
850
  for (let i = 0; i < args.length; ++i) {
851
+ assertPath(args[i]);
837
852
  // Normalise separators before processing.
838
853
  const arg = args[i].replace(/\\/g, '/');
839
854
  if (arg.length === 0) continue
840
855
 
841
856
  // A Windows drive-letter path (e.g. "C:/worktrees/foo") cannot be
842
857
  // meaningfully appended to any base, so it resets the accumulator.
843
- // Unix absolute paths (leading '/') are NOT reset here — that would be
858
+ // Unix absolute paths (leading '/') are NOT reset here - that would be
844
859
  // path.resolve() semantics; path.join('foo', '/bar') must yield 'foo/bar'.
845
860
  if (/^[a-zA-Z]:\//.test(arg)) {
846
861
  joined = arg;
862
+ } else if (joined === undefined) {
863
+ joined = arg;
847
864
  } else {
848
- if (joined === undefined) joined = arg;
849
- else joined += '/' + arg;
865
+ joined += '/' + arg;
850
866
  }
851
867
  }
852
868
  if (joined === undefined) return '.'
@@ -1890,16 +1906,45 @@ class GitPackedRefs {
1890
1906
  }
1891
1907
 
1892
1908
  class GitRefSpec {
1893
- constructor({ remotePath, localPath, force, matchPrefix }) {
1909
+ constructor({
1910
+ remotePath,
1911
+ remoteSuffix = '',
1912
+ localPath,
1913
+ force,
1914
+ matchPrefix,
1915
+ negative = false,
1916
+ }) {
1894
1917
  Object.assign(this, {
1895
1918
  remotePath,
1919
+ remoteSuffix,
1896
1920
  localPath,
1897
1921
  force,
1898
1922
  matchPrefix,
1923
+ negative,
1899
1924
  });
1900
1925
  }
1901
1926
 
1902
1927
  static from(refspec) {
1928
+ // A negative refspec like `^refs/heads/tmp/*` excludes the refs it matches,
1929
+ // and a refspec without a destination like `refs/heads/main` doesn't store
1930
+ // the ref locally.
1931
+ if (refspec.startsWith('^') || !refspec.includes(':')) {
1932
+ const negative = refspec.startsWith('^');
1933
+ const [, forceMatch, remote] = refspec
1934
+ .slice(negative ? 1 : 0)
1935
+ .match(/^(\+?)(.*)$/);
1936
+ // The `*` of a pattern can be followed by the rest of the name, like
1937
+ // `refs/heads/*-tmp`.
1938
+ const star = remote.indexOf('*');
1939
+ return new GitRefSpec({
1940
+ remotePath: star === -1 ? remote : remote.slice(0, star),
1941
+ remoteSuffix: star === -1 ? '' : remote.slice(star + 1),
1942
+ localPath: null,
1943
+ force: forceMatch === '+',
1944
+ matchPrefix: star !== -1,
1945
+ negative,
1946
+ })
1947
+ }
1903
1948
  const [forceMatch, remotePath, remoteGlobMatch, localPath, localGlobMatch] =
1904
1949
  refspec.match(/^(\+?)(.*?)(\*?):(.*?)(\*?)$/).slice(1);
1905
1950
  const force = forceMatch === '+';
@@ -1919,7 +1964,19 @@ class GitRefSpec {
1919
1964
  // TODO: We need to run resolveRef on both paths to expand them to their full name.
1920
1965
  }
1921
1966
 
1967
+ matches(remoteBranch) {
1968
+ // Like canonical git, the `*` matches any part of the name, even an empty
1969
+ // one, as long as the prefix and the suffix don't overlap.
1970
+ return this.matchPrefix
1971
+ ? remoteBranch.length >=
1972
+ this.remotePath.length + this.remoteSuffix.length &&
1973
+ remoteBranch.startsWith(this.remotePath) &&
1974
+ remoteBranch.endsWith(this.remoteSuffix)
1975
+ : remoteBranch === this.remotePath
1976
+ }
1977
+
1922
1978
  translate(remoteBranch) {
1979
+ if (this.localPath === null) return null
1923
1980
  if (this.matchPrefix) {
1924
1981
  if (remoteBranch.startsWith(this.remotePath)) {
1925
1982
  return this.localPath + remoteBranch.replace(this.remotePath, '')
@@ -1931,6 +1988,7 @@ class GitRefSpec {
1931
1988
  }
1932
1989
 
1933
1990
  reverseTranslate(localBranch) {
1991
+ if (this.localPath === null) return null
1934
1992
  if (this.matchPrefix) {
1935
1993
  if (localBranch.startsWith(this.localPath)) {
1936
1994
  return this.remotePath + localBranch.replace(this.localPath, '')
@@ -1960,10 +2018,15 @@ class GitRefSpecSet {
1960
2018
  this.rules.push(rule);
1961
2019
  }
1962
2020
 
2021
+ isExcluded(remoteRef) {
2022
+ return this.rules.some(rule => rule.negative && rule.matches(remoteRef))
2023
+ }
2024
+
1963
2025
  translate(remoteRefs) {
1964
2026
  const result = [];
1965
2027
  for (const rule of this.rules) {
1966
2028
  for (const remoteRef of remoteRefs) {
2029
+ if (this.isExcluded(remoteRef)) continue
1967
2030
  const localRef = rule.translate(remoteRef);
1968
2031
  if (localRef) {
1969
2032
  result.push([remoteRef, localRef]);
@@ -1975,6 +2038,7 @@ class GitRefSpecSet {
1975
2038
 
1976
2039
  translateOne(remoteRef) {
1977
2040
  let result = null;
2041
+ if (this.isExcluded(remoteRef)) return result
1978
2042
  for (const rule of this.rules) {
1979
2043
  const localRef = rule.translate(remoteRef);
1980
2044
  if (localRef) {
@@ -1986,7 +2050,7 @@ class GitRefSpecSet {
1986
2050
 
1987
2051
  localNamespaces() {
1988
2052
  return this.rules
1989
- .filter(rule => rule.matchPrefix)
2053
+ .filter(rule => rule.matchPrefix && rule.localPath !== null)
1990
2054
  .map(rule => rule.localPath.replace(/\/$/, ''))
1991
2055
  }
1992
2056
  }