workspace-tools 0.41.9 → 0.41.10

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.
@@ -1,4 +1,6 @@
1
- import { type GetDefaultRemoteOptions } from "./getDefaultRemote.js";
1
+ import { getDefaultRemote, type GetDefaultRemoteOptions } from "./getDefaultRemote.js";
2
+ import type { getRemotes } from "./getRemotes.js";
3
+ import { parseRemoteBranchPlusRemotes, type parseRemoteBranch } from "./parseRemoteBranch.js";
2
4
  import type { RemoteBranch } from "./types.js";
3
5
  export type GetDefaultRemoteBranchOptions = GetDefaultRemoteOptions & {
4
6
  /**
@@ -9,6 +11,7 @@ export type GetDefaultRemoteBranchOptions = GetDefaultRemoteOptions & {
9
11
  */
10
12
  branch?: string;
11
13
  };
14
+ export type { getDefaultRemote as _1, getRemotes as _2, parseRemoteBranch as _3, parseRemoteBranchPlusRemotes as _4 };
12
15
  /**
13
16
  * Gets a reference to `options.branch` or the default branch relative to the default remote.
14
17
  * (See {@link getDefaultRemote} for how the default remote is determined.)
@@ -35,7 +35,7 @@ function getDefaultRemoteBranch(...args) {
35
35
  cwd: argsCwd
36
36
  } : branchOrOptions;
37
37
  const result = getDefaultRemoteAndBranch(options);
38
- return `${result.remote}/${result.branch}`;
38
+ return `${result.remote}/${result.remoteBranch}`;
39
39
  }
40
40
  /**
41
41
  * Like {@link getDefaultRemoteBranch} but it returns an object.
@@ -45,9 +45,10 @@ function getDefaultRemoteBranch(...args) {
45
45
  const { cwd, branch } = options;
46
46
  const defaultRemote = (0, _getDefaultRemote.getDefaultRemote)(options);
47
47
  if (branch) {
48
+ // For this specific function, `branch` has no remote prefix
48
49
  return {
49
50
  remote: defaultRemote,
50
- branch
51
+ remoteBranch: branch
51
52
  };
52
53
  }
53
54
  let remoteDefaultBranch;
@@ -80,12 +81,12 @@ function getDefaultRemoteBranch(...args) {
80
81
  }));
81
82
  return {
82
83
  remote: defaultRemote,
83
- branch: remoteDefaultBranch
84
+ remoteBranch: remoteDefaultBranch
84
85
  };
85
86
  }
86
87
  function resolveRemoteBranch(options) {
87
88
  const result = resolveRemoteAndBranch(options);
88
- return `${result.remote}/${result.branch}`;
89
+ return `${result.remote}/${result.remoteBranch}`;
89
90
  }
90
91
  function resolveRemoteAndBranch(options) {
91
92
  const { branch } = options;
@@ -98,9 +99,10 @@ function resolveRemoteAndBranch(options) {
98
99
  branch
99
100
  });
100
101
  if (parsed.remote) {
102
+ // have to extract these to avoid returning `remotes`
101
103
  return {
102
104
  remote: parsed.remote,
103
- branch: parsed.remoteBranch
105
+ remoteBranch: parsed.remoteBranch
104
106
  };
105
107
  }
106
108
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/git/getDefaultRemoteBranch.ts"],"sourcesContent":["import { getDefaultRemote, type GetDefaultRemoteOptions } from \"./getDefaultRemote.js\";\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- referenced by docs\nimport type { getRemotes } from \"./getRemotes.js\";\nimport { git } from \"./git.js\";\nimport { getDefaultBranch } from \"./gitUtilities.js\";\nimport {\n parseRemoteBranchPlusRemotes,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n type parseRemoteBranch,\n} from \"./parseRemoteBranch.js\";\nimport type { RemoteBranch } from \"./types.js\";\n\nexport type GetDefaultRemoteBranchOptions = GetDefaultRemoteOptions & {\n /**\n * Name of branch to use, **without** a remote prefix. If you want to resolve a branch\n * that may already include a remote prefix, use {@link resolveRemoteAndBranch}.\n *\n * If undefined, uses the default branch name (falling back to `master`).\n */\n branch?: string;\n};\n\n/**\n * Gets a reference to `options.branch` or the default branch relative to the default remote.\n * (See {@link getDefaultRemote} for how the default remote is determined.)\n * Throws if `options.cwd` is not in a git repo.\n *\n * If you want to resolve a branch that may already include a remote prefix, use\n * {@link resolveRemoteAndBranch} instead.\n *\n * If `options.strict` is true, throws in the same cases as {@link getDefaultRemote}, {@link getRemotes},\n * or if querying the default branch from the remote fails.\n *\n * @returns A branch reference like `upstream/master` or `origin/master`.\n */\nexport function getDefaultRemoteBranch(options: GetDefaultRemoteBranchOptions): string;\n/**\n * First param: `branch`. Second param: `cwd`. See {@link GetDefaultRemoteBranchOptions} for more info.\n * (This had to be changed to `...args` to avoid a conflict with the object param version.)\n * @deprecated Use the object param version\n */\nexport function getDefaultRemoteBranch(...args: string[]): string;\nexport function getDefaultRemoteBranch(...args: (string | GetDefaultRemoteBranchOptions)[]): string {\n const [branchOrOptions, argsCwd] = args;\n const options =\n typeof branchOrOptions === \"string\"\n ? ({ branch: branchOrOptions, cwd: argsCwd } as GetDefaultRemoteBranchOptions)\n : branchOrOptions;\n\n const result = getDefaultRemoteAndBranch(options);\n return `${result.remote}/${result.branch}`;\n}\n\n/**\n * Like {@link getDefaultRemoteBranch} but it returns an object.\n *\n * @returns A branch reference like `{ remote: \"upstream\", branch: \"master\" }` or `{ remote: \"origin\", branch: \"main\" }`.\n */\nfunction getDefaultRemoteAndBranch(options: GetDefaultRemoteBranchOptions): RemoteBranch {\n const { cwd, branch } = options;\n\n const defaultRemote = getDefaultRemote(options);\n\n if (branch) {\n return { remote: defaultRemote, branch };\n }\n\n let remoteDefaultBranch: string | undefined;\n\n // Get the default branch name from the default remote.\n // ls-remote is a plumbing command with stable, locale-independent output.\n // Output format: \"ref: refs/heads/main\\tHEAD\\n<hash>\\tHEAD\"\n const lsRemoteCmd = [\"ls-remote\", \"--symref\", defaultRemote, \"HEAD\"];\n const lsRemote = git(lsRemoteCmd, {\n cwd,\n throwOnError: options.strict,\n description: `Fetching default branch info from remote \"${defaultRemote}\"`,\n });\n if (lsRemote.success) {\n const refRegex = /^ref: refs\\/heads\\/(.*?)\\t/;\n const symRefLine = lsRemote.stdout.split(\"\\n\").find((line) => refRegex.test(line));\n remoteDefaultBranch = symRefLine && symRefLine.match(refRegex)?.[1];\n\n if (!remoteDefaultBranch && options.strict) {\n throw new Error(\n `Could not parse default branch from \\`git ${lsRemoteCmd.join(\" \")}\\` output:\\n${lsRemote.stdout}`\n );\n }\n }\n\n // If no default branch found from the remote, fall back to the local git config or \"master\"\n // (this can't use throwOnError in case the key isn't set)\n remoteDefaultBranch ||= getDefaultBranch({ cwd });\n\n return { remote: defaultRemote, branch: remoteDefaultBranch };\n}\n\n/**\n * Resolve a user-provided branch (possibly with a remote) to a fully-qualified remote branch.\n * @returns A fully-qualified target remote branch reference (e.g. `origin/main`)\n * @deprecated Use {@link resolveRemoteAndBranch} instead\n */\nexport function resolveRemoteBranch(\n options: Omit<GetDefaultRemoteBranchOptions, \"branch\" | \"remotes\"> & {\n /** Branch which might include a remote prefix */\n branch: string | undefined;\n }\n): string {\n const result = resolveRemoteAndBranch(options);\n return `${result.remote}/${result.branch}`;\n}\n\n/**\n * Resolve a user-provided branch (possibly with a remote) to a fully-qualified remote branch.\n * First tries the less-expensive {@link parseRemoteBranchPlusRemotes} (compares with remote names\n * read from `git config`) to see if there's an explicit remote in the branch name, then tries\n * {@link getDefaultRemoteBranch}.\n *\n * If `options.strict` is true, throws in the same cases as {@link parseRemoteBranch},\n * {@link getDefaultRemoteBranch}, {@link getDefaultRemote}, or {@link getRemotes}.\n *\n * @returns A fully-qualified target remote branch reference (e.g. `{ remote: \"origin\", branch: \"main\" }`)\n */\nexport function resolveRemoteAndBranch(\n options: Omit<GetDefaultRemoteBranchOptions, \"branch\" | \"remotes\"> & {\n /** Branch which might include a remote prefix */\n branch: string | undefined;\n }\n): RemoteBranch {\n const { branch } = options;\n\n let parsed: ReturnType<typeof parseRemoteBranchPlusRemotes> | undefined;\n if (branch) {\n // A branch is provided, so see if it includes a remote name.\n // The result is saved so the fetched list of remotes can be reused.\n parsed = parseRemoteBranchPlusRemotes({ ...options, branch });\n if (parsed.remote) {\n return { remote: parsed.remote, branch: parsed.remoteBranch };\n }\n }\n\n // No branch provided, or the provided branch didn't include a remote.\n // Get the default remote and possibly default branch.\n return getDefaultRemoteAndBranch({ ...options, remotes: parsed?.remotes });\n}\n"],"names":["getDefaultRemoteBranch","resolveRemoteAndBranch","resolveRemoteBranch","args","branchOrOptions","argsCwd","options","branch","cwd","result","getDefaultRemoteAndBranch","remote","defaultRemote","getDefaultRemote","remoteDefaultBranch","lsRemoteCmd","lsRemote","git","throwOnError","strict","description","success","refRegex","symRefLine","stdout","split","find","line","test","match","Error","join","getDefaultBranch","parsed","parseRemoteBranchPlusRemotes","remoteBranch","remotes"],"mappings":";;;;;;;;;;;;;;;;QA0CgBA;eAAAA;;QAiFAC;eAAAA;;QArBAC;eAAAA;;;kCAtG+C;qBAG3C;8BACa;mCAK1B;AAiCA,SAASF,uBAAuB,GAAGG,IAAgD;IACxF,MAAM,CAACC,iBAAiBC,QAAQ,GAAGF;IACnC,MAAMG,UACJ,OAAOF,oBAAoB,WACtB;QAAEG,QAAQH;QAAiBI,KAAKH;IAAQ,IACzCD;IAEN,MAAMK,SAASC,0BAA0BJ;IACzC,OAAO,GAAGG,OAAOE,MAAM,CAAC,CAAC,EAAEF,OAAOF,MAAM,EAAE;AAC5C;AAEA;;;;CAIC,GACD,SAASG,0BAA0BJ,OAAsC;IACvE,MAAM,EAAEE,GAAG,EAAED,MAAM,EAAE,GAAGD;IAExB,MAAMM,gBAAgBC,IAAAA,kCAAgB,EAACP;IAEvC,IAAIC,QAAQ;QACV,OAAO;YAAEI,QAAQC;YAAeL;QAAO;IACzC;IAEA,IAAIO;IAEJ,uDAAuD;IACvD,0EAA0E;IAC1E,4DAA4D;IAC5D,MAAMC,cAAc;QAAC;QAAa;QAAYH;QAAe;KAAO;IACpE,MAAMI,WAAWC,IAAAA,QAAG,EAACF,aAAa;QAChCP;QACAU,cAAcZ,QAAQa,MAAM;QAC5BC,aAAa,CAAC,0CAA0C,EAAER,cAAc,CAAC,CAAC;IAC5E;IACA,IAAII,SAASK,OAAO,EAAE;QACpB,MAAMC,WAAW;QACjB,MAAMC,aAAaP,SAASQ,MAAM,CAACC,KAAK,CAAC,MAAMC,IAAI,CAAC,CAACC,OAASL,SAASM,IAAI,CAACD;QAC5Eb,sBAAsBS,cAAcA,WAAWM,KAAK,CAACP,WAAW,CAAC,EAAE;QAEnE,IAAI,CAACR,uBAAuBR,QAAQa,MAAM,EAAE;YAC1C,MAAM,IAAIW,MACR,CAAC,0CAA0C,EAAEf,YAAYgB,IAAI,CAAC,KAAK,YAAY,EAAEf,SAASQ,MAAM,EAAE;QAEtG;IACF;IAEA,4FAA4F;IAC5F,0DAA0D;IAC1DV,wBAAAA,sBAAwBkB,IAAAA,8BAAgB,EAAC;QAAExB;IAAI;IAE/C,OAAO;QAAEG,QAAQC;QAAeL,QAAQO;IAAoB;AAC9D;AAOO,SAASZ,oBACdI,OAGC;IAED,MAAMG,SAASR,uBAAuBK;IACtC,OAAO,GAAGG,OAAOE,MAAM,CAAC,CAAC,EAAEF,OAAOF,MAAM,EAAE;AAC5C;AAaO,SAASN,uBACdK,OAGC;IAED,MAAM,EAAEC,MAAM,EAAE,GAAGD;IAEnB,IAAI2B;IACJ,IAAI1B,QAAQ;QACV,6DAA6D;QAC7D,oEAAoE;QACpE0B,SAASC,IAAAA,+CAA4B,EAAC;YAAE,GAAG5B,OAAO;YAAEC;QAAO;QAC3D,IAAI0B,OAAOtB,MAAM,EAAE;YACjB,OAAO;gBAAEA,QAAQsB,OAAOtB,MAAM;gBAAEJ,QAAQ0B,OAAOE,YAAY;YAAC;QAC9D;IACF;IAEA,sEAAsE;IACtE,sDAAsD;IACtD,OAAOzB,0BAA0B;QAAE,GAAGJ,OAAO;QAAE8B,SAASH,QAAQG;IAAQ;AAC1E"}
1
+ {"version":3,"sources":["../../src/git/getDefaultRemoteBranch.ts"],"sourcesContent":["import { getDefaultRemote, type GetDefaultRemoteOptions } from \"./getDefaultRemote.js\";\nimport type { getRemotes } from \"./getRemotes.js\";\nimport { git } from \"./git.js\";\nimport { getDefaultBranch } from \"./gitUtilities.js\";\nimport { parseRemoteBranchPlusRemotes, type parseRemoteBranch } from \"./parseRemoteBranch.js\";\nimport type { RemoteBranch } from \"./types.js\";\n\nexport type GetDefaultRemoteBranchOptions = GetDefaultRemoteOptions & {\n /**\n * Name of branch to use, **without** a remote prefix. If you want to resolve a branch\n * that may already include a remote prefix, use {@link resolveRemoteAndBranch}.\n *\n * If undefined, uses the default branch name (falling back to `master`).\n */\n branch?: string;\n};\n\n// Re-export these so the @link references in jsdoc comments work in the generated .d.ts\nexport type { getDefaultRemote as _1, getRemotes as _2, parseRemoteBranch as _3, parseRemoteBranchPlusRemotes as _4 };\n\n/**\n * Gets a reference to `options.branch` or the default branch relative to the default remote.\n * (See {@link getDefaultRemote} for how the default remote is determined.)\n * Throws if `options.cwd` is not in a git repo.\n *\n * If you want to resolve a branch that may already include a remote prefix, use\n * {@link resolveRemoteAndBranch} instead.\n *\n * If `options.strict` is true, throws in the same cases as {@link getDefaultRemote}, {@link getRemotes},\n * or if querying the default branch from the remote fails.\n *\n * @returns A branch reference like `upstream/master` or `origin/master`.\n */\nexport function getDefaultRemoteBranch(options: GetDefaultRemoteBranchOptions): string;\n/**\n * First param: `branch`. Second param: `cwd`. See {@link GetDefaultRemoteBranchOptions} for more info.\n * (This had to be changed to `...args` to avoid a conflict with the object param version.)\n * @deprecated Use the object param version\n */\nexport function getDefaultRemoteBranch(...args: string[]): string;\nexport function getDefaultRemoteBranch(...args: (string | GetDefaultRemoteBranchOptions)[]): string {\n const [branchOrOptions, argsCwd] = args;\n const options =\n typeof branchOrOptions === \"string\"\n ? ({ branch: branchOrOptions, cwd: argsCwd } as GetDefaultRemoteBranchOptions)\n : branchOrOptions;\n\n const result = getDefaultRemoteAndBranch(options);\n return `${result.remote}/${result.remoteBranch}`;\n}\n\n/**\n * Like {@link getDefaultRemoteBranch} but it returns an object.\n *\n * @returns A branch reference like `{ remote: \"upstream\", branch: \"master\" }` or `{ remote: \"origin\", branch: \"main\" }`.\n */\nfunction getDefaultRemoteAndBranch(options: GetDefaultRemoteBranchOptions): RemoteBranch {\n const { cwd, branch } = options;\n\n const defaultRemote = getDefaultRemote(options);\n\n if (branch) {\n // For this specific function, `branch` has no remote prefix\n return { remote: defaultRemote, remoteBranch: branch };\n }\n\n let remoteDefaultBranch: string | undefined;\n\n // Get the default branch name from the default remote.\n // ls-remote is a plumbing command with stable, locale-independent output.\n // Output format: \"ref: refs/heads/main\\tHEAD\\n<hash>\\tHEAD\"\n const lsRemoteCmd = [\"ls-remote\", \"--symref\", defaultRemote, \"HEAD\"];\n const lsRemote = git(lsRemoteCmd, {\n cwd,\n throwOnError: options.strict,\n description: `Fetching default branch info from remote \"${defaultRemote}\"`,\n });\n if (lsRemote.success) {\n const refRegex = /^ref: refs\\/heads\\/(.*?)\\t/;\n const symRefLine = lsRemote.stdout.split(\"\\n\").find((line) => refRegex.test(line));\n remoteDefaultBranch = symRefLine && symRefLine.match(refRegex)?.[1];\n\n if (!remoteDefaultBranch && options.strict) {\n throw new Error(\n `Could not parse default branch from \\`git ${lsRemoteCmd.join(\" \")}\\` output:\\n${lsRemote.stdout}`\n );\n }\n }\n\n // If no default branch found from the remote, fall back to the local git config or \"master\"\n // (this can't use throwOnError in case the key isn't set)\n remoteDefaultBranch ||= getDefaultBranch({ cwd });\n\n return { remote: defaultRemote, remoteBranch: remoteDefaultBranch };\n}\n\n/**\n * Resolve a user-provided branch (possibly with a remote) to a fully-qualified remote branch.\n * @returns A fully-qualified target remote branch reference (e.g. `origin/main`)\n * @deprecated Use {@link resolveRemoteAndBranch} instead\n */\nexport function resolveRemoteBranch(\n options: Omit<GetDefaultRemoteBranchOptions, \"branch\" | \"remotes\"> & {\n /** Branch which might include a remote prefix */\n branch: string | undefined;\n }\n): string {\n const result = resolveRemoteAndBranch(options);\n return `${result.remote}/${result.remoteBranch}`;\n}\n\n/**\n * Resolve a user-provided branch (possibly with a remote) to a fully-qualified remote branch.\n * First tries the less-expensive {@link parseRemoteBranchPlusRemotes} (compares with remote names\n * read from `git config`) to see if there's an explicit remote in the branch name, then tries\n * {@link getDefaultRemoteBranch}.\n *\n * If `options.strict` is true, throws in the same cases as {@link parseRemoteBranch},\n * {@link getDefaultRemoteBranch}, {@link getDefaultRemote}, or {@link getRemotes}.\n *\n * @returns A fully-qualified target remote branch reference (e.g. `{ remote: \"origin\", branch: \"main\" }`)\n */\nexport function resolveRemoteAndBranch(\n options: Omit<GetDefaultRemoteBranchOptions, \"branch\" | \"remotes\"> & {\n /** Branch which might include a remote prefix */\n branch: string | undefined;\n }\n): RemoteBranch {\n const { branch } = options;\n\n let parsed: ReturnType<typeof parseRemoteBranchPlusRemotes> | undefined;\n if (branch) {\n // A branch is provided, so see if it includes a remote name.\n // The result is saved so the fetched list of remotes can be reused.\n parsed = parseRemoteBranchPlusRemotes({ ...options, branch });\n if (parsed.remote) {\n // have to extract these to avoid returning `remotes`\n return { remote: parsed.remote, remoteBranch: parsed.remoteBranch };\n }\n }\n\n // No branch provided, or the provided branch didn't include a remote.\n // Get the default remote and possibly default branch.\n return getDefaultRemoteAndBranch({ ...options, remotes: parsed?.remotes });\n}\n"],"names":["getDefaultRemoteBranch","resolveRemoteAndBranch","resolveRemoteBranch","args","branchOrOptions","argsCwd","options","branch","cwd","result","getDefaultRemoteAndBranch","remote","remoteBranch","defaultRemote","getDefaultRemote","remoteDefaultBranch","lsRemoteCmd","lsRemote","git","throwOnError","strict","description","success","refRegex","symRefLine","stdout","split","find","line","test","match","Error","join","getDefaultBranch","parsed","parseRemoteBranchPlusRemotes","remotes"],"mappings":";;;;;;;;;;;;;;;;QAwCgBA;eAAAA;;QAkFAC;eAAAA;;QArBAC;eAAAA;;;kCArG+C;qBAE3C;8BACa;mCACoC;AAoC9D,SAASF,uBAAuB,GAAGG,IAAgD;IACxF,MAAM,CAACC,iBAAiBC,QAAQ,GAAGF;IACnC,MAAMG,UACJ,OAAOF,oBAAoB,WACtB;QAAEG,QAAQH;QAAiBI,KAAKH;IAAQ,IACzCD;IAEN,MAAMK,SAASC,0BAA0BJ;IACzC,OAAO,GAAGG,OAAOE,MAAM,CAAC,CAAC,EAAEF,OAAOG,YAAY,EAAE;AAClD;AAEA;;;;CAIC,GACD,SAASF,0BAA0BJ,OAAsC;IACvE,MAAM,EAAEE,GAAG,EAAED,MAAM,EAAE,GAAGD;IAExB,MAAMO,gBAAgBC,IAAAA,kCAAgB,EAACR;IAEvC,IAAIC,QAAQ;QACV,4DAA4D;QAC5D,OAAO;YAAEI,QAAQE;YAAeD,cAAcL;QAAO;IACvD;IAEA,IAAIQ;IAEJ,uDAAuD;IACvD,0EAA0E;IAC1E,4DAA4D;IAC5D,MAAMC,cAAc;QAAC;QAAa;QAAYH;QAAe;KAAO;IACpE,MAAMI,WAAWC,IAAAA,QAAG,EAACF,aAAa;QAChCR;QACAW,cAAcb,QAAQc,MAAM;QAC5BC,aAAa,CAAC,0CAA0C,EAAER,cAAc,CAAC,CAAC;IAC5E;IACA,IAAII,SAASK,OAAO,EAAE;QACpB,MAAMC,WAAW;QACjB,MAAMC,aAAaP,SAASQ,MAAM,CAACC,KAAK,CAAC,MAAMC,IAAI,CAAC,CAACC,OAASL,SAASM,IAAI,CAACD;QAC5Eb,sBAAsBS,cAAcA,WAAWM,KAAK,CAACP,WAAW,CAAC,EAAE;QAEnE,IAAI,CAACR,uBAAuBT,QAAQc,MAAM,EAAE;YAC1C,MAAM,IAAIW,MACR,CAAC,0CAA0C,EAAEf,YAAYgB,IAAI,CAAC,KAAK,YAAY,EAAEf,SAASQ,MAAM,EAAE;QAEtG;IACF;IAEA,4FAA4F;IAC5F,0DAA0D;IAC1DV,wBAAAA,sBAAwBkB,IAAAA,8BAAgB,EAAC;QAAEzB;IAAI;IAE/C,OAAO;QAAEG,QAAQE;QAAeD,cAAcG;IAAoB;AACpE;AAOO,SAASb,oBACdI,OAGC;IAED,MAAMG,SAASR,uBAAuBK;IACtC,OAAO,GAAGG,OAAOE,MAAM,CAAC,CAAC,EAAEF,OAAOG,YAAY,EAAE;AAClD;AAaO,SAASX,uBACdK,OAGC;IAED,MAAM,EAAEC,MAAM,EAAE,GAAGD;IAEnB,IAAI4B;IACJ,IAAI3B,QAAQ;QACV,6DAA6D;QAC7D,oEAAoE;QACpE2B,SAASC,IAAAA,+CAA4B,EAAC;YAAE,GAAG7B,OAAO;YAAEC;QAAO;QAC3D,IAAI2B,OAAOvB,MAAM,EAAE;YACjB,qDAAqD;YACrD,OAAO;gBAAEA,QAAQuB,OAAOvB,MAAM;gBAAEC,cAAcsB,OAAOtB,YAAY;YAAC;QACpE;IACF;IAEA,sEAAsE;IACtE,sDAAsD;IACtD,OAAOF,0BAA0B;QAAE,GAAGJ,OAAO;QAAE8B,SAASF,QAAQE;IAAQ;AAC1E"}
@@ -1,4 +1,6 @@
1
+ import { getRemotes } from "./getRemotes.js";
1
2
  import type { ParsedRemoteBranch, ParseRemoteBranchOptions } from "./types.js";
