workspace-tools 0.41.8 → 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.
- package/lib/git/getDefaultRemoteBranch.d.ts +19 -6
- package/lib/git/getDefaultRemoteBranch.js +31 -4
- package/lib/git/getDefaultRemoteBranch.js.map +1 -1
- package/lib/git/index.d.ts +2 -1
- package/lib/git/index.js +9 -0
- package/lib/git/index.js.map +1 -1
- package/lib/git/parseRemoteBranch.d.ts +2 -0
- package/lib/git/parseRemoteBranch.js.map +1 -1
- package/lib/git/types.d.ts +4 -0
- package/lib/git/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,20 +1,24 @@
|
|
|
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";
|
|
4
|
+
import type { RemoteBranch } from "./types.js";
|
|
2
5
|
export type GetDefaultRemoteBranchOptions = GetDefaultRemoteOptions & {
|
|
3
6
|
/**
|
|
4
7
|
* Name of branch to use, **without** a remote prefix. If you want to resolve a branch
|
|
5
|
-
* that may already include a remote prefix, use {@link
|
|
8
|
+
* that may already include a remote prefix, use {@link resolveRemoteAndBranch}.
|
|
6
9
|
*
|
|
7
10
|
* If undefined, uses the default branch name (falling back to `master`).
|
|
8
11
|
*/
|
|
9
12
|
branch?: string;
|
|
10
13
|
};
|
|
14
|
+
export type { getDefaultRemote as _1, getRemotes as _2, parseRemoteBranch as _3, parseRemoteBranchPlusRemotes as _4 };
|
|
11
15
|
/**
|
|
12
16
|
* Gets a reference to `options.branch` or the default branch relative to the default remote.
|
|
13
17
|
* (See {@link getDefaultRemote} for how the default remote is determined.)
|
|
14
18
|
* Throws if `options.cwd` is not in a git repo.
|
|
15
19
|
*
|
|
16
20
|
* If you want to resolve a branch that may already include a remote prefix, use
|
|
17
|
-
* {@link
|
|
21
|
+
* {@link resolveRemoteAndBranch} instead.
|
|
18
22
|
*
|
|
19
23
|
* If `options.strict` is true, throws in the same cases as {@link getDefaultRemote}, {@link getRemotes},
|
|
20
24
|
* or if querying the default branch from the remote fails.
|
|
@@ -28,6 +32,15 @@ export declare function getDefaultRemoteBranch(options: GetDefaultRemoteBranchOp
|
|
|
28
32
|
* @deprecated Use the object param version
|
|
29
33
|
*/
|
|
30
34
|
export declare function getDefaultRemoteBranch(...args: string[]): string;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve a user-provided branch (possibly with a remote) to a fully-qualified remote branch.
|
|
37
|
+
* @returns A fully-qualified target remote branch reference (e.g. `origin/main`)
|
|
38
|
+
* @deprecated Use {@link resolveRemoteAndBranch} instead
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveRemoteBranch(options: Omit<GetDefaultRemoteBranchOptions, "branch" | "remotes"> & {
|
|
41
|
+
/** Branch which might include a remote prefix */
|
|
42
|
+
branch: string | undefined;
|
|
43
|
+
}): string;
|
|
31
44
|
/**
|
|
32
45
|
* Resolve a user-provided branch (possibly with a remote) to a fully-qualified remote branch.
|
|
33
46
|
* First tries the less-expensive {@link parseRemoteBranchPlusRemotes} (compares with remote names
|
|
@@ -37,9 +50,9 @@ export declare function getDefaultRemoteBranch(...args: string[]): string;
|
|
|
37
50
|
* If `options.strict` is true, throws in the same cases as {@link parseRemoteBranch},
|
|
38
51
|
* {@link getDefaultRemoteBranch}, {@link getDefaultRemote}, or {@link getRemotes}.
|
|
39
52
|
*
|
|
40
|
-
* @returns A fully-qualified target remote branch reference (e.g. `origin
|
|
53
|
+
* @returns A fully-qualified target remote branch reference (e.g. `{ remote: "origin", branch: "main" }`)
|
|
41
54
|
*/
|
|
42
|
-
export declare function
|
|
55
|
+
export declare function resolveRemoteAndBranch(options: Omit<GetDefaultRemoteBranchOptions, "branch" | "remotes"> & {
|
|
43
56
|
/** Branch which might include a remote prefix */
|
|
44
57
|
branch: string | undefined;
|
|
45
|
-
}):
|
|
58
|
+
}): RemoteBranch;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
0 && (module.exports = {
|
|
6
6
|
getDefaultRemoteBranch: null,
|
|
7
|
+
resolveRemoteAndBranch: null,
|
|
7
8
|
resolveRemoteBranch: null
|
|
8
9
|
});
|
|
9
10
|
function _export(target, all) {
|
|
@@ -16,6 +17,9 @@ _export(exports, {
|
|
|
16
17
|
get getDefaultRemoteBranch () {
|
|
17
18
|
return getDefaultRemoteBranch;
|
|
18
19
|
},
|
|
20
|
+
get resolveRemoteAndBranch () {
|
|
21
|
+
return resolveRemoteAndBranch;
|
|
22
|
+
},
|
|
19
23
|
get resolveRemoteBranch () {
|
|
20
24
|
return resolveRemoteBranch;
|
|
21
25
|
}
|
|
@@ -30,10 +34,22 @@ function getDefaultRemoteBranch(...args) {
|
|
|
30
34
|
branch: branchOrOptions,
|
|
31
35
|
cwd: argsCwd
|
|
32
36
|
} : branchOrOptions;
|
|
37
|
+
const result = getDefaultRemoteAndBranch(options);
|
|
38
|
+
return `${result.remote}/${result.remoteBranch}`;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Like {@link getDefaultRemoteBranch} but it returns an object.
|
|
42
|
+
*
|
|
43
|
+
* @returns A branch reference like `{ remote: "upstream", branch: "master" }` or `{ remote: "origin", branch: "main" }`.
|
|
44
|
+
*/ function getDefaultRemoteAndBranch(options) {
|
|
33
45
|
const { cwd, branch } = options;
|
|
34
46
|
const defaultRemote = (0, _getDefaultRemote.getDefaultRemote)(options);
|
|
35
47
|
if (branch) {
|
|
36
|
-
|
|
48
|
+
// For this specific function, `branch` has no remote prefix
|
|
49
|
+
return {
|
|
50
|
+
remote: defaultRemote,
|
|
51
|
+
remoteBranch: branch
|
|
52
|
+
};
|
|
37
53
|
}
|
|
38
54
|
let remoteDefaultBranch;
|
|
39
55
|
// Get the default branch name from the default remote.
|
|
@@ -63,9 +79,16 @@ function getDefaultRemoteBranch(...args) {
|
|
|
63
79
|
remoteDefaultBranch || (remoteDefaultBranch = (0, _gitUtilities.getDefaultBranch)({
|
|
64
80
|
cwd
|
|
65
81
|
}));
|
|
66
|
-
return
|
|
82
|
+
return {
|
|
83
|
+
remote: defaultRemote,
|
|
84
|
+
remoteBranch: remoteDefaultBranch
|
|
85
|
+
};
|
|
67
86
|
}
|
|
68
87
|
function resolveRemoteBranch(options) {
|
|
88
|
+
const result = resolveRemoteAndBranch(options);
|
|
89
|
+
return `${result.remote}/${result.remoteBranch}`;
|
|
90
|
+
}
|
|
91
|
+
function resolveRemoteAndBranch(options) {
|
|
69
92
|
const { branch } = options;
|
|
70
93
|
let parsed;
|
|
71
94
|
if (branch) {
|
|
@@ -76,12 +99,16 @@ function resolveRemoteBranch(options) {
|
|
|
76
99
|
branch
|
|
77
100
|
});
|
|
78
101
|
if (parsed.remote) {
|
|
79
|
-
|
|
102
|
+
// have to extract these to avoid returning `remotes`
|
|
103
|
+
return {
|
|
104
|
+
remote: parsed.remote,
|
|
105
|
+
remoteBranch: parsed.remoteBranch
|
|
106
|
+
};
|
|
80
107
|
}
|
|
81
108
|
}
|
|
82
109
|
// No branch provided, or the provided branch didn't include a remote.
|
|
83
110
|
// Get the default remote and possibly default branch.
|
|
84
|
-
return
|
|
111
|
+
return getDefaultRemoteAndBranch({
|
|
85
112
|
...options,
|
|
86
113
|
remotes: parsed?.remotes
|
|
87
114
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/git/getDefaultRemoteBranch.ts"],"sourcesContent":["import { getDefaultRemote, type GetDefaultRemoteOptions } from \"./getDefaultRemote.js\";\
|
|
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"}
|
package/lib/git/index.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ export { fetchRemote, fetchRemoteBranch } from "./fetchRemote.js";
|
|
|
4
4
|
export { getBranchChanges, getChanges, getChangesBetweenRefs, getStagedChanges, getUnstagedChanges, getUntrackedChanges, } from "./getChanges.js";
|
|
5
5
|
export { getCurrentHash } from "./getCurrentHash.js";
|
|
6
6
|
export { getDefaultRemote, type GetDefaultRemoteOptions } from "./getDefaultRemote.js";
|
|
7
|
-
export { getDefaultRemoteBranch, type GetDefaultRemoteBranchOptions, resolveRemoteBranch, } from "./getDefaultRemoteBranch.js";
|
|
7
|
+
export { getDefaultRemoteBranch, type GetDefaultRemoteBranchOptions, resolveRemoteBranch, resolveRemoteAndBranch, } from "./getDefaultRemoteBranch.js";
|
|
8
8
|
export { getFileAddedHash } from "./getFileAddedHash.js";
|
|
9
9
|
export { getFileFromRef } from "./getFileFromRef.js";
|
|
10
10
|
export { getRecentCommitMessages } from "./getRecentCommitMessages.js";
|
|
11
|
+
export { getRemotes } from "./getRemotes.js";
|
|
11
12
|
export { addGitObserver, clearGitObservers, git, gitFailFast, type GitError, type GitObserver, type GitOptions, type GitProcessOutput, } from "./git.js";
|
|
12
13
|
export { getParentBranch } from "./gitUtilities.js";
|
|
13
14
|
export { init } from "./init.js";
|
package/lib/git/index.js
CHANGED
|
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
23
23
|
getParentBranch: null,
|
|
24
24
|
getRecentCommitMessages: null,
|
|
25
25
|
getRemoteBranch: null,
|
|
26
|
+
getRemotes: null,
|
|
26
27
|
getShortBranchName: null,
|
|
27
28
|
getStagedChanges: null,
|
|
28
29
|
getUnstagedChanges: null,
|
|
@@ -33,6 +34,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
33
34
|
init: null,
|
|
34
35
|
listAllTrackedFiles: null,
|
|
35
36
|
parseRemoteBranch: null,
|
|
37
|
+
resolveRemoteAndBranch: null,
|
|
36
38
|
resolveRemoteBranch: null,
|
|
37
39
|
revertLocalChanges: null,
|
|
38
40
|
stage: null,
|
|
@@ -105,6 +107,9 @@ _export(exports, {
|
|
|
105
107
|
get getRemoteBranch () {
|
|
106
108
|
return _branchRefs.getRemoteBranch;
|
|
107
109
|
},
|
|
110
|
+
get getRemotes () {
|
|
111
|
+
return _getRemotes.getRemotes;
|
|
112
|
+
},
|
|
108
113
|
get getShortBranchName () {
|
|
109
114
|
return _branchRefs.getShortBranchName;
|
|
110
115
|
},
|
|
@@ -135,6 +140,9 @@ _export(exports, {
|
|
|
135
140
|
get parseRemoteBranch () {
|
|
136
141
|
return _parseRemoteBranch.parseRemoteBranch;
|
|
137
142
|
},
|
|
143
|
+
get resolveRemoteAndBranch () {
|
|
144
|
+
return _getDefaultRemoteBranch.resolveRemoteAndBranch;
|
|
145
|
+
},
|
|
138
146
|
get resolveRemoteBranch () {
|
|
139
147
|
return _getDefaultRemoteBranch.resolveRemoteBranch;
|
|
140
148
|
},
|
|
@@ -158,6 +166,7 @@ const _getDefaultRemoteBranch = require("./getDefaultRemoteBranch.js");
|
|
|
158
166
|
const _getFileAddedHash = require("./getFileAddedHash.js");
|
|
159
167
|
const _getFileFromRef = require("./getFileFromRef.js");
|
|
160
168
|
const _getRecentCommitMessages = require("./getRecentCommitMessages.js");
|
|
169
|
+
const _getRemotes = require("./getRemotes.js");
|
|
161
170
|
const _git = require("./git.js");
|
|
162
171
|
const _gitUtilities = require("./gitUtilities.js");
|
|
163
172
|
const _init = require("./init.js");
|
package/lib/git/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/git/index.ts"],"sourcesContent":["export { getBranchName, getFullBranchRef, getRemoteBranch, getShortBranchName } from \"./branchRefs.js\";\nexport { getConfigValue, getDefaultBranch, getUserEmail } from \"./config.js\";\nexport { fetchRemote, fetchRemoteBranch } from \"./fetchRemote.js\";\nexport {\n getBranchChanges,\n getChanges,\n getChangesBetweenRefs,\n getStagedChanges,\n getUnstagedChanges,\n getUntrackedChanges,\n} from \"./getChanges.js\";\nexport { getCurrentHash } from \"./getCurrentHash.js\";\nexport { getDefaultRemote, type GetDefaultRemoteOptions } from \"./getDefaultRemote.js\";\nexport {\n getDefaultRemoteBranch,\n type GetDefaultRemoteBranchOptions,\n resolveRemoteBranch,\n} from \"./getDefaultRemoteBranch.js\";\nexport { getFileAddedHash } from \"./getFileAddedHash.js\";\nexport { getFileFromRef } from \"./getFileFromRef.js\";\nexport { getRecentCommitMessages } from \"./getRecentCommitMessages.js\";\nexport {\n addGitObserver,\n clearGitObservers,\n git,\n gitFailFast,\n type GitError,\n type GitObserver,\n type GitOptions,\n type GitProcessOutput,\n} from \"./git.js\";\nexport { getParentBranch } from \"./gitUtilities.js\";\nexport { init } from \"./init.js\";\nexport { listAllTrackedFiles } from \"./listAllTrackedFiles.js\";\nexport { parseRemoteBranch } from \"./parseRemoteBranch.js\";\nexport { revertLocalChanges } from \"./revertLocalChanges.js\";\nexport { commit, stage, stageAndCommit } from \"./stageAndCommit.js\";\n\n// getRepositoryName is not currently exported; could be changed if it would be useful externally\n"],"names":["addGitObserver","clearGitObservers","commit","fetchRemote","fetchRemoteBranch","getBranchChanges","getBranchName","getChanges","getChangesBetweenRefs","getConfigValue","getCurrentHash","getDefaultBranch","getDefaultRemote","getDefaultRemoteBranch","getFileAddedHash","getFileFromRef","getFullBranchRef","getParentBranch","getRecentCommitMessages","getRemoteBranch","getShortBranchName","getStagedChanges","getUnstagedChanges","getUntrackedChanges","getUserEmail","git","gitFailFast","init","listAllTrackedFiles","parseRemoteBranch","resolveRemoteBranch","revertLocalChanges","stage","stageAndCommit"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/git/index.ts"],"sourcesContent":["export { getBranchName, getFullBranchRef, getRemoteBranch, getShortBranchName } from \"./branchRefs.js\";\nexport { getConfigValue, getDefaultBranch, getUserEmail } from \"./config.js\";\nexport { fetchRemote, fetchRemoteBranch } from \"./fetchRemote.js\";\nexport {\n getBranchChanges,\n getChanges,\n getChangesBetweenRefs,\n getStagedChanges,\n getUnstagedChanges,\n getUntrackedChanges,\n} from \"./getChanges.js\";\nexport { getCurrentHash } from \"./getCurrentHash.js\";\nexport { getDefaultRemote, type GetDefaultRemoteOptions } from \"./getDefaultRemote.js\";\nexport {\n getDefaultRemoteBranch,\n type GetDefaultRemoteBranchOptions,\n resolveRemoteBranch,\n resolveRemoteAndBranch,\n} from \"./getDefaultRemoteBranch.js\";\nexport { getFileAddedHash } from \"./getFileAddedHash.js\";\nexport { getFileFromRef } from \"./getFileFromRef.js\";\nexport { getRecentCommitMessages } from \"./getRecentCommitMessages.js\";\nexport { getRemotes } from \"./getRemotes.js\";\nexport {\n addGitObserver,\n clearGitObservers,\n git,\n gitFailFast,\n type GitError,\n type GitObserver,\n type GitOptions,\n type GitProcessOutput,\n} from \"./git.js\";\nexport { getParentBranch } from \"./gitUtilities.js\";\nexport { init } from \"./init.js\";\nexport { listAllTrackedFiles } from \"./listAllTrackedFiles.js\";\nexport { parseRemoteBranch } from \"./parseRemoteBranch.js\";\nexport { revertLocalChanges } from \"./revertLocalChanges.js\";\nexport { commit, stage, stageAndCommit } from \"./stageAndCommit.js\";\n\n// getRepositoryName is not currently exported; could be changed if it would be useful externally\n"],"names":["addGitObserver","clearGitObservers","commit","fetchRemote","fetchRemoteBranch","getBranchChanges","getBranchName","getChanges","getChangesBetweenRefs","getConfigValue","getCurrentHash","getDefaultBranch","getDefaultRemote","getDefaultRemoteBranch","getFileAddedHash","getFileFromRef","getFullBranchRef","getParentBranch","getRecentCommitMessages","getRemoteBranch","getRemotes","getShortBranchName","getStagedChanges","getUnstagedChanges","getUntrackedChanges","getUserEmail","git","gitFailFast","init","listAllTrackedFiles","parseRemoteBranch","resolveRemoteAndBranch","resolveRemoteBranch","revertLocalChanges","stage","stageAndCommit"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAwBEA;eAAAA,mBAAc;;QACdC;eAAAA,sBAAiB;;QAaVC;eAAAA,sBAAM;;QApCNC;eAAAA,wBAAW;;QAAEC;eAAAA,8BAAiB;;QAErCC;eAAAA,4BAAgB;;QAJTC;eAAAA,yBAAa;;QAKpBC;eAAAA,sBAAU;;QACVC;eAAAA,iCAAqB;;QALdC;eAAAA,sBAAc;;QAUdC;eAAAA,8BAAc;;QAVEC;eAAAA,wBAAgB;;QAWhCC;eAAAA,kCAAgB;;QAEvBC;eAAAA,8CAAsB;;QAKfC;eAAAA,kCAAgB;;QAChBC;eAAAA,8BAAc;;QApBCC;eAAAA,4BAAgB;;QAiC/BC;eAAAA,6BAAe;;QAZfC;eAAAA,gDAAuB;;QArBUC;eAAAA,2BAAe;;QAsBhDC;eAAAA,sBAAU;;QAtBwCC;eAAAA,8BAAkB;;QAO3EC;eAAAA,4BAAgB;;QAChBC;eAAAA,8BAAkB;;QAClBC;eAAAA,+BAAmB;;QARsBC;eAAAA,oBAAY;;QAyBrDC;eAAAA,QAAG;;QACHC;eAAAA,gBAAW;;QAOJC;eAAAA,UAAI;;QACJC;eAAAA,wCAAmB;;QACnBC;eAAAA,oCAAiB;;QAnBxBC;eAAAA,8CAAsB;;QADtBC;eAAAA,2CAAmB;;QAqBZC;eAAAA,sCAAkB;;QACVC;eAAAA,qBAAK;;QAAEC;eAAAA,8BAAc;;;4BAtC+C;wBACtB;6BAChB;4BAQxC;gCACwB;kCACgC;wCAMxD;kCAC0B;gCACF;yCACS;4BACb;qBAUpB;8BACyB;sBACX;qCACe;mCACF;oCACC;gCACW;CAE9C,iGAAiG"}
|
|
@@ -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":";;;;;;;;;;;;;;;
|
|
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"}
|
package/lib/git/types.d.ts
CHANGED
|
@@ -51,6 +51,10 @@ 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 = Pick<ParsedRemoteBranch, "remoteBranch"> & {
|
|
55
|
+
/** Remote name, e.g. `origin`. */
|
|
56
|
+
remote: string;
|
|
57
|
+
};
|
|
54
58
|
export type GitStageOptions = {
|
|
55
59
|
/** File patterns to stage */
|
|
56
60
|
patterns: string[];
|
package/lib/git/types.js.map
CHANGED
|
@@ -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 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"}
|