workspace-tools 0.38.6 → 0.40.2
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/config.d.ts +8 -0
- package/lib/git/config.js +17 -0
- package/lib/git/config.js.map +1 -0
- package/lib/git/getDefaultRemoteBranch.js +2 -1
- package/lib/git/getDefaultRemoteBranch.js.map +1 -1
- package/lib/git/git.d.ts +30 -10
- package/lib/git/git.js +47 -9
- package/lib/git/git.js.map +1 -1
- package/lib/git/gitUtilities.d.ts +88 -50
- package/lib/git/gitUtilities.js +187 -314
- package/lib/git/gitUtilities.js.map +1 -1
- package/lib/git/index.d.ts +2 -1
- package/lib/git/index.js +9 -1
- package/lib/git/index.js.map +1 -1
- package/lib/git/types.d.ts +60 -0
- package/lib/git/types.js +3 -0
- package/lib/git/types.js.map +1 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +8 -5
- package/lib/index.js.map +1 -1
- package/lib/types/Catalogs.d.ts +11 -3
- package/lib/workspaces/catalogsToYaml.d.ts +8 -0
- package/lib/workspaces/catalogsToYaml.js +29 -0
- package/lib/workspaces/catalogsToYaml.js.map +1 -0
- package/lib/workspaces/{catalogs.d.ts → getCatalogVersion.d.ts} +0 -7
- package/lib/workspaces/{catalogs.js → getCatalogVersion.js} +13 -17
- package/lib/workspaces/getCatalogVersion.js.map +1 -0
- package/lib/workspaces/getCatalogs.d.ts +9 -0
- package/lib/workspaces/getCatalogs.js +17 -0
- package/lib/workspaces/getCatalogs.js.map +1 -0
- package/lib/workspaces/getChangedPackages.d.ts +49 -20
- package/lib/workspaces/getChangedPackages.js +39 -56
- package/lib/workspaces/getChangedPackages.js.map +1 -1
- package/lib/workspaces/getPackagesByFiles.d.ts +15 -6
- package/lib/workspaces/getPackagesByFiles.js +16 -17
- package/lib/workspaces/getPackagesByFiles.js.map +1 -1
- package/lib/workspaces/implementations/getWorkspaceUtilities.d.ts +1 -0
- package/lib/workspaces/implementations/getWorkspaceUtilities.js +1 -0
- package/lib/workspaces/implementations/getWorkspaceUtilities.js.map +1 -1
- package/lib/workspaces/implementations/pnpm.js +5 -2
- package/lib/workspaces/implementations/pnpm.js.map +1 -1
- package/lib/workspaces/implementations/yarn.js +6 -1
- package/lib/workspaces/implementations/yarn.js.map +1 -1
- package/package.json +1 -1
- package/lib/workspaces/catalogs.js.map +0 -1
package/lib/git/gitUtilities.js
CHANGED
|
@@ -5,57 +5,59 @@
|
|
|
5
5
|
//
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.listAllTrackedFiles = exports.getDefaultBranch = exports.parseRemoteBranch = exports.getRemoteBranch = exports.getParentBranch = exports.revertLocalChanges = exports.stageAndCommit = exports.commit = exports.stage = exports.init = exports.getFileAddedHash = exports.getCurrentHash = exports.getShortBranchName = exports.getFullBranchRef = exports.getBranchName = exports.getUserEmail = exports.getRecentCommitMessages = exports.getStagedChanges = exports.getChangesBetweenRefs = exports.getBranchChanges = exports.getChanges = exports.getUnstagedChanges = exports.fetchRemoteBranch = exports.fetchRemote = exports.getUntrackedChanges = void 0;
|
|
8
|
+
const config_1 = require("./config");
|
|
8
9
|
const git_1 = require("./git");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
throw new git_1.GitError(`Cannot gather information about untracked changes`, e);
|
|
21
|
-
}
|
|
10
|
+
const diffArgs = ["--no-pager", "diff", "--name-only", "--relative"];
|
|
11
|
+
function getUntrackedChanges(cwdOrOptions) {
|
|
12
|
+
const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
|
|
13
|
+
const results = (0, git_1.git)(["ls-files", "--others", "--exclude-standard"], {
|
|
14
|
+
description: "Gathering information about untracked changes",
|
|
15
|
+
throwOnError: true,
|
|
16
|
+
...options,
|
|
17
|
+
});
|
|
18
|
+
return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
|
|
22
19
|
}
|
|
23
20
|
exports.getUntrackedChanges = getUntrackedChanges;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
function fetchRemote(remoteOrOptions, cwd) {
|
|
22
|
+
const { remote, remoteBranch, options, ...gitOptions } = typeof remoteOrOptions === "string"
|
|
23
|
+
? ({ remote: remoteOrOptions, cwd: cwd })
|
|
24
|
+
: remoteOrOptions;
|
|
25
|
+
if (remoteBranch && !remote) {
|
|
26
|
+
throw new Error('Must provide "remote" when using "remoteBranch" option');
|
|
27
|
+
}
|
|
28
|
+
const fetchArgs = [
|
|
29
|
+
"fetch",
|
|
30
|
+
"--",
|
|
31
|
+
...(remote ? [remote] : []),
|
|
32
|
+
...(remoteBranch ? [remoteBranch] : []),
|
|
33
|
+
...(options || []),
|
|
34
|
+
];
|
|
35
|
+
(0, git_1.git)(fetchArgs, {
|
|
36
|
+
description: remote
|
|
37
|
+
? `Fetching ${remoteBranch ? `branch "${remoteBranch}" from ` : ""}remote "${remote}"`
|
|
38
|
+
: "Fetching all remotes",
|
|
39
|
+
throwOnError: true,
|
|
40
|
+
...gitOptions,
|
|
41
|
+
});
|
|
33
42
|
}
|
|
34
43
|
exports.fetchRemote = fetchRemote;
|
|
35
44
|
/**
|
|
36
|
-
* Fetch from the given remote and branch.
|
|
37
|
-
*
|
|
45
|
+
* Fetch from the given remote and branch. Throws an error on failure.
|
|
46
|
+
* @deprecated Use `fetchRemote({ remote, remoteBranch, cwd })`
|
|
38
47
|
*/
|
|
48
|
+
// TODO: move to fetch.ts
|
|
39
49
|
function fetchRemoteBranch(remote, remoteBranch, cwd) {
|
|
40
|
-
|
|
41
|
-
if (!results.success) {
|
|
42
|
-
throw new git_1.GitError(`Cannot fetch branch "${remoteBranch}" from remote "${remote}"`);
|
|
43
|
-
}
|
|
50
|
+
fetchRemote({ remote, remoteBranch, cwd, throwOnError: true });
|
|
44
51
|
}
|
|
45
52
|
exports.fetchRemoteBranch = fetchRemoteBranch;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return processGitOutput((0, git_1.git)(["--no-pager", "diff", "--name-only", "--relative"], { cwd }));
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
throw new git_1.GitError(`Cannot gather information about unstaged changes`, e);
|
|
58
|
-
}
|
|
53
|
+
function getUnstagedChanges(cwdOrOptions) {
|
|
54
|
+
const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
|
|
55
|
+
const results = (0, git_1.git)(diffArgs, {
|
|
56
|
+
description: "Gathering information about unstaged changes",
|
|
57
|
+
throwOnError: true,
|
|
58
|
+
...options,
|
|
59
|
+
});
|
|
60
|
+
return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
|
|
59
61
|
}
|
|
60
62
|
exports.getUnstagedChanges = getUnstagedChanges;
|
|
61
63
|
/**
|
|
@@ -63,259 +65,157 @@ exports.getUnstagedChanges = getUnstagedChanges;
|
|
|
63
65
|
* Throws an error on failure.
|
|
64
66
|
*
|
|
65
67
|
* @returns An array of relative file paths that have changed
|
|
68
|
+
* @deprecated Use `getBranchChanges({ branch, cwd })`
|
|
66
69
|
*/
|
|
70
|
+
// TODO: move to getChanges.ts
|
|
67
71
|
function getChanges(branch, cwd) {
|
|
68
|
-
|
|
69
|
-
return processGitOutput((0, git_1.git)(["--no-pager", "diff", "--relative", "--name-only", branch + "..."], { cwd }));
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
throw new git_1.GitError(`Cannot gather information about changes`, e);
|
|
73
|
-
}
|
|
72
|
+
return getChangesBetweenRefs({ fromRef: branch, cwd, throwOnError: true });
|
|
74
73
|
}
|
|
75
74
|
exports.getChanges = getChanges;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* @returns An array of relative file paths that have changed
|
|
80
|
-
*/
|
|
81
|
-
function getBranchChanges(branch, cwd) {
|
|
82
|
-
return getChangesBetweenRefs(/*from*/ branch, /*to*/ "", /*options*/ [], /*file pattern*/ "", cwd);
|
|
75
|
+
function getBranchChanges(branchOrOptions, cwd) {
|
|
76
|
+
const { branch, ...options } = typeof branchOrOptions === "string" ? { branch: branchOrOptions, cwd: cwd } : branchOrOptions;
|
|
77
|
+
return getChangesBetweenRefs({ fromRef: branch, throwOnError: true, ...options });
|
|
83
78
|
}
|
|
84
79
|
exports.getBranchChanges = getBranchChanges;
|
|
85
|
-
/**
|
|
86
|
-
* Gets file paths with changes between two git references (commits, branches, tags).
|
|
87
|
-
* Throws an error on failure.
|
|
88
|
-
*
|
|
89
|
-
* @param fromRef - The starting reference
|
|
90
|
-
* @param toRef - The ending reference
|
|
91
|
-
* @param options - Additional git diff options
|
|
92
|
-
* @param pattern - Optional file pattern to filter results
|
|
93
|
-
* @param cwd - The working directory
|
|
94
|
-
* @returns An array of file paths that have changed
|
|
95
|
-
*/
|
|
96
80
|
function getChangesBetweenRefs(fromRef, toRef, options, pattern, cwd) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
81
|
+
let gitOptions;
|
|
82
|
+
if (typeof fromRef === "string") {
|
|
83
|
+
gitOptions = { cwd: cwd };
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
({ fromRef, toRef, options, pattern, ...gitOptions } = fromRef);
|
|
87
|
+
}
|
|
88
|
+
const range = `${fromRef}...${toRef || ""}`;
|
|
89
|
+
const results = (0, git_1.git)([...diffArgs, ...(options || []), range, ...(pattern ? ["--", pattern] : [])], {
|
|
90
|
+
description: `Gathering information about changes between refs (${range})`,
|
|
91
|
+
throwOnError: true,
|
|
92
|
+
...gitOptions,
|
|
93
|
+
});
|
|
94
|
+
return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
|
|
111
95
|
}
|
|
112
96
|
exports.getChangesBetweenRefs = getChangesBetweenRefs;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return processGitOutput((0, git_1.git)(["--no-pager", "diff", "--relative", "--staged", "--name-only"], { cwd }));
|
|
122
|
-
}
|
|
123
|
-
catch (e) {
|
|
124
|
-
throw new git_1.GitError(`Cannot gather information about staged changes`, e);
|
|
125
|
-
}
|
|
97
|
+
function getStagedChanges(cwdOrOptions) {
|
|
98
|
+
const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
|
|
99
|
+
const results = (0, git_1.git)([...diffArgs, "--staged"], {
|
|
100
|
+
description: "Gathering information about staged changes",
|
|
101
|
+
throwOnError: true,
|
|
102
|
+
...options,
|
|
103
|
+
});
|
|
104
|
+
return (0, git_1.processGitOutput)(results, { excludeNodeModules: true });
|
|
126
105
|
}
|
|
127
106
|
exports.getStagedChanges = getStagedChanges;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
try {
|
|
136
|
-
const results = (0, git_1.git)(["log", "--decorate", "--pretty=format:%s", `${branch}..HEAD`], { cwd });
|
|
137
|
-
if (!results.success) {
|
|
138
|
-
return [];
|
|
139
|
-
}
|
|
140
|
-
return results.stdout
|
|
141
|
-
.split(/\n/)
|
|
142
|
-
.map((line) => line.trim())
|
|
143
|
-
.filter((line) => !!line);
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
throw new git_1.GitError(`Cannot gather information about recent commits`, e);
|
|
147
|
-
}
|
|
107
|
+
function getRecentCommitMessages(branchOrOptions, cwd) {
|
|
108
|
+
const { branch, ...options } = typeof branchOrOptions === "string" ? { branch: branchOrOptions, cwd: cwd } : branchOrOptions;
|
|
109
|
+
const results = (0, git_1.git)(["log", "--decorate", "--pretty=format:%s", `${branch}..HEAD`], {
|
|
110
|
+
description: `Getting recent commit messages for branch "${branch}"`,
|
|
111
|
+
...options,
|
|
112
|
+
});
|
|
113
|
+
return (0, git_1.processGitOutput)(results);
|
|
148
114
|
}
|
|
149
115
|
exports.getRecentCommitMessages = getRecentCommitMessages;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
*/
|
|
154
|
-
function getUserEmail(cwd) {
|
|
155
|
-
try {
|
|
156
|
-
const results = (0, git_1.git)(["config", "user.email"], { cwd });
|
|
157
|
-
return results.success ? results.stdout : null;
|
|
158
|
-
}
|
|
159
|
-
catch (e) {
|
|
160
|
-
throw new git_1.GitError(`Cannot gather information about user.email`, e);
|
|
161
|
-
}
|
|
116
|
+
function getUserEmail(cwdOrOptions) {
|
|
117
|
+
const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
|
|
118
|
+
return (0, config_1.getConfigValue)({ key: "user.email", ...options });
|
|
162
119
|
}
|
|
163
120
|
exports.getUserEmail = getUserEmail;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return results.success ? results.stdout : null;
|
|
172
|
-
}
|
|
173
|
-
catch (e) {
|
|
174
|
-
throw new git_1.GitError(`Cannot get branch name`, e);
|
|
175
|
-
}
|
|
121
|
+
function getBranchName(cwdOrOptions) {
|
|
122
|
+
const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
|
|
123
|
+
const results = (0, git_1.git)(["rev-parse", "--abbrev-ref", "HEAD"], {
|
|
124
|
+
description: "Getting current branch name",
|
|
125
|
+
...options,
|
|
126
|
+
});
|
|
127
|
+
return results.success ? results.stdout : null;
|
|
176
128
|
}
|
|
177
129
|
exports.getBranchName = getBranchName;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
* @returns The full branch reference (e.g., `refs/heads/branch-name`) if found, null otherwise
|
|
182
|
-
*/
|
|
183
|
-
function getFullBranchRef(branch, cwd) {
|
|
184
|
-
const showRefResults = (0, git_1.git)(["show-ref", "--heads", branch], { cwd });
|
|
130
|
+
function getFullBranchRef(branchOrOptions, cwd) {
|
|
131
|
+
const { branch, ...options } = typeof branchOrOptions === "string" ? { branch: branchOrOptions, cwd: cwd } : branchOrOptions;
|
|
132
|
+
const showRefResults = (0, git_1.git)(["show-ref", "--heads", branch], options);
|
|
185
133
|
return showRefResults.success ? showRefResults.stdout.split(" ")[1] : null;
|
|
186
134
|
}
|
|
187
135
|
exports.getFullBranchRef = getFullBranchRef;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
function getShortBranchName(fullBranchRef, cwd) {
|
|
195
|
-
const showRefResults = (0, git_1.git)(["name-rev", "--name-only", fullBranchRef], {
|
|
196
|
-
cwd,
|
|
197
|
-
});
|
|
198
|
-
return showRefResults.success ? showRefResults.stdout : null;
|
|
136
|
+
function getShortBranchName(refOrOptions, cwd) {
|
|
137
|
+
const { fullBranchRef, ...options } = typeof refOrOptions === "string" ? { fullBranchRef: refOrOptions, cwd: cwd } : refOrOptions;
|
|
138
|
+
// The original command `git name-rev --name-only` returned unreliable results if multiple
|
|
139
|
+
// named refs point to the same commit as the branch.
|
|
140
|
+
const showRefResults = (0, git_1.git)(["rev-parse", "--abbrev-ref", fullBranchRef], options);
|
|
141
|
+
return showRefResults.success ? showRefResults.stdout || null : null;
|
|
199
142
|
}
|
|
200
143
|
exports.getShortBranchName = getShortBranchName;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return results.success ? results.stdout : null;
|
|
209
|
-
}
|
|
210
|
-
catch (e) {
|
|
211
|
-
throw new git_1.GitError(`Cannot get current git hash`, e);
|
|
212
|
-
}
|
|
144
|
+
function getCurrentHash(cwdOrOptions) {
|
|
145
|
+
const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
|
|
146
|
+
const results = (0, git_1.git)(["rev-parse", "HEAD"], {
|
|
147
|
+
description: "Getting current git hash",
|
|
148
|
+
...options,
|
|
149
|
+
});
|
|
150
|
+
return results.success ? results.stdout : null;
|
|
213
151
|
}
|
|
214
152
|
exports.getCurrentHash = getCurrentHash;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
function getFileAddedHash(filename, cwd) {
|
|
220
|
-
const results = (0, git_1.git)(["rev-list", "--max-count=1", "HEAD", filename], { cwd });
|
|
221
|
-
if (results.success) {
|
|
222
|
-
return results.stdout.trim();
|
|
223
|
-
}
|
|
224
|
-
return undefined;
|
|
153
|
+
function getFileAddedHash(filenameOrOptions, cwd) {
|
|
154
|
+
const { filename, ...options } = typeof filenameOrOptions === "string" ? { filename: filenameOrOptions, cwd: cwd } : filenameOrOptions;
|
|
155
|
+
const results = (0, git_1.git)(["rev-list", "--max-count=1", "HEAD", filename], options);
|
|
156
|
+
return results.success ? results.stdout.trim() : undefined;
|
|
225
157
|
}
|
|
226
158
|
exports.getFileAddedHash = getFileAddedHash;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
*
|
|
232
|
-
* @param cwd - The directory to initialize the git repository in
|
|
233
|
-
* @param email - Optional email to set in git config
|
|
234
|
-
* @param username - Optional username to set in git config
|
|
235
|
-
*/
|
|
236
|
-
function init(cwd, email, username) {
|
|
237
|
-
(0, git_1.git)(["init"], { cwd });
|
|
238
|
-
const configLines = (0, git_1.git)(["config", "--list"], { cwd }).stdout.split("\n");
|
|
239
|
-
if (!configLines.find((line) => line.includes("user.name"))) {
|
|
159
|
+
function init(cwdOrOptions, _email, _username) {
|
|
160
|
+
const { email, username, ...options } = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions, email: _email, username: _username } : cwdOrOptions;
|
|
161
|
+
(0, git_1.git)(["init"], { ...options, throwOnError: true });
|
|
162
|
+
if (!(0, config_1.getConfigValue)({ key: "user.name", ...options })) {
|
|
240
163
|
if (!username) {
|
|
241
|
-
throw new
|
|
164
|
+
throw new Error("must include a username when initializing git repo");
|
|
242
165
|
}
|
|
243
|
-
(0, git_1.git)(["config", "user.name", username],
|
|
166
|
+
(0, git_1.git)(["config", "user.name", username], options);
|
|
244
167
|
}
|
|
245
|
-
if (!
|
|
168
|
+
if (!getUserEmail(options)) {
|
|
246
169
|
if (!email) {
|
|
247
170
|
throw new Error("must include a email when initializing git repo");
|
|
248
171
|
}
|
|
249
|
-
(0, git_1.git)(["config", "user.email", email],
|
|
172
|
+
(0, git_1.git)(["config", "user.email", email], options);
|
|
250
173
|
}
|
|
251
174
|
}
|
|
252
175
|
exports.init = init;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
(0, git_1.git)(["add", pattern], { cwd });
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
catch (e) {
|
|
263
|
-
throw new git_1.GitError(`Cannot stage changes`, e);
|
|
176
|
+
function stage(patternsOrOptions, cwd) {
|
|
177
|
+
const { patterns, ...options } = Array.isArray(patternsOrOptions)
|
|
178
|
+
? { patterns: patternsOrOptions, cwd: cwd }
|
|
179
|
+
: patternsOrOptions;
|
|
180
|
+
for (const pattern of patterns) {
|
|
181
|
+
(0, git_1.git)(["add", pattern], { ...options, description: `Staging changes (git add ${pattern})` });
|
|
264
182
|
}
|
|
265
183
|
}
|
|
266
184
|
exports.stage = stage;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
try {
|
|
277
|
-
const commitResults = (0, git_1.git)(["commit", "-m", message, ...options], { cwd });
|
|
278
|
-
if (!commitResults.success) {
|
|
279
|
-
throw new Error(`Cannot commit changes: ${commitResults.stdout} ${commitResults.stderr}`);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
catch (e) {
|
|
283
|
-
throw new git_1.GitError(`Cannot commit changes`, e);
|
|
284
|
-
}
|
|
185
|
+
function commit(messageOrOptions, _cwd, _options) {
|
|
186
|
+
const { message, options, ...gitOptions } = typeof messageOrOptions === "string"
|
|
187
|
+
? { message: messageOrOptions, cwd: _cwd, options: _options }
|
|
188
|
+
: messageOrOptions;
|
|
189
|
+
(0, git_1.git)(["commit", "-m", message, ...(options || [])], {
|
|
190
|
+
throwOnError: true,
|
|
191
|
+
description: "Committing changes",
|
|
192
|
+
...gitOptions,
|
|
193
|
+
});
|
|
285
194
|
}
|
|
286
195
|
exports.commit = commit;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
* @param message - The commit message
|
|
294
|
-
* @param cwd - The working directory
|
|
295
|
-
* @param commitOptions - Additional git commit options
|
|
296
|
-
*/
|
|
297
|
-
function stageAndCommit(patterns, message, cwd, commitOptions = []) {
|
|
298
|
-
stage(patterns, cwd);
|
|
299
|
-
commit(message, cwd, commitOptions);
|
|
196
|
+
function stageAndCommit(patternsOrOptions, message, cwd, commitOptions) {
|
|
197
|
+
const options = Array.isArray(patternsOrOptions)
|
|
198
|
+
? { patterns: patternsOrOptions, message: message, cwd: cwd, options: commitOptions }
|
|
199
|
+
: patternsOrOptions;
|
|
200
|
+
stage(options);
|
|
201
|
+
commit(options);
|
|
300
202
|
}
|
|
301
203
|
exports.stageAndCommit = stageAndCommit;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
* @returns True if the revert was successful, false otherwise
|
|
305
|
-
*/
|
|
306
|
-
function revertLocalChanges(cwd) {
|
|
204
|
+
function revertLocalChanges(cwdOrOptions) {
|
|
205
|
+
const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
|
|
307
206
|
const stash = `workspace-tools_${new Date().getTime()}`;
|
|
308
|
-
(0, git_1.git)(["stash", "push", "-u", "-m", stash], {
|
|
309
|
-
|
|
207
|
+
if (!(0, git_1.git)(["stash", "push", "-u", "-m", stash], options).success) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
const results = (0, git_1.git)(["stash", "list"], options);
|
|
310
211
|
if (results.success) {
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
212
|
+
const matched = results.stdout
|
|
213
|
+
.split(/\n/)
|
|
214
|
+
.find((line) => line.includes(stash))
|
|
215
|
+
?.match(/^[^:]+/);
|
|
216
|
+
if (matched) {
|
|
217
|
+
(0, git_1.git)(["stash", "drop", matched[0]], options);
|
|
218
|
+
return true;
|
|
319
219
|
}
|
|
320
220
|
}
|
|
321
221
|
return false;
|
|
@@ -323,11 +223,11 @@ function revertLocalChanges(cwd) {
|
|
|
323
223
|
exports.revertLocalChanges = revertLocalChanges;
|
|
324
224
|
/**
|
|
325
225
|
* Attempts to determine the parent branch of the current branch using `git show-branch`.
|
|
326
|
-
*
|
|
327
226
|
* @returns The parent branch name if found, null otherwise
|
|
227
|
+
* @deprecated Does not appear to be used
|
|
328
228
|
*/
|
|
329
229
|
function getParentBranch(cwd) {
|
|
330
|
-
const branchName = getBranchName(cwd);
|
|
230
|
+
const branchName = getBranchName({ cwd });
|
|
331
231
|
if (!branchName || branchName === "HEAD") {
|
|
332
232
|
return null;
|
|
333
233
|
}
|
|
@@ -341,75 +241,48 @@ function getParentBranch(cwd) {
|
|
|
341
241
|
return null;
|
|
342
242
|
}
|
|
343
243
|
exports.getParentBranch = getParentBranch;
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
*/
|
|
349
|
-
function getRemoteBranch(branch, cwd) {
|
|
350
|
-
const results = (0, git_1.git)(["rev-parse", "--abbrev-ref", "--symbolic-full-name", `${branch}@\{u\}`], { cwd });
|
|
351
|
-
if (results.success) {
|
|
352
|
-
return results.stdout.trim();
|
|
353
|
-
}
|
|
354
|
-
return null;
|
|
244
|
+
function getRemoteBranch(branchOrOptions, cwd) {
|
|
245
|
+
const options = typeof branchOrOptions === "string" ? { branch: branchOrOptions, cwd: cwd } : branchOrOptions;
|
|
246
|
+
const results = (0, git_1.git)(["rev-parse", "--abbrev-ref", "--symbolic-full-name", `${options.branch}@\{u\}`], options);
|
|
247
|
+
return results.success ? results.stdout.trim() : null;
|
|
355
248
|
}
|
|
356
249
|
exports.getRemoteBranch = getRemoteBranch;
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
remoteBranch
|
|
369
|
-
}
|
|
250
|
+
function parseRemoteBranch(branchOrOptions) {
|
|
251
|
+
if (typeof branchOrOptions === "string") {
|
|
252
|
+
const branch = branchOrOptions;
|
|
253
|
+
const firstSlashPos = branch.indexOf("/", 0);
|
|
254
|
+
return {
|
|
255
|
+
remote: branch.substring(0, firstSlashPos),
|
|
256
|
+
remoteBranch: branch.substring(firstSlashPos + 1),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const { branch, knownRemotes = ["origin", "upstream"], ...options } = branchOrOptions;
|
|
260
|
+
if (!branch.includes("/")) {
|
|
261
|
+
return { remote: "", remoteBranch: branch };
|
|
262
|
+
}
|
|
263
|
+
let remote = knownRemotes.find((remote) => branch.startsWith(`${remote}/`));
|
|
264
|
+
if (!remote) {
|
|
265
|
+
const remotes = (0, git_1.git)(["remote"], options).stdout.trim().split(/\n/);
|
|
266
|
+
remote = remotes.find((remote) => branch.startsWith(`${remote}/`));
|
|
267
|
+
}
|
|
268
|
+
if (remote) {
|
|
269
|
+
return { remote, remoteBranch: branch.slice(remote.length + 1) };
|
|
270
|
+
}
|
|
271
|
+
return { remote: "", remoteBranch: branch };
|
|
370
272
|
}
|
|
371
273
|
exports.parseRemoteBranch = parseRemoteBranch;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
*/
|
|
375
|
-
function getDefaultBranch(cwd) {
|
|
376
|
-
const result = (0, git_1.git)(["config", "init.defaultBranch"], { cwd });
|
|
274
|
+
function getDefaultBranch(cwdOrOptions) {
|
|
275
|
+
const options = typeof cwdOrOptions === "string" ? { cwd: cwdOrOptions } : cwdOrOptions;
|
|
377
276
|
// Default to the legacy 'master' for backwards compat and old git clients
|
|
378
|
-
return
|
|
277
|
+
return (0, config_1.getConfigValue)({ key: "init.defaultBranch", ...options }) || "master";
|
|
379
278
|
}
|
|
380
279
|
exports.getDefaultBranch = getDefaultBranch;
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
*/
|
|
388
|
-
function listAllTrackedFiles(patterns, cwd) {
|
|
389
|
-
const results = (0, git_1.git)(["ls-files", ...patterns], { cwd });
|
|
390
|
-
return results.success && results.stdout.trim() ? results.stdout.trim().split(/\n/) : [];
|
|
280
|
+
function listAllTrackedFiles(patternsOrOptions, cwd) {
|
|
281
|
+
const { patterns, ...options } = Array.isArray(patternsOrOptions)
|
|
282
|
+
? { patterns: patternsOrOptions, cwd: cwd }
|
|
283
|
+
: patternsOrOptions;
|
|
284
|
+
const results = (0, git_1.git)(["ls-files", ...patterns], { throwOnError: true, ...options });
|
|
285
|
+
return (0, git_1.processGitOutput)(results);
|
|
391
286
|
}
|
|
392
287
|
exports.listAllTrackedFiles = listAllTrackedFiles;
|
|
393
|
-
/**
|
|
394
|
-
* Processes git command output by splitting it into lines and filtering out empty lines and `node_modules`.
|
|
395
|
-
*
|
|
396
|
-
* If the command failed with stderr output, an error is thrown.
|
|
397
|
-
*
|
|
398
|
-
* @param output - The git command output to process
|
|
399
|
-
* @returns An array of lines (presumably file paths), or an empty array if the command failed
|
|
400
|
-
* without stderr output.
|
|
401
|
-
*/
|
|
402
|
-
function processGitOutput(output) {
|
|
403
|
-
if (!output.success) {
|
|
404
|
-
if (output.stderr) {
|
|
405
|
-
throw new Error(output.stderr);
|
|
406
|
-
}
|
|
407
|
-
// TODO: this inconsistency seems maybe not desirable?
|
|
408
|
-
return [];
|
|
409
|
-
}
|
|
410
|
-
return output.stdout
|
|
411
|
-
.split(/\n/)
|
|
412
|
-
.map((line) => line.trim())
|
|
413
|
-
.filter((line) => !!line && !line.includes("node_modules"));
|
|
414
|
-
}
|
|
415
288
|
//# sourceMappingURL=gitUtilities.js.map
|