3
+ export type { getRemotes as _1 };
2
4
  /**
3
5
  * Get the remote and branch name from a full branch name that may include a remote prefix.
4
6
  * If the path doesn't start with one of `options.knownRemotes` (but has multiple segments),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/git/parseRemoteBranch.ts"],"sourcesContent":["import { getRemotes } from \"./getRemotes.js\";\nimport type { ParsedRemoteBranch, ParseRemoteBranchOptions } from \"./types.js\";\n\n/**\n * Get the remote and branch name from a full branch name that may include a remote prefix.\n * If the path doesn't start with one of `options.knownRemotes` (but has multiple segments),\n * the actual list of remotes will be read via `git config` to see if one of those matches.\n *\n * With `throwOnError: true`, currently it will NOT throw if the branch prefix matches `knownRemotes`\n * regardless of the actual state of remotes in the repo. If it has to get the actual list of\n * remotes, it will throw in the same cases as {@link getRemotes}.\n *\n * NOTE: The additional verification is new in the object params version; the original version\n * incorrectly assumes the first segment before a slash is always a remote.\n */\nexport function parseRemoteBranch(options: ParseRemoteBranchOptions): ParsedRemoteBranch;\n/**\n * @deprecated Use object params version, which does more verification. This version inaccurately\n * assumes the first segment before a slash is always a remote, which could lead to tricky bugs.\n */\nexport function parseRemoteBranch(branch: string): ParsedRemoteBranch;\nexport function parseRemoteBranch(branchOrOptions: string | ParseRemoteBranchOptions): ParsedRemoteBranch {\n if (typeof branchOrOptions === \"string\") {\n const branch = branchOrOptions;\n const firstSlashPos = branch.indexOf(\"/\", 0);\n return {\n remote: branch.substring(0, firstSlashPos),\n remoteBranch: branch.substring(firstSlashPos + 1),\n };\n }\n\n // Remove the list of remotes from the result\n const { remote, remoteBranch } = parseRemoteBranchPlusRemotes(branchOrOptions);\n return { remote, remoteBranch };\n}\n\n/**\n * See {@link parseRemoteBranch}. This version also returns the remotes in the result if they were\n * read from git, for reuse by other operations.\n */\nexport function parseRemoteBranchPlusRemotes(\n options: ParseRemoteBranchOptions\n): ParsedRemoteBranch & { remotes: Record<string, string> | undefined } {\n const { branch, knownRemotes = [\"origin\", \"upstream\"], ...otherOptions } = options;\n\n if (!branch.includes(\"/\")) {\n return { remote: \"\", remoteBranch: branch, remotes: undefined };\n }\n\n // As a shortcut, check for the most common remote names before doing git operations\n let remote = knownRemotes.find((r) => branch.startsWith(`${r}/`));\n\n let remotes: Record<string, string> | undefined;\n if (!remote) {\n // There's a slash in the branch name, but it doesn't start with one of the common remote names.\n // Get the real list of remotes from git to see if it matches any of those, or is just a branch\n // with a slash in the name (e.g. \"feature/foo/bar\"). This just reads the git config and isn't\n // an expensive operation, but save the returned remotes for later anyway.\n remotes = getRemotes(otherOptions);\n if (remotes) {\n remote = Object.keys(remotes).find((r) => branch.startsWith(`${r}/`));\n }\n }\n\n if (remote) {\n return { remote, remoteBranch: branch.slice(remote.length + 1), remotes };\n }\n return { remote: \"\", remoteBranch: branch, remotes };\n}\n"],"names":["parseRemoteBranch","parseRemoteBranchPlusRemotes","branchOrOptions","branch","firstSlashPos","indexOf","remote","substring","remoteBranch","options","knownRemotes","otherOptions","includes","remotes","undefined","find","r","startsWith","getRemotes","Object","keys","slice","length"],"mappings":";;;;;;;;;;;;;;;QAqBgBA;eAAAA;;QAmBAC;eAAAA;;;4BAxCW;AAqBpB,SAASD,kBAAkBE,eAAkD;IAClF,IAAI,OAAOA,oBAAoB,UAAU;QACvC,MAAMC,SAASD;QACf,MAAME,gBAAgBD,OAAOE,OAAO,CAAC,KAAK;QAC1C,OAAO;YACLC,QAAQH,OAAOI,SAAS,CAAC,GAAGH;YAC5BI,cAAcL,OAAOI,SAAS,CAACH,gBAAgB;QACjD;IACF;IAEA,6CAA6C;IAC7C,MAAM,EAAEE,MAAM,EAAEE,YAAY,EAAE,GAAGP,6BAA6BC;IAC9D,OAAO;QAAEI;QAAQE;IAAa;AAChC;AAMO,SAASP,6BACdQ,OAAiC;IAEjC,MAAM,EAAEN,MAAM,EAAEO,eAAe;QAAC;QAAU;KAAW,EAAE,GAAGC,cAAc,GAAGF;IAE3E,IAAI,CAACN,OAAOS,QAAQ,CAAC,MAAM;QACzB,OAAO;YAAEN,QAAQ;YAAIE,cAAcL;YAAQU,SAASC;QAAU;IAChE;IAEA,oFAAoF;IACpF,IAAIR,SAASI,aAAaK,IAAI,CAAC,CAACC,IAAMb,OAAOc,UAAU,CAAC,GAAGD,EAAE,CAAC,CAAC;IAE/D,IAAIH;IACJ,IAAI,CAACP,QAAQ;QACX,gGAAgG;QAChG,+FAA+F;QAC/F,8FAA8F;QAC9F,0EAA0E;QAC1EO,UAAUK,IAAAA,sBAAU,EAACP;QACrB,IAAIE,SAAS;YACXP,SAASa,OAAOC,IAAI,CAACP,SAASE,IAAI,CAAC,CAACC,IAAMb,OAAOc,UAAU,CAAC,GAAGD,EAAE,CAAC,CAAC;QACrE;IACF;IAEA,IAAIV,QAAQ;QACV,OAAO;YAAEA;YAAQE,cAAcL,OAAOkB,KAAK,CAACf,OAAOgB,MAAM,GAAG;YAAIT;QAAQ;IAC1E;IACA,OAAO;QAAEP,QAAQ;QAAIE,cAAcL;QAAQU;IAAQ;AACrD"}
