isomorphic-git 1.44.14 → 1.44.15

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.
@@ -1896,16 +1896,45 @@ class GitPackedRefs {
1896
1896
  }
1897
1897
 
1898
1898
  class GitRefSpec {
1899
- constructor({ remotePath, localPath, force, matchPrefix }) {
1899
+ constructor({
1900
+ remotePath,
1901
+ remoteSuffix = '',
1902
+ localPath,
1903
+ force,
1904
+ matchPrefix,
1905
+ negative = false,
1906
+ }) {
1900
1907
  Object.assign(this, {
1901
1908
  remotePath,
1909
+ remoteSuffix,
1902
1910
  localPath,
1903
1911
  force,
1904
1912
  matchPrefix,
1913
+ negative,
1905
1914
  });
1906
1915
  }
1907
1916
 
1908
1917
  static from(refspec) {
1918
+ // A negative refspec like `^refs/heads/tmp/*` excludes the refs it matches,
1919
+ // and a refspec without a destination like `refs/heads/main` doesn't store
1920
+ // the ref locally.
1921
+ if (refspec.startsWith('^') || !refspec.includes(':')) {
1922
+ const negative = refspec.startsWith('^');
1923
+ const [, forceMatch, remote] = refspec
1924
+ .slice(negative ? 1 : 0)
1925
+ .match(/^(\+?)(.*)$/);
1926
+ // The `*` of a pattern can be followed by the rest of the name, like
1927
+ // `refs/heads/*-tmp`.
1928
+ const star = remote.indexOf('*');
1929
+ return new GitRefSpec({
1930
+ remotePath: star === -1 ? remote : remote.slice(0, star),
1931
+ remoteSuffix: star === -1 ? '' : remote.slice(star + 1),
1932
+ localPath: null,
1933
+ force: forceMatch === '+',
1934
+ matchPrefix: star !== -1,
1935
+ negative,
1936
+ })
1937
+ }
1909
1938
  const [forceMatch, remotePath, remoteGlobMatch, localPath, localGlobMatch] =
1910
1939
  refspec.match(/^(\+?)(.*?)(\*?):(.*?)(\*?)$/).slice(1);
1911
1940
  const force = forceMatch === '+';
@@ -1925,7 +1954,19 @@ class GitRefSpec {
1925
1954
  // TODO: We need to run resolveRef on both paths to expand them to their full name.
1926
1955
  }
1927
1956
 
1957
+ matches(remoteBranch) {
1958
+ // Like canonical git, the `*` matches any part of the name, even an empty
1959
+ // one, as long as the prefix and the suffix don't overlap.
1960
+ return this.matchPrefix
1961
+ ? remoteBranch.length >=
1962
+ this.remotePath.length + this.remoteSuffix.length &&
1963
+ remoteBranch.startsWith(this.remotePath) &&
1964
+ remoteBranch.endsWith(this.remoteSuffix)
1965
+ : remoteBranch === this.remotePath
1966
+ }
1967
+
1928
1968
  translate(remoteBranch) {
1969
+ if (this.localPath === null) return null
1929
1970
  if (this.matchPrefix) {
1930
1971
  if (remoteBranch.startsWith(this.remotePath)) {
1931
1972
  return this.localPath + remoteBranch.replace(this.remotePath, '')
@@ -1937,6 +1978,7 @@ class GitRefSpec {
1937
1978
  }
1938
1979
 
1939
1980
  reverseTranslate(localBranch) {
1981
+ if (this.localPath === null) return null
1940
1982
  if (this.matchPrefix) {
1941
1983
  if (localBranch.startsWith(this.localPath)) {
1942
1984
  return this.remotePath + localBranch.replace(this.localPath, '')
@@ -1966,10 +2008,15 @@ class GitRefSpecSet {
1966
2008
  this.rules.push(rule);
1967
2009
  }
1968
2010
 
2011
+ isExcluded(remoteRef) {
2012
+ return this.rules.some(rule => rule.negative && rule.matches(remoteRef))
2013
+ }
2014
+
1969
2015
  translate(remoteRefs) {
1970
2016
  const result = [];
1971
2017
  for (const rule of this.rules) {
1972
2018
  for (const remoteRef of remoteRefs) {
2019
+ if (this.isExcluded(remoteRef)) continue
1973
2020
  const localRef = rule.translate(remoteRef);
1974
2021
  if (localRef) {
1975
2022
  result.push([remoteRef, localRef]);
@@ -1981,6 +2028,7 @@ class GitRefSpecSet {
1981
2028
 
1982
2029
  translateOne(remoteRef) {
1983
2030
  let result = null;
2031
+ if (this.isExcluded(remoteRef)) return result
1984
2032
  for (const rule of this.rules) {
1985
2033
  const localRef = rule.translate(remoteRef);
1986
2034
  if (localRef) {
@@ -1992,7 +2040,7 @@ class GitRefSpecSet {
1992
2040
 
1993
2041
  localNamespaces() {
1994
2042
  return this.rules
1995
- .filter(rule => rule.matchPrefix)
2043
+ .filter(rule => rule.matchPrefix && rule.localPath !== null)
1996
2044
  .map(rule => rule.localPath.replace(/\/$/, ''))
1997
2045
  }
1998
2046
  }
package/managers/index.js CHANGED
@@ -1890,16 +1890,45 @@ class GitPackedRefs {
1890
1890
  }
1891
1891
 
1892
1892
  class GitRefSpec {
1893
- constructor({ remotePath, localPath, force, matchPrefix }) {
1893
+ constructor({
1894
+ remotePath,
1895
+ remoteSuffix = '',
1896
+ localPath,
1897
+ force,
1898
+ matchPrefix,
1899
+ negative = false,
1900
+ }) {
1894
1901
  Object.assign(this, {
1895
1902
  remotePath,
1903
+ remoteSuffix,
1896
1904
  localPath,
1897
1905
  force,
1898
1906
  matchPrefix,
1907
+ negative,
1899
1908
  });
1900
1909
  }
1901
1910
 
1902
1911
  static from(refspec) {
1912
+ // A negative refspec like `^refs/heads/tmp/*` excludes the refs it matches,
1913
+ // and a refspec without a destination like `refs/heads/main` doesn't store
1914
+ // the ref locally.
1915
+ if (refspec.startsWith('^') || !refspec.includes(':')) {
1916
+ const negative = refspec.startsWith('^');
1917
+ const [, forceMatch, remote] = refspec
1918
+ .slice(negative ? 1 : 0)
1919
+ .match(/^(\+?)(.*)$/);
1920
+ // The `*` of a pattern can be followed by the rest of the name, like
1921
+ // `refs/heads/*-tmp`.
1922
+ const star = remote.indexOf('*');
1923
+ return new GitRefSpec({
1924
+ remotePath: star === -1 ? remote : remote.slice(0, star),
1925
+ remoteSuffix: star === -1 ? '' : remote.slice(star + 1),
1926
+ localPath: null,
1927
+ force: forceMatch === '+',
1928
+ matchPrefix: star !== -1,
1929
+ negative,
1930
+ })
1931
+ }
1903
1932
  const [forceMatch, remotePath, remoteGlobMatch, localPath, localGlobMatch] =
1904
1933
  refspec.match(/^(\+?)(.*?)(\*?):(.*?)(\*?)$/).slice(1);
1905
1934
  const force = forceMatch === '+';
@@ -1919,7 +1948,19 @@ class GitRefSpec {
1919
1948
  // TODO: We need to run resolveRef on both paths to expand them to their full name.
1920
1949
  }
1921
1950
 
1951
+ matches(remoteBranch) {
1952
+ // Like canonical git, the `*` matches any part of the name, even an empty
1953
+ // one, as long as the prefix and the suffix don't overlap.
1954
+ return this.matchPrefix
1955
+ ? remoteBranch.length >=
1956
+ this.remotePath.length + this.remoteSuffix.length &&
1957
+ remoteBranch.startsWith(this.remotePath) &&
1958
+ remoteBranch.endsWith(this.remoteSuffix)
1959
+ : remoteBranch === this.remotePath
1960
+ }
1961
+
1922
1962
  translate(remoteBranch) {
1963
+ if (this.localPath === null) return null
1923
1964
  if (this.matchPrefix) {
1924
1965
  if (remoteBranch.startsWith(this.remotePath)) {
1925
1966
  return this.localPath + remoteBranch.replace(this.remotePath, '')
@@ -1931,6 +1972,7 @@ class GitRefSpec {
1931
1972
  }
1932
1973
 
1933
1974
  reverseTranslate(localBranch) {
1975
+ if (this.localPath === null) return null
1934
1976
  if (this.matchPrefix) {
1935
1977
  if (localBranch.startsWith(this.localPath)) {
1936
1978
  return this.remotePath + localBranch.replace(this.localPath, '')
@@ -1960,10 +2002,15 @@ class GitRefSpecSet {
1960
2002
  this.rules.push(rule);
1961
2003
  }
1962
2004
 
2005
+ isExcluded(remoteRef) {
2006
+ return this.rules.some(rule => rule.negative && rule.matches(remoteRef))
2007
+ }
2008
+
1963
2009
  translate(remoteRefs) {
1964
2010
  const result = [];
1965
2011
  for (const rule of this.rules) {
1966
2012
  for (const remoteRef of remoteRefs) {
2013
+ if (this.isExcluded(remoteRef)) continue
1967
2014
  const localRef = rule.translate(remoteRef);
1968
2015
  if (localRef) {
1969
2016
  result.push([remoteRef, localRef]);
@@ -1975,6 +2022,7 @@ class GitRefSpecSet {
1975
2022
 
1976
2023
  translateOne(remoteRef) {
1977
2024
  let result = null;
2025
+ if (this.isExcluded(remoteRef)) return result
1978
2026
  for (const rule of this.rules) {
1979
2027
  const localRef = rule.translate(remoteRef);
1980
2028
  if (localRef) {
@@ -1986,7 +2034,7 @@ class GitRefSpecSet {
1986
2034
 
1987
2035
  localNamespaces() {
1988
2036
  return this.rules
1989
- .filter(rule => rule.matchPrefix)
2037
+ .filter(rule => rule.matchPrefix && rule.localPath !== null)
1990
2038
  .map(rule => rule.localPath.replace(/\/$/, ''))
1991
2039
  }
1992
2040
  }