1
+ {"version":3,"sources":["../../src/git/parseRemoteBranch.ts"],"sourcesContent":["import { getRemotes } from \"./getRemotes.js\";\nimport type { ParsedRemoteBranch, ParseRemoteBranchOptions } from \"./types.js\";\n\n// Re-export this so the @link references in jsdoc comments work in the generated .d.ts\nexport type { getRemotes as _1 };\n\n/**\n * Get the remote and branch name from a full branch name that may include a remote prefix.\n * If the path doesn't start with one of `options.knownRemotes` (but has multiple segments),\n * the actual list of remotes will be read via `git config` to see if one of those matches.\n *\n * With `throwOnError: true`, currently it will NOT throw if the branch prefix matches `knownRemotes`\n * regardless of the actual state of remotes in the repo. If it has to get the actual list of\n * remotes, it will throw in the same cases as {@link getRemotes}.\n *\n * NOTE: The additional verification is new in the object params version; the original version\n * incorrectly assumes the first segment before a slash is always a remote.\n */\nexport function parseRemoteBranch(options: ParseRemoteBranchOptions): ParsedRemoteBranch;\n/**\n * @deprecated Use object params version, which does more verification. This version inaccurately\n * assumes the first segment before a slash is always a remote, which could lead to tricky bugs.\n */\nexport function parseRemoteBranch(branch: string): ParsedRemoteBranch;\nexport function parseRemoteBranch(branchOrOptions: string | ParseRemoteBranchOptions): ParsedRemoteBranch {\n if (typeof branchOrOptions === \"string\") {\n const branch = branchOrOptions;\n const firstSlashPos = branch.indexOf(\"/\", 0);\n return {\n remote: branch.substring(0, firstSlashPos),\n remoteBranch: branch.substring(firstSlashPos + 1),\n };\n }\n\n // Remove the list of remotes from the result\n const { remote, remoteBranch } = parseRemoteBranchPlusRemotes(branchOrOptions);\n return { remote, remoteBranch };\n}\n\n/**\n * See {@link parseRemoteBranch}. This version also returns the remotes in the result if they were\n * read from git, for reuse by other operations.\n */\nexport function parseRemoteBranchPlusRemotes(\n options: ParseRemoteBranchOptions\n): ParsedRemoteBranch & { remotes: Record<string, string> | undefined } {\n const { branch, knownRemotes = [\"origin\", \"upstream\"], ...otherOptions } = options;\n\n if (!branch.includes(\"/\")) {\n return { remote: \"\", remoteBranch: branch, remotes: undefined };\n }\n\n // As a shortcut, check for the most common remote names before doing git operations\n let remote = knownRemotes.find((r) => branch.startsWith(`${r}/`));\n\n let remotes: Record<string, string> | undefined;\n if (!remote) {\n // There's a slash in the branch name, but it doesn't start with one of the common remote names.\n // Get the real list of remotes from git to see if it matches any of those, or is just a branch\n // with a slash in the name (e.g. \"feature/foo/bar\"). This just reads the git config and isn't\n // an expensive operation, but save the returned remotes for later anyway.\n remotes = getRemotes(otherOptions);\n if (remotes) {\n remote = Object.keys(remotes).find((r) => branch.startsWith(`${r}/`));\n }\n }\n\n if (remote) {\n return { remote, remoteBranch: branch.slice(remote.length + 1), remotes };\n }\n return { remote: \"\", remoteBranch: branch, remotes };\n}\n"],"names":["parseRemoteBranch","parseRemoteBranchPlusRemotes","branchOrOptions","branch","firstSlashPos","indexOf","remote","substring","remoteBranch","options","knownRemotes","otherOptions","includes","remotes","undefined","find","r","startsWith","getRemotes","Object","keys","slice","length"],"mappings":";;;;;;;;;;;;;;;QAwBgBA;eAAAA;;QAmBAC;eAAAA;;;4BA3CW;AAwBpB,SAASD,kBAAkBE,eAAkD;IAClF,IAAI,OAAOA,oBAAoB,UAAU;QACvC,MAAMC,SAASD;QACf,MAAME,gBAAgBD,OAAOE,OAAO,CAAC,KAAK;QAC1C,OAAO;YACLC,QAAQH,OAAOI,SAAS,CAAC,GAAGH;YAC5BI,cAAcL,OAAOI,SAAS,CAACH,gBAAgB;QACjD;IACF;IAEA,6CAA6C;IAC7C,MAAM,EAAEE,MAAM,EAAEE,YAAY,EAAE,GAAGP,6BAA6BC;IAC9D,OAAO;QAAEI;QAAQE;IAAa;AAChC;AAMO,SAASP,6BACdQ,OAAiC;IAEjC,MAAM,EAAEN,MAAM,EAAEO,eAAe;QAAC;QAAU;KAAW,EAAE,GAAGC,cAAc,GAAGF;IAE3E,IAAI,CAACN,OAAOS,QAAQ,CAAC,MAAM;QACzB,OAAO;YAAEN,QAAQ;YAAIE,cAAcL;YAAQU,SAASC;QAAU;IAChE;IAEA,oFAAoF;IACpF,IAAIR,SAASI,aAAaK,IAAI,CAAC,CAACC,IAAMb,OAAOc,UAAU,CAAC,GAAGD,EAAE,CAAC,CAAC;IAE/D,IAAIH;IACJ,IAAI,CAACP,QAAQ;QACX,gGAAgG;QAChG,+FAA+F;QAC/F,8FAA8F;QAC9F,0EAA0E;QAC1EO,UAAUK,IAAAA,sBAAU,EAACP;QACrB,IAAIE,SAAS;YACXP,SAASa,OAAOC,IAAI,CAACP,SAASE,IAAI,CAAC,CAACC,IAAMb,OAAOc,UAAU,CAAC,GAAGD,EAAE,CAAC,CAAC;QACrE;IACF;IAEA,IAAIV,QAAQ;QACV,OAAO;YAAEA;YAAQE,cAAcL,OAAOkB,KAAK,CAACf,OAAOgB,MAAM,GAAG;YAAIT;QAAQ;IAC1E;IACA,OAAO;QAAEP,QAAQ;QAAIE,cAAcL;QAAQU;IAAQ;AACrD"}
@@ -51,11 +51,9 @@ export type ParsedRemoteBranch = {
51
51
  /** Branch name without remote, e.g. `main`. This is always set. */
52
52
  remoteBranch: string;
53
53
  };
54
- export type RemoteBranch = {
54
+ export type RemoteBranch = Pick<ParsedRemoteBranch, "remoteBranch"> & {
55
55
  /** Remote name, e.g. `origin`. */
56
56
  remote: string;
57
- /** Branch name without remote, e.g. `main`. */
58
- branch: string;
59
57
  };
60
58
  export type GitStageOptions = {
61
59
  /** File patterns to stage */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/git/types.ts"],"sourcesContent":["/** Options used for all git operations and wrappers */\nexport type GitCommonOptions = {\n cwd: string;\n /** If true, throw if the command fails */\n throwOnError?: boolean;\n};\n\n/** Options for git operations related to a branch */\nexport type GitBranchOptions = { branch: string } & GitCommonOptions;\n\nexport type GitFetchOptions = GitCommonOptions & {\n /** Remote name to fetch, e.g. \"origin\" (if not provided, fetches all remotes) */\n remote?: string;\n /** Branch name to fetch, e.g. \"main\". To use this, `remote` must also be set. */\n remoteBranch?: string;\n /** Extra command line options */\n options?: string[];\n};\n\nexport type GetChangesBetweenRefsOptions = GitCommonOptions & {\n /** The starting reference */\n fromRef: string;\n /** The ending reference */\n toRef?: string;\n /** Extra command line options */\n options?: string[];\n /** Optional file pattern to filter results */\n pattern?: string;\n};\n\nexport type GitInitOptions = Omit<GitCommonOptions, \"throwOnError\"> & {\n /** Email to set in the git config, if not already set */\n email?: string;\n /** Username to set in the git config, if not already set */\n username?: string;\n};\n\nexport type ParseRemoteBranchOptions = GitCommonOptions & {\n /** Branch name with possible remote prefix */\n branch: string;\n /**\n * Well-known remote names. If these appear at the beginning of a branch name, they'll always\n * be returned as `ParsedRemoteBranch.remote` regardless of whether they exist locally.\n * @default [\"origin\", \"upstream\"]\n */\n knownRemotes?: string[];\n};\n\nexport type ParsedRemoteBranch = {\n /**\n * Remote name, e.g. `origin`.\n * May be an empty string if the original branch reference didn't include a remote.\n */\n remote: string;\n /** Branch name without remote, e.g. `main`. This is always set. */\n remoteBranch: string;\n};\n\nexport type RemoteBranch = {\n /** Remote name, e.g. `origin`. */\n remote: string;\n /** Branch name without remote, e.g. `main`. */\n branch: string;\n};\n\nexport type GitStageOptions = {\n /** File patterns to stage */\n patterns: string[];\n} & GitCommonOptions;\n\nexport type GitCommitOptions = GitCommonOptions & {\n /** Commit message */\n message: string;\n /** Additional git commit options */\n options?: string[];\n};\n"],"names":[],"mappings":"AAAA,qDAAqD"}
1
+ {"version":3,"sources":["../../src/git/types.ts"],"sourcesContent":["/** Options used for all git operations and wrappers */\nexport type GitCommonOptions = {\n cwd: string;\n /** If true, throw if the command fails */\n throwOnError?: boolean;\n};\n\n/** Options for git operations related to a branch */\nexport type GitBranchOptions = { branch: string } & GitCommonOptions;\n\nexport type GitFetchOptions = GitCommonOptions & {\n /** Remote name to fetch, e.g. \"origin\" (if not provided, fetches all remotes) */\n remote?: string;\n /** Branch name to fetch, e.g. \"main\". To use this, `remote` must also be set. */\n remoteBranch?: string;\n /** Extra command line options */\n options?: string[];\n};\n\nexport type GetChangesBetweenRefsOptions = GitCommonOptions & {\n /** The starting reference */\n fromRef: string;\n /** The ending reference */\n toRef?: string;\n /** Extra command line options */\n options?: string[];\n /** Optional file pattern to filter results */\n pattern?: string;\n};\n\nexport type GitInitOptions = Omit<GitCommonOptions, \"throwOnError\"> & {\n /** Email to set in the git config, if not already set */\n email?: string;\n /** Username to set in the git config, if not already set */\n username?: string;\n};\n\nexport type ParseRemoteBranchOptions = GitCommonOptions & {\n /** Branch name with possible remote prefix */\n branch: string;\n /**\n * Well-known remote names. If these appear at the beginning of a branch name, they'll always\n * be returned as `ParsedRemoteBranch.remote` regardless of whether they exist locally.\n * @default [\"origin\", \"upstream\"]\n */\n knownRemotes?: string[];\n};\n\nexport type ParsedRemoteBranch = {\n /**\n * Remote name, e.g. `origin`.\n * May be an empty string if the original branch reference didn't include a remote.\n */\n remote: string;\n /** Branch name without remote, e.g. `main`. This is always set. */\n remoteBranch: string;\n};\n\nexport type RemoteBranch = Pick<ParsedRemoteBranch, \"remoteBranch\"> & {\n /** Remote name, e.g. `origin`. */\n remote: string;\n};\n\nexport type GitStageOptions = {\n /** File patterns to stage */\n patterns: string[];\n} & GitCommonOptions;\n\nexport type GitCommitOptions = GitCommonOptions & {\n /** Commit message */\n message: string;\n /** Additional git commit options */\n options?: string[];\n};\n"],"names":[],"mappings":"AAAA,qDAAqD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workspace-tools",
3
- "version": "0.41.9",
3
+ "version": "0.41.10",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",