workspace-tools 0.41.5 → 0.41.7
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/branchRefs.d.ts +36 -0
- package/lib/git/branchRefs.js +84 -0
- package/lib/git/branchRefs.js.map +1 -0
- package/lib/git/config.d.ts +16 -0
- package/lib/git/config.js +39 -4
- package/lib/git/config.js.map +1 -1
- package/lib/git/fetchRemote.d.ts +13 -0
- package/lib/git/fetchRemote.js +56 -0
- package/lib/git/fetchRemote.js.map +1 -0
- package/lib/git/getChanges.d.ts +54 -0
- package/lib/git/getChanges.js +138 -0
- package/lib/git/getChanges.js.map +1 -0
- package/lib/git/getCurrentHash.d.ts +8 -0
- package/lib/git/getCurrentHash.js +24 -0
- package/lib/git/getCurrentHash.js.map +1 -0
- package/lib/git/getDefaultRemote.d.ts +14 -3
- package/lib/git/getDefaultRemote.js +92 -53
- package/lib/git/getDefaultRemote.js.map +1 -1
- package/lib/git/getDefaultRemoteBranch.d.ts +29 -2
- package/lib/git/getDefaultRemoteBranch.js +61 -21
- package/lib/git/getDefaultRemoteBranch.js.map +1 -1
- package/lib/git/getFileAddedHash.d.ts +10 -0
- package/lib/git/getFileAddedHash.js +24 -0
- package/lib/git/getFileAddedHash.js.map +1 -0
- package/lib/git/getFileFromRef.d.ts +11 -0
- package/lib/git/getFileFromRef.js +22 -0
- package/lib/git/getFileFromRef.js.map +1 -0
- package/lib/git/getRecentCommitMessages.d.ts +10 -0
- package/lib/git/getRecentCommitMessages.js +27 -0
- package/lib/git/getRecentCommitMessages.js.map +1 -0
- package/lib/git/getRemotes.d.ts +14 -0
- package/lib/git/getRemotes.js +53 -0
- package/lib/git/getRemotes.js.map +1 -0
- package/lib/git/gitUtilities.d.ts +12 -212
- package/lib/git/gitUtilities.js +38 -448
- package/lib/git/gitUtilities.js.map +1 -1
- package/lib/git/index.d.ts +17 -5
- package/lib/git/index.js +123 -17
- package/lib/git/index.js.map +1 -1
- package/lib/git/init.d.ts +11 -0
- package/lib/git/init.js +48 -0
- package/lib/git/init.js.map +1 -0
- package/lib/git/listAllTrackedFiles.d.ts +12 -0
- package/lib/git/listAllTrackedFiles.js +25 -0
- package/lib/git/listAllTrackedFiles.js.map +1 -0
- package/lib/git/parseRemoteBranch.d.ts +26 -0
- package/lib/git/parseRemoteBranch.js +77 -0
- package/lib/git/parseRemoteBranch.js.map +1 -0
- package/lib/git/revertLocalChanges.d.ts +9 -0
- package/lib/git/revertLocalChanges.js +42 -0
- package/lib/git/revertLocalChanges.js.map +1 -0
- package/lib/git/stageAndCommit.d.ts +21 -0
- package/lib/git/stageAndCommit.js +69 -0
- package/lib/git/stageAndCommit.js.map +1 -0
- package/lib/git/types.d.ts +5 -2
- package/lib/git/types.js.map +1 -1
- package/lib/workspaces/getCatalogVersion.d.ts +8 -3
- package/lib/workspaces/getCatalogVersion.js +9 -3
- package/lib/workspaces/getCatalogVersion.js.map +1 -1
- package/package.json +1 -1
package/lib/git/gitUtilities.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// (could be split into separate files later if desired)
|
|
4
|
-
//
|
|
1
|
+
// File preserved for compatibility with existing imports.
|
|
2
|
+
// New utilities don't need to be added here.
|
|
5
3
|
"use strict";
|
|
6
4
|
Object.defineProperty(exports, "__esModule", {
|
|
7
5
|
value: true
|
|
@@ -17,7 +15,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
17
15
|
getCurrentHash: null,
|
|
18
16
|
getDefaultBranch: null,
|
|
19
17
|
getFileAddedHash: null,
|
|
20
|
-
getFileFromVersion: null,
|
|
21
18
|
getFullBranchRef: null,
|
|
22
19
|
getParentBranch: null,
|
|
23
20
|
getRecentCommitMessages: null,
|
|
@@ -42,418 +39,96 @@ function _export(target, all) {
|
|
|
42
39
|
}
|
|
43
40
|
_export(exports, {
|
|
44
41
|
get commit () {
|
|
45
|
-
return commit;
|
|
42
|
+
return _stageAndCommit.commit;
|
|
46
43
|
},
|
|
47
44
|
get fetchRemote () {
|
|
48
|
-
return fetchRemote;
|
|
45
|
+
return _fetchRemote.fetchRemote;
|
|
49
46
|
},
|
|
50
47
|
get fetchRemoteBranch () {
|
|
51
|
-
return fetchRemoteBranch;
|
|
48
|
+
return _fetchRemote.fetchRemoteBranch;
|
|
52
49
|
},
|
|
53
50
|
get getBranchChanges () {
|
|
54
|
-
return getBranchChanges;
|
|
51
|
+
return _getChanges.getBranchChanges;
|
|
55
52
|
},
|
|
56
53
|
get getBranchName () {
|
|
57
|
-
return getBranchName;
|
|
54
|
+
return _branchRefs.getBranchName;
|
|
58
55
|
},
|
|
59
56
|
get getChanges () {
|
|
60
|
-
return getChanges;
|
|
57
|
+
return _getChanges.getChanges;
|
|
61
58
|
},
|
|
62
59
|
get getChangesBetweenRefs () {
|
|
63
|
-
return getChangesBetweenRefs;
|
|
60
|
+
return _getChanges.getChangesBetweenRefs;
|
|
64
61
|
},
|
|
65
62
|
get getCurrentHash () {
|
|
66
|
-
return getCurrentHash;
|
|
63
|
+
return _getCurrentHash.getCurrentHash;
|
|
67
64
|
},
|
|
68
65
|
get getDefaultBranch () {
|
|
69
|
-
return getDefaultBranch;
|
|
66
|
+
return _config.getDefaultBranch;
|
|
70
67
|
},
|
|
71
68
|
get getFileAddedHash () {
|
|
72
|
-
return getFileAddedHash;
|
|
73
|
-
},
|
|
74
|
-
get getFileFromVersion () {
|
|
75
|
-
return getFileFromVersion;
|
|
69
|
+
return _getFileAddedHash.getFileAddedHash;
|
|
76
70
|
},
|
|
77
71
|
get getFullBranchRef () {
|
|
78
|
-
return getFullBranchRef;
|
|
72
|
+
return _branchRefs.getFullBranchRef;
|
|
79
73
|
},
|
|
80
74
|
get getParentBranch () {
|
|
81
75
|
return getParentBranch;
|
|
82
76
|
},
|
|
83
77
|
get getRecentCommitMessages () {
|
|
84
|
-
return getRecentCommitMessages;
|
|
78
|
+
return _getRecentCommitMessages.getRecentCommitMessages;
|
|
85
79
|
},
|
|
86
80
|
get getRemoteBranch () {
|
|
87
|
-
return getRemoteBranch;
|
|
81
|
+
return _branchRefs.getRemoteBranch;
|
|
88
82
|
},
|
|
89
83
|
get getShortBranchName () {
|
|
90
|
-
return getShortBranchName;
|
|
84
|
+
return _branchRefs.getShortBranchName;
|
|
91
85
|
},
|
|
92
86
|
get getStagedChanges () {
|
|
93
|
-
return getStagedChanges;
|
|
87
|
+
return _getChanges.getStagedChanges;
|
|
94
88
|
},
|
|
95
89
|
get getUnstagedChanges () {
|
|
96
|
-
return getUnstagedChanges;
|
|
90
|
+
return _getChanges.getUnstagedChanges;
|
|
97
91
|
},
|
|
98
92
|
get getUntrackedChanges () {
|
|
99
|
-
return getUntrackedChanges;
|
|
93
|
+
return _getChanges.getUntrackedChanges;
|
|
100
94
|
},
|
|
101
95
|
get getUserEmail () {
|
|
102
|
-
return getUserEmail;
|
|
96
|
+
return _config.getUserEmail;
|
|
103
97
|
},
|
|
104
98
|
get init () {
|
|
105
|
-
return init;
|
|
99
|
+
return _init.init;
|
|
106
100
|
},
|
|
107
101
|
get listAllTrackedFiles () {
|
|
108
|
-
return listAllTrackedFiles;
|
|
102
|
+
return _listAllTrackedFiles.listAllTrackedFiles;
|
|
109
103
|
},
|
|
110
104
|
get parseRemoteBranch () {
|
|
111
|
-
return parseRemoteBranch;
|
|
105
|
+
return _parseRemoteBranch.parseRemoteBranch;
|
|
112
106
|
},
|
|
113
107
|
get revertLocalChanges () {
|
|
114
|
-
return revertLocalChanges;
|
|
108
|
+
return _revertLocalChanges.revertLocalChanges;
|
|
115
109
|
},
|
|
116
110
|
get stage () {
|
|
117
|
-
return stage;
|
|
111
|
+
return _stageAndCommit.stage;
|
|
118
112
|
},
|
|
119
113
|
get stageAndCommit () {
|
|
120
|
-
return stageAndCommit;
|
|
114
|
+
return _stageAndCommit.stageAndCommit;
|
|
121
115
|
}
|
|
122
116
|
});
|
|
117
|
+
const _branchRefs = require("./branchRefs.js");
|
|
123
118
|
const _config = require("./config.js");
|
|
119
|
+
const _fetchRemote = require("./fetchRemote.js");
|
|
120
|
+
const _getChanges = require("./getChanges.js");
|
|
121
|
+
const _getCurrentHash = require("./getCurrentHash.js");
|
|
122
|
+
const _getFileAddedHash = require("./getFileAddedHash.js");
|
|
123
|
+
const _getRecentCommitMessages = require("./getRecentCommitMessages.js");
|
|
124
|
+
const _init = require("./init.js");
|
|
125
|
+
const _listAllTrackedFiles = require("./listAllTrackedFiles.js");
|
|
126
|
+
const _parseRemoteBranch = require("./parseRemoteBranch.js");
|
|
127
|
+
const _revertLocalChanges = require("./revertLocalChanges.js");
|
|
128
|
+
const _stageAndCommit = require("./stageAndCommit.js");
|
|
124
129
|
const _git = require("./git.js");
|
|
125
|
-
const diffArgs = [
|
|
126
|
-
"--no-pager",
|
|
127
|
-
"diff",
|
|
128
|
-
"--name-only",
|
|
129
|
-
"--relative"
|
|
130
|
-
];
|
|
131
|
-
function getUntrackedChanges(cwdOrOptions) {
|
|
132
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
133
|
-
cwd: cwdOrOptions
|
|
134
|
-
} : cwdOrOptions;
|
|
135
|
-
const results = (0, _git.git)([
|
|
136
|
-
"ls-files",
|
|
137
|
-
"--others",
|
|
138
|
-
"--exclude-standard"
|
|
139
|
-
], {
|
|
140
|
-
description: "Gathering information about untracked changes",
|
|
141
|
-
throwOnError: true,
|
|
142
|
-
...options
|
|
143
|
-
});
|
|
144
|
-
return (0, _git.processGitOutput)(results, {
|
|
145
|
-
excludeNodeModules: true
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
function fetchRemote(remoteOrOptions, cwd) {
|
|
149
|
-
const { remote, remoteBranch, options, ...gitOptions } = typeof remoteOrOptions === "string" ? {
|
|
150
|
-
remote: remoteOrOptions,
|
|
151
|
-
cwd: cwd
|
|
152
|
-
} : remoteOrOptions;
|
|
153
|
-
if (remoteBranch && !remote) {
|
|
154
|
-
throw new Error('Must provide "remote" when using "remoteBranch" option');
|
|
155
|
-
}
|
|
156
|
-
const fetchArgs = [
|
|
157
|
-
"fetch",
|
|
158
|
-
"--",
|
|
159
|
-
...remote ? [
|
|
160
|
-
remote
|
|
161
|
-
] : [],
|
|
162
|
-
...remoteBranch ? [
|
|
163
|
-
remoteBranch
|
|
164
|
-
] : [],
|
|
165
|
-
...options || []
|
|
166
|
-
];
|
|
167
|
-
(0, _git.git)(fetchArgs, {
|
|
168
|
-
description: remote ? `Fetching ${remoteBranch ? `branch "${remoteBranch}" from ` : ""}remote "${remote}"` : "Fetching all remotes",
|
|
169
|
-
throwOnError: true,
|
|
170
|
-
...gitOptions
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
function fetchRemoteBranch(remote, remoteBranch, cwd) {
|
|
174
|
-
fetchRemote({
|
|
175
|
-
remote,
|
|
176
|
-
remoteBranch,
|
|
177
|
-
cwd,
|
|
178
|
-
throwOnError: true
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
function getUnstagedChanges(cwdOrOptions) {
|
|
182
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
183
|
-
cwd: cwdOrOptions
|
|
184
|
-
} : cwdOrOptions;
|
|
185
|
-
const results = (0, _git.git)(diffArgs, {
|
|
186
|
-
description: "Gathering information about unstaged changes",
|
|
187
|
-
throwOnError: true,
|
|
188
|
-
...options
|
|
189
|
-
});
|
|
190
|
-
return (0, _git.processGitOutput)(results, {
|
|
191
|
-
excludeNodeModules: true
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
function getChanges(branch, cwd) {
|
|
195
|
-
return getChangesBetweenRefs({
|
|
196
|
-
fromRef: branch,
|
|
197
|
-
cwd,
|
|
198
|
-
throwOnError: true
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
function getBranchChanges(branchOrOptions, cwd) {
|
|
202
|
-
const { branch, ...options } = typeof branchOrOptions === "string" ? {
|
|
203
|
-
branch: branchOrOptions,
|
|
204
|
-
cwd: cwd
|
|
205
|
-
} : branchOrOptions;
|
|
206
|
-
return getChangesBetweenRefs({
|
|
207
|
-
fromRef: branch,
|
|
208
|
-
throwOnError: true,
|
|
209
|
-
...options
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
function getChangesBetweenRefs(fromRef, toRef, options, pattern, cwd) {
|
|
213
|
-
let gitOptions;
|
|
214
|
-
if (typeof fromRef === "string") {
|
|
215
|
-
gitOptions = {
|
|
216
|
-
cwd: cwd
|
|
217
|
-
};
|
|
218
|
-
} else {
|
|
219
|
-
({ fromRef, toRef, options, pattern, ...gitOptions } = fromRef);
|
|
220
|
-
}
|
|
221
|
-
const range = `${fromRef}...${toRef || ""}`;
|
|
222
|
-
const results = (0, _git.git)([
|
|
223
|
-
...diffArgs,
|
|
224
|
-
...options || [],
|
|
225
|
-
range,
|
|
226
|
-
...pattern ? [
|
|
227
|
-
"--",
|
|
228
|
-
pattern
|
|
229
|
-
] : []
|
|
230
|
-
], {
|
|
231
|
-
description: `Gathering information about changes between refs (${range})`,
|
|
232
|
-
throwOnError: true,
|
|
233
|
-
...gitOptions
|
|
234
|
-
});
|
|
235
|
-
return (0, _git.processGitOutput)(results, {
|
|
236
|
-
excludeNodeModules: true
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
function getStagedChanges(cwdOrOptions) {
|
|
240
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
241
|
-
cwd: cwdOrOptions
|
|
242
|
-
} : cwdOrOptions;
|
|
243
|
-
const results = (0, _git.git)([
|
|
244
|
-
...diffArgs,
|
|
245
|
-
"--staged"
|
|
246
|
-
], {
|
|
247
|
-
description: "Gathering information about staged changes",
|
|
248
|
-
throwOnError: true,
|
|
249
|
-
...options
|
|
250
|
-
});
|
|
251
|
-
return (0, _git.processGitOutput)(results, {
|
|
252
|
-
excludeNodeModules: true
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
function getRecentCommitMessages(branchOrOptions, cwd) {
|
|
256
|
-
const { branch, ...options } = typeof branchOrOptions === "string" ? {
|
|
257
|
-
branch: branchOrOptions,
|
|
258
|
-
cwd: cwd
|
|
259
|
-
} : branchOrOptions;
|
|
260
|
-
const results = (0, _git.git)([
|
|
261
|
-
"log",
|
|
262
|
-
"--decorate",
|
|
263
|
-
"--pretty=format:%s",
|
|
264
|
-
`${branch}..HEAD`
|
|
265
|
-
], {
|
|
266
|
-
description: `Getting recent commit messages for branch "${branch}"`,
|
|
267
|
-
...options
|
|
268
|
-
});
|
|
269
|
-
return (0, _git.processGitOutput)(results);
|
|
270
|
-
}
|
|
271
|
-
function getUserEmail(cwdOrOptions) {
|
|
272
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
273
|
-
cwd: cwdOrOptions
|
|
274
|
-
} : cwdOrOptions;
|
|
275
|
-
return (0, _config.getConfigValue)({
|
|
276
|
-
key: "user.email",
|
|
277
|
-
...options
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
function getBranchName(cwdOrOptions) {
|
|
281
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
282
|
-
cwd: cwdOrOptions
|
|
283
|
-
} : cwdOrOptions;
|
|
284
|
-
const results = (0, _git.git)([
|
|
285
|
-
"rev-parse",
|
|
286
|
-
"--abbrev-ref",
|
|
287
|
-
"HEAD"
|
|
288
|
-
], {
|
|
289
|
-
description: "Getting current branch name",
|
|
290
|
-
...options
|
|
291
|
-
});
|
|
292
|
-
return results.success ? results.stdout : null;
|
|
293
|
-
}
|
|
294
|
-
function getFullBranchRef(branchOrOptions, cwd) {
|
|
295
|
-
const { branch, ...options } = typeof branchOrOptions === "string" ? {
|
|
296
|
-
branch: branchOrOptions,
|
|
297
|
-
cwd: cwd
|
|
298
|
-
} : branchOrOptions;
|
|
299
|
-
const showRefResults = (0, _git.git)([
|
|
300
|
-
"show-ref",
|
|
301
|
-
"--heads",
|
|
302
|
-
branch
|
|
303
|
-
], options);
|
|
304
|
-
return showRefResults.success ? showRefResults.stdout.split(" ")[1] : null;
|
|
305
|
-
}
|
|
306
|
-
function getShortBranchName(refOrOptions, cwd) {
|
|
307
|
-
const { fullBranchRef, ...options } = typeof refOrOptions === "string" ? {
|
|
308
|
-
fullBranchRef: refOrOptions,
|
|
309
|
-
cwd: cwd
|
|
310
|
-
} : refOrOptions;
|
|
311
|
-
// The original command `git name-rev --name-only` returned unreliable results if multiple
|
|
312
|
-
// named refs point to the same commit as the branch.
|
|
313
|
-
const showRefResults = (0, _git.git)([
|
|
314
|
-
"rev-parse",
|
|
315
|
-
"--abbrev-ref",
|
|
316
|
-
fullBranchRef
|
|
317
|
-
], options);
|
|
318
|
-
return showRefResults.success ? showRefResults.stdout || null : null;
|
|
319
|
-
}
|
|
320
|
-
function getCurrentHash(cwdOrOptions) {
|
|
321
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
322
|
-
cwd: cwdOrOptions
|
|
323
|
-
} : cwdOrOptions;
|
|
324
|
-
const results = (0, _git.git)([
|
|
325
|
-
"rev-parse",
|
|
326
|
-
"HEAD"
|
|
327
|
-
], {
|
|
328
|
-
description: "Getting current git hash",
|
|
329
|
-
...options
|
|
330
|
-
});
|
|
331
|
-
return results.success ? results.stdout : null;
|
|
332
|
-
}
|
|
333
|
-
function getFileAddedHash(filenameOrOptions, cwd) {
|
|
334
|
-
const { filename, ...options } = typeof filenameOrOptions === "string" ? {
|
|
335
|
-
filename: filenameOrOptions,
|
|
336
|
-
cwd: cwd
|
|
337
|
-
} : filenameOrOptions;
|
|
338
|
-
const results = (0, _git.git)([
|
|
339
|
-
"rev-list",
|
|
340
|
-
"--max-count=1",
|
|
341
|
-
"HEAD",
|
|
342
|
-
filename
|
|
343
|
-
], options);
|
|
344
|
-
return results.success ? results.stdout.trim() : undefined;
|
|
345
|
-
}
|
|
346
|
-
function init(cwdOrOptions, _email, _username) {
|
|
347
|
-
const { email, username, ...options } = typeof cwdOrOptions === "string" ? {
|
|
348
|
-
cwd: cwdOrOptions,
|
|
349
|
-
email: _email,
|
|
350
|
-
username: _username
|
|
351
|
-
} : cwdOrOptions;
|
|
352
|
-
(0, _git.git)([
|
|
353
|
-
"init"
|
|
354
|
-
], {
|
|
355
|
-
...options,
|
|
356
|
-
throwOnError: true
|
|
357
|
-
});
|
|
358
|
-
if (!(0, _config.getConfigValue)({
|
|
359
|
-
key: "user.name",
|
|
360
|
-
...options
|
|
361
|
-
})) {
|
|
362
|
-
if (!username) {
|
|
363
|
-
throw new Error("must include a username when initializing git repo");
|
|
364
|
-
}
|
|
365
|
-
(0, _git.git)([
|
|
366
|
-
"config",
|
|
367
|
-
"user.name",
|
|
368
|
-
username
|
|
369
|
-
], options);
|
|
370
|
-
}
|
|
371
|
-
if (!getUserEmail(options)) {
|
|
372
|
-
if (!email) {
|
|
373
|
-
throw new Error("must include a email when initializing git repo");
|
|
374
|
-
}
|
|
375
|
-
(0, _git.git)([
|
|
376
|
-
"config",
|
|
377
|
-
"user.email",
|
|
378
|
-
email
|
|
379
|
-
], options);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
function stage(patternsOrOptions, cwd) {
|
|
383
|
-
const { patterns, ...options } = Array.isArray(patternsOrOptions) ? {
|
|
384
|
-
patterns: patternsOrOptions,
|
|
385
|
-
cwd: cwd
|
|
386
|
-
} : patternsOrOptions;
|
|
387
|
-
for (const pattern of patterns){
|
|
388
|
-
(0, _git.git)([
|
|
389
|
-
"add",
|
|
390
|
-
pattern
|
|
391
|
-
], {
|
|
392
|
-
...options,
|
|
393
|
-
description: `Staging changes (git add ${pattern})`
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
function commit(messageOrOptions, _cwd, _options) {
|
|
398
|
-
const { message, options, ...gitOptions } = typeof messageOrOptions === "string" ? {
|
|
399
|
-
message: messageOrOptions,
|
|
400
|
-
cwd: _cwd,
|
|
401
|
-
options: _options
|
|
402
|
-
} : messageOrOptions;
|
|
403
|
-
(0, _git.git)([
|
|
404
|
-
"commit",
|
|
405
|
-
"-m",
|
|
406
|
-
message,
|
|
407
|
-
...options || []
|
|
408
|
-
], {
|
|
409
|
-
throwOnError: true,
|
|
410
|
-
description: "Committing changes",
|
|
411
|
-
...gitOptions
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
function stageAndCommit(patternsOrOptions, message, cwd, commitOptions) {
|
|
415
|
-
const options = Array.isArray(patternsOrOptions) ? {
|
|
416
|
-
patterns: patternsOrOptions,
|
|
417
|
-
message: message,
|
|
418
|
-
cwd: cwd,
|
|
419
|
-
options: commitOptions
|
|
420
|
-
} : patternsOrOptions;
|
|
421
|
-
stage(options);
|
|
422
|
-
commit(options);
|
|
423
|
-
}
|
|
424
|
-
function revertLocalChanges(cwdOrOptions) {
|
|
425
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
426
|
-
cwd: cwdOrOptions
|
|
427
|
-
} : cwdOrOptions;
|
|
428
|
-
const stash = `workspace-tools_${new Date().getTime()}`;
|
|
429
|
-
if (!(0, _git.git)([
|
|
430
|
-
"stash",
|
|
431
|
-
"push",
|
|
432
|
-
"-u",
|
|
433
|
-
"-m",
|
|
434
|
-
stash
|
|
435
|
-
], options).success) {
|
|
436
|
-
return false;
|
|
437
|
-
}
|
|
438
|
-
const results = (0, _git.git)([
|
|
439
|
-
"stash",
|
|
440
|
-
"list"
|
|
441
|
-
], options);
|
|
442
|
-
if (results.success) {
|
|
443
|
-
const matched = results.stdout.split(/\n/).find((line)=>line.includes(stash))?.match(/^[^:]+/);
|
|
444
|
-
if (matched) {
|
|
445
|
-
(0, _git.git)([
|
|
446
|
-
"stash",
|
|
447
|
-
"drop",
|
|
448
|
-
matched[0]
|
|
449
|
-
], options);
|
|
450
|
-
return true;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
130
|
function getParentBranch(cwd) {
|
|
456
|
-
const branchName = getBranchName({
|
|
131
|
+
const branchName = (0, _branchRefs.getBranchName)({
|
|
457
132
|
cwd
|
|
458
133
|
});
|
|
459
134
|
if (!branchName || branchName === "HEAD") {
|
|
@@ -473,88 +148,3 @@ function getParentBranch(cwd) {
|
|
|
473
148
|
}
|
|
474
149
|
return null;
|
|
475
150
|
}
|
|
476
|
-
function getRemoteBranch(branchOrOptions, cwd) {
|
|
477
|
-
const options = typeof branchOrOptions === "string" ? {
|
|
478
|
-
branch: branchOrOptions,
|
|
479
|
-
cwd: cwd
|
|
480
|
-
} : branchOrOptions;
|
|
481
|
-
const results = (0, _git.git)([
|
|
482
|
-
"rev-parse",
|
|
483
|
-
"--abbrev-ref",
|
|
484
|
-
"--symbolic-full-name",
|
|
485
|
-
`${options.branch}@{u}`
|
|
486
|
-
], options);
|
|
487
|
-
return results.success ? results.stdout.trim() : null;
|
|
488
|
-
}
|
|
489
|
-
function parseRemoteBranch(branchOrOptions) {
|
|
490
|
-
if (typeof branchOrOptions === "string") {
|
|
491
|
-
const branch = branchOrOptions;
|
|
492
|
-
const firstSlashPos = branch.indexOf("/", 0);
|
|
493
|
-
return {
|
|
494
|
-
remote: branch.substring(0, firstSlashPos),
|
|
495
|
-
remoteBranch: branch.substring(firstSlashPos + 1)
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
const { branch, knownRemotes = [
|
|
499
|
-
"origin",
|
|
500
|
-
"upstream"
|
|
501
|
-
], ...options } = branchOrOptions;
|
|
502
|
-
if (!branch.includes("/")) {
|
|
503
|
-
return {
|
|
504
|
-
remote: "",
|
|
505
|
-
remoteBranch: branch
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
let remote = knownRemotes.find((r)=>branch.startsWith(`${r}/`));
|
|
509
|
-
if (!remote) {
|
|
510
|
-
const remotes = (0, _git.git)([
|
|
511
|
-
"remote"
|
|
512
|
-
], options).stdout.trim().split(/\n/);
|
|
513
|
-
remote = remotes.find((r)=>branch.startsWith(`${r}/`));
|
|
514
|
-
}
|
|
515
|
-
if (remote) {
|
|
516
|
-
return {
|
|
517
|
-
remote,
|
|
518
|
-
remoteBranch: branch.slice(remote.length + 1)
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
return {
|
|
522
|
-
remote: "",
|
|
523
|
-
remoteBranch: branch
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
function getDefaultBranch(cwdOrOptions) {
|
|
527
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
528
|
-
cwd: cwdOrOptions
|
|
529
|
-
} : cwdOrOptions;
|
|
530
|
-
// Default to the legacy 'master' for backwards compat and old git clients
|
|
531
|
-
return (0, _config.getConfigValue)({
|
|
532
|
-
key: "init.defaultBranch",
|
|
533
|
-
...options
|
|
534
|
-
}) || "master";
|
|
535
|
-
}
|
|
536
|
-
function listAllTrackedFiles(patternsOrOptions, cwd) {
|
|
537
|
-
const { patterns, ...options } = Array.isArray(patternsOrOptions) ? {
|
|
538
|
-
patterns: patternsOrOptions,
|
|
539
|
-
cwd: cwd
|
|
540
|
-
} : patternsOrOptions;
|
|
541
|
-
const results = (0, _git.git)([
|
|
542
|
-
"ls-files",
|
|
543
|
-
...patterns
|
|
544
|
-
], {
|
|
545
|
-
throwOnError: true,
|
|
546
|
-
...options
|
|
547
|
-
});
|
|
548
|
-
return (0, _git.processGitOutput)(results);
|
|
549
|
-
}
|
|
550
|
-
function getFileFromVersion(params) {
|
|
551
|
-
const { filePath, ref, ...options } = params;
|
|
552
|
-
const result = (0, _git.git)([
|
|
553
|
-
"show",
|
|
554
|
-
`${ref}:${filePath}`
|
|
555
|
-
], {
|
|
556
|
-
description: `Getting file ${filePath} at ref ${ref}`,
|
|
557
|
-
...options
|
|
558
|
-
});
|
|
559
|
-
return result.success ? result.stdout : undefined;
|
|
560
|
-
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/git/gitUtilities.ts"],"sourcesContent":["//\n// Assorted other git utilities\n// (could be split into separate files later if desired)\n//\n\nimport { getConfigValue } from \"./config.js\";\nimport { git, processGitOutput } from \"./git.js\";\nimport type {\n GetChangesBetweenRefsOptions,\n GitBranchOptions,\n GitCommitOptions,\n GitCommonOptions,\n GitFetchOptions,\n GitInitOptions,\n GitStageOptions,\n ParsedRemoteBranch,\n ParseRemoteBranchOptions,\n} from \"./types.js\";\n\nconst diffArgs = [\"--no-pager\", \"diff\", \"--name-only\", \"--relative\"];\n\n/**\n * Get a list of files with untracked changes.\n * Throws an error on failure by default.\n *\n * @returns An array of file paths with untracked changes\n */\n// TODO: move to getChanges.ts\nexport function getUntrackedChanges(options: GitCommonOptions): string[];\n/** @deprecated Use object params version */\nexport function getUntrackedChanges(cwd: string): string[];\nexport function getUntrackedChanges(cwdOrOptions: string | GitCommonOptions): string[] {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([\"ls-files\", \"--others\", \"--exclude-standard\"], {\n description: \"Gathering information about untracked changes\",\n throwOnError: true,\n ...options,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Fetch from the given remote (and optionally branch) or all remotes.\n * Throws an error on failure by default.\n */\n// TODO: move to fetch.ts\nexport function fetchRemote(options: GitFetchOptions): void;\n/** @deprecated Use object params version */\nexport function fetchRemote(remote: string, cwd: string): void;\nexport function fetchRemote(remoteOrOptions: string | GitFetchOptions, cwd?: string): void {\n const { remote, remoteBranch, options, ...gitOptions } =\n typeof remoteOrOptions === \"string\"\n ? ({ remote: remoteOrOptions, cwd: cwd! } satisfies GitFetchOptions)\n : remoteOrOptions;\n\n if (remoteBranch && !remote) {\n throw new Error('Must provide \"remote\" when using \"remoteBranch\" option');\n }\n\n const fetchArgs = [\n \"fetch\",\n \"--\",\n ...(remote ? [remote] : []),\n ...(remoteBranch ? [remoteBranch] : []),\n ...(options || []),\n ];\n\n git(fetchArgs, {\n description: remote\n ? `Fetching ${remoteBranch ? `branch \"${remoteBranch}\" from ` : \"\"}remote \"${remote}\"`\n : \"Fetching all remotes\",\n throwOnError: true,\n ...gitOptions,\n });\n}\n\n/**\n * Fetch from the given remote and branch. Throws an error on failure.\n * @deprecated Use `fetchRemote({ remote, remoteBranch, cwd })`\n */\n// TODO: move to fetch.ts\nexport function fetchRemoteBranch(remote: string, remoteBranch: string, cwd: string): void {\n fetchRemote({ remote, remoteBranch, cwd, throwOnError: true });\n}\n\n/**\n * Gets file paths with changes that have not been staged yet.\n * Throws an error on failure by default.\n *\n * @returns An array of relative file paths with unstaged changes\n */\n// TODO: move to getChanges.ts\nexport function getUnstagedChanges(options: GitCommonOptions): string[];\n/** @deprecated Use object params version */\nexport function getUnstagedChanges(cwd: string): string[];\nexport function getUnstagedChanges(cwdOrOptions: string | GitCommonOptions): string[] {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git(diffArgs, {\n description: \"Gathering information about unstaged changes\",\n throwOnError: true,\n ...options,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Gets file paths with changes between the current branch and the given branch.\n * Throws an error on failure.\n *\n * @returns An array of relative file paths that have changed\n * @deprecated Use `getBranchChanges({ branch, cwd })`\n */\n// TODO: move to getChanges.ts\nexport function getChanges(branch: string, cwd: string): string[] {\n return getChangesBetweenRefs({ fromRef: branch, cwd, throwOnError: true });\n}\n\n/**\n * Gets file paths with changes between the branch and the merge-base.\n * Throws an error on failure by default.\n *\n * @returns An array of relative file paths that have changed\n */\n// TODO: move to getChanges.ts\nexport function getBranchChanges(options: GitBranchOptions): string[];\n/** @deprecated Use object params version */\nexport function getBranchChanges(branch: string, cwd: string): string[];\nexport function getBranchChanges(branchOrOptions: string | GitBranchOptions, cwd?: string): string[] {\n const { branch, ...options } =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n return getChangesBetweenRefs({ fromRef: branch, throwOnError: true, ...options });\n}\n\n/**\n * Gets file paths with changes between two git references (commits, branches, tags).\n * Throws an error on failure by default.\n *\n * @returns An array of file paths that have changed\n */\n// TODO: move to getChanges.ts\nexport function getChangesBetweenRefs(options: GetChangesBetweenRefsOptions): string[];\n/** @deprecated Use object param version */\nexport function getChangesBetweenRefs(\n fromRef: string,\n toRef: string,\n options: string[],\n pattern: string,\n cwd: string\n): string[];\nexport function getChangesBetweenRefs(\n fromRef: string | GetChangesBetweenRefsOptions,\n toRef?: string,\n options?: string[],\n pattern?: string,\n cwd?: string\n): string[] {\n let gitOptions: GitCommonOptions;\n if (typeof fromRef === \"string\") {\n gitOptions = { cwd: cwd! };\n } else {\n ({ fromRef, toRef, options, pattern, ...gitOptions } = fromRef);\n }\n\n const range = `${fromRef}...${toRef || \"\"}`;\n const results = git([...diffArgs, ...(options || []), range, ...(pattern ? [\"--\", pattern] : [])], {\n description: `Gathering information about changes between refs (${range})`,\n throwOnError: true,\n ...gitOptions,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Gets all files with staged changes (files added to the index).\n * Throws an error on failure by default.\n *\n * @returns An array of relative file paths that have been staged\n */\n// TODO: move to getChanges.ts\nexport function getStagedChanges(options: GitCommonOptions): string[];\n/** @deprecated Use object params version */\nexport function getStagedChanges(cwd: string): string[];\nexport function getStagedChanges(cwdOrOptions: string | GitCommonOptions): string[] {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([...diffArgs, \"--staged\"], {\n description: \"Gathering information about staged changes\",\n throwOnError: true,\n ...options,\n });\n return processGitOutput(results, { excludeNodeModules: true });\n}\n\n/**\n * Gets recent commit messages between the specified parent branch and HEAD.\n * By default, returns an empty array if the operation fails.\n *\n * @returns An array of commit message strings\n */\n// TODO: move to history.ts\nexport function getRecentCommitMessages(options: GitBranchOptions): string[];\n/** @deprecated Use object params version */\nexport function getRecentCommitMessages(branch: string, cwd: string): string[];\nexport function getRecentCommitMessages(branchOrOptions: string | GitBranchOptions, cwd?: string): string[] {\n const { branch, ...options } =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n const results = git([\"log\", \"--decorate\", \"--pretty=format:%s\", `${branch}..HEAD`], {\n description: `Getting recent commit messages for branch \"${branch}\"`,\n ...options,\n });\n return processGitOutput(results);\n}\n\n/**\n * Gets the user email from the git config.\n * @returns The email string if found, null otherwise\n */\n// TODO: move to config.ts\nexport function getUserEmail(options: GitCommonOptions): string | null;\n/** @deprecated Use object params version */\nexport function getUserEmail(cwd: string): string | null;\nexport function getUserEmail(cwdOrOptions: string | GitCommonOptions): string | null {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n return getConfigValue({ key: \"user.email\", ...options });\n}\n\n/**\n * Gets the current branch name.\n * In detached HEAD state, returns \"HEAD\".\n *\n * @returns The branch name if successful, null otherwise\n */\n// TODO: move to refs.ts\nexport function getBranchName(options: GitCommonOptions): string | null;\n/** @deprecated Use object params version */\nexport function getBranchName(cwd: string): string | null;\nexport function getBranchName(cwdOrOptions: string | GitCommonOptions): string | null {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([\"rev-parse\", \"--abbrev-ref\", \"HEAD\"], {\n description: \"Getting current branch name\",\n ...options,\n });\n return results.success ? results.stdout : null;\n}\n\n/**\n * Gets the full reference path for a given branch.\n * `branch` here is the short branch name, e.g. `branch-name`.\n * @returns The full branch reference (e.g., `refs/heads/branch-name`) if found, null otherwise\n */\n// TODO: move to refs.ts\nexport function getFullBranchRef(options: GitBranchOptions): string | null;\n/** @deprecated Use object params version */\nexport function getFullBranchRef(branch: string, cwd: string): string | null;\nexport function getFullBranchRef(branchOrOptions: string | GitBranchOptions, cwd?: string): string | null {\n const { branch, ...options } =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n const showRefResults = git([\"show-ref\", \"--heads\", branch], options);\n\n return showRefResults.success ? showRefResults.stdout.split(\" \")[1] : null;\n}\n\n/**\n * Gets the short branch name from a full branch reference.\n * @returns The short branch name if successful, null otherwise\n */\n// TODO: move to refs.ts\nexport function getShortBranchName(\n options: {\n /** The full branch reference (e.g., `refs/heads/branch-name`) */\n fullBranchRef: string;\n } & GitCommonOptions\n): string | null;\n/** @deprecated Use object params version */\nexport function getShortBranchName(fullBranchRef: string, cwd: string): string | null;\nexport function getShortBranchName(\n refOrOptions: string | ({ fullBranchRef: string } & GitCommonOptions),\n cwd?: string\n): string | null {\n const { fullBranchRef, ...options } =\n typeof refOrOptions === \"string\" ? { fullBranchRef: refOrOptions, cwd: cwd! } : refOrOptions;\n\n // The original command `git name-rev --name-only` returned unreliable results if multiple\n // named refs point to the same commit as the branch.\n const showRefResults = git([\"rev-parse\", \"--abbrev-ref\", fullBranchRef], options);\n\n return showRefResults.success ? showRefResults.stdout || null : null;\n}\n\n/**\n * Gets the current commit hash (SHA).\n * @returns The hash if successful, null otherwise\n */\n// TODO: move to refs.ts\nexport function getCurrentHash(options: GitCommonOptions): string | null;\n/** @deprecated Use object params version */\nexport function getCurrentHash(cwd: string): string | null;\nexport function getCurrentHash(cwdOrOptions: string | GitCommonOptions): string | null {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const results = git([\"rev-parse\", \"HEAD\"], {\n description: \"Getting current git hash\",\n ...options,\n });\n\n return results.success ? results.stdout : null;\n}\n\n/**\n * Get the commit hash in which the file was first added.\n * @returns The commit hash if found, undefined otherwise\n */\n// TODO: move to history.ts\nexport function getFileAddedHash(options: { filename: string } & GitCommonOptions): string | undefined;\n/** @deprecated Use object params version */\nexport function getFileAddedHash(filename: string, cwd: string): string | undefined;\nexport function getFileAddedHash(\n filenameOrOptions: string | ({ filename: string } & GitCommonOptions),\n cwd?: string\n): string | undefined {\n const { filename, ...options } =\n typeof filenameOrOptions === \"string\" ? { filename: filenameOrOptions, cwd: cwd! } : filenameOrOptions;\n\n const results = git([\"rev-list\", \"--max-count=1\", \"HEAD\", filename], options);\n\n return results.success ? results.stdout.trim() : undefined;\n}\n\n/**\n * Run `git init` and verify that the `user.name` and `user.email` configs are set (at any level).\n * Throws an error if `git init` fails.\n *\n * If `user.email` and `user.name` aren't already set globally, and the missing value is provided\n * in params, set it at the repo level. Otherwise, throw an error.\n */\n// TODO: move to init.ts\nexport function init(options: GitInitOptions): void;\n/** @deprecated Use object params version */\nexport function init(cwd: string, email?: string, username?: string): void;\nexport function init(cwdOrOptions: string | GitInitOptions, _email?: string, _username?: string): void {\n const { email, username, ...options } =\n typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions, email: _email, username: _username } : cwdOrOptions;\n\n git([\"init\"], { ...options, throwOnError: true });\n\n if (!getConfigValue({ key: \"user.name\", ...options })) {\n if (!username) {\n throw new Error(\"must include a username when initializing git repo\");\n }\n git([\"config\", \"user.name\", username], options);\n }\n\n if (!getUserEmail(options)) {\n if (!email) {\n throw new Error(\"must include a email when initializing git repo\");\n }\n git([\"config\", \"user.email\", email], options);\n }\n}\n\n/**\n * Stages files matching the given patterns.\n */\n// TODO: move to stageAndCommit.ts\nexport function stage(options: GitStageOptions): void;\n/** @deprecated Use object params version */\nexport function stage(patterns: string[], cwd: string): void;\nexport function stage(patternsOrOptions: string[] | GitStageOptions, cwd?: string): void {\n const { patterns, ...options } = Array.isArray(patternsOrOptions)\n ? { patterns: patternsOrOptions, cwd: cwd! }\n : patternsOrOptions;\n\n for (const pattern of patterns) {\n git([\"add\", pattern], { ...options, description: `Staging changes (git add ${pattern})` });\n }\n}\n\n/**\n * Commit changes. Throws an error on failure by default.\n */\n// TODO: move to stageAndCommit.ts\nexport function commit(options: GitCommitOptions): void;\n/** @deprecated Use object params version */\nexport function commit(message: string, cwd: string, options?: string[]): void;\nexport function commit(messageOrOptions: string | GitCommitOptions, _cwd?: string, _options?: string[]): void {\n const { message, options, ...gitOptions } =\n typeof messageOrOptions === \"string\"\n ? { message: messageOrOptions, cwd: _cwd!, options: _options }\n : messageOrOptions;\n\n git([\"commit\", \"-m\", message, ...(options || [])], {\n throwOnError: true,\n description: \"Committing changes\",\n ...gitOptions,\n });\n}\n\n/**\n * Stages files matching the given patterns and creates a commit with the specified message.\n * Convenience function that combines `stage()` and `commit()`.\n * Throws an error on commit failure by default.\n */\n// TODO: move to stageAndCommit.ts\nexport function stageAndCommit(options: GitStageOptions & GitCommitOptions): void;\n/** @deprecated Use object params version */\nexport function stageAndCommit(patterns: string[], message: string, cwd: string, commitOptions?: string[]): void;\nexport function stageAndCommit(\n patternsOrOptions: string[] | (GitStageOptions & GitCommitOptions),\n message?: string,\n cwd?: string,\n commitOptions?: string[]\n): void {\n const options: GitStageOptions & GitCommitOptions = Array.isArray(patternsOrOptions)\n ? { patterns: patternsOrOptions, message: message!, cwd: cwd!, options: commitOptions }\n : patternsOrOptions;\n\n stage(options);\n commit(options);\n}\n\n/**\n * Reverts all local changes (both staged and unstaged) by stashing them and then dropping the stash.\n * @returns True if the revert was successful, false otherwise. It will also be false if there were\n * no changes to revert. (To distinguish between this case and errors, use the `throwOnError` option.)\n */\n// TODO: move to revertLocalChanges.ts\nexport function revertLocalChanges(options: GitCommonOptions): boolean;\n/** @deprecated Use object params version */\nexport function revertLocalChanges(cwd: string): boolean;\nexport function revertLocalChanges(cwdOrOptions: string | GitCommonOptions): boolean {\n const options: GitCommonOptions = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n const stash = `workspace-tools_${new Date().getTime()}`;\n if (!git([\"stash\", \"push\", \"-u\", \"-m\", stash], options).success) {\n return false;\n }\n\n const results = git([\"stash\", \"list\"], options);\n if (results.success) {\n const matched = results.stdout\n .split(/\\n/)\n .find((line) => line.includes(stash))\n ?.match(/^[^:]+/);\n\n if (matched) {\n git([\"stash\", \"drop\", matched[0]], options);\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Attempts to determine the parent branch of the current branch using `git show-branch`.\n * @returns The parent branch name if found, null otherwise\n * @deprecated Does not appear to be used\n */\nexport function getParentBranch(cwd: string): string | null {\n const branchName = getBranchName({ cwd });\n\n if (!branchName || branchName === \"HEAD\") {\n return null;\n }\n\n const showBranchResult = git([\"show-branch\", \"-a\"], { cwd });\n\n if (showBranchResult.success) {\n const showBranchLines = showBranchResult.stdout.split(/\\n/);\n const parentLine = showBranchLines.find(\n (line) => line.includes(\"*\") && !line.includes(branchName) && !line.includes(\"publish_\")\n );\n\n const matched = parentLine?.match(/\\[(.*)\\]/);\n return matched ? matched[1] : null;\n }\n\n return null;\n}\n\n/**\n * Gets the remote tracking branch for the specified branch.\n *\n * @returns The remote branch name (e.g., `origin/main`) if found, null otherwise\n */\n// TODO: move to refs.ts\nexport function getRemoteBranch(options: GitBranchOptions): string | null;\n/** @deprecated Use object params version */\nexport function getRemoteBranch(branch: string, cwd: string): string | null;\nexport function getRemoteBranch(branchOrOptions: string | GitBranchOptions, cwd?: string): string | null {\n const options: GitBranchOptions =\n typeof branchOrOptions === \"string\" ? { branch: branchOrOptions, cwd: cwd! } : branchOrOptions;\n\n const results = git([\"rev-parse\", \"--abbrev-ref\", \"--symbolic-full-name\", `${options.branch}@{u}`], options);\n\n return results.success ? results.stdout.trim() : null;\n}\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 fetched to see if one of those matches.\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 */\n// TODO: move to parseRemoteBranch.ts\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 const { branch, knownRemotes = [\"origin\", \"upstream\"], ...options } = branchOrOptions;\n\n if (!branch.includes(\"/\")) {\n return { remote: \"\", remoteBranch: branch };\n }\n\n let remote = knownRemotes.find((r) => branch.startsWith(`${r}/`));\n\n if (!remote) {\n const remotes = git([\"remote\"], options).stdout.trim().split(/\\n/);\n remote = remotes.find((r) => branch.startsWith(`${r}/`));\n }\n\n if (remote) {\n return { remote, remoteBranch: branch.slice(remote.length + 1) };\n }\n return { remote: \"\", remoteBranch: branch };\n}\n\n/**\n * Gets the default branch based on `git config init.defaultBranch`, falling back to `master`.\n */\n// TODO: move to config.ts\nexport function getDefaultBranch(options: GitCommonOptions): string;\n/** @deprecated Use object params version */\nexport function getDefaultBranch(cwd: string): string;\nexport function getDefaultBranch(cwdOrOptions: string | GitCommonOptions): string {\n const options = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n\n // Default to the legacy 'master' for backwards compat and old git clients\n return getConfigValue({ key: \"init.defaultBranch\", ...options }) || \"master\";\n}\n\n/**\n * Lists all tracked files matching the given patterns.\n * Throws on error by default.\n * @returns An array of file paths, or an empty array if no files are found\n */\n// TODO: move to history.ts\nexport function listAllTrackedFiles(\n options: {\n /** File patterns to match (passed to git ls-files) */\n patterns: string[];\n } & GitCommonOptions\n): string[];\n/** @deprecated Use object params version */\nexport function listAllTrackedFiles(patterns: string[], cwd: string): string[];\nexport function listAllTrackedFiles(\n patternsOrOptions: string[] | ({ patterns: string[] } & GitCommonOptions),\n cwd?: string\n): string[] {\n const { patterns, ...options } = Array.isArray(patternsOrOptions)\n ? { patterns: patternsOrOptions, cwd: cwd! }\n : patternsOrOptions;\n\n const results = git([\"ls-files\", ...patterns], { throwOnError: true, ...options });\n\n return processGitOutput(results);\n}\n\n/**\n * Get the content of a file at a specific git ref (commit, branch, tag, etc).\n * Returns undefined if the file doesn't exist at that ref or the command fails.\n */\nexport function getFileFromVersion(\n params: {\n /** Repo-relative path to the file with *forward* slashes */\n filePath: string;\n /** git ref (branch, tag, commit SHA, etc) to get the file content from */\n ref: string;\n } & GitCommonOptions\n): string | undefined {\n const { filePath, ref, ...options } = params;\n const result = git([\"show\", `${ref}:${filePath}`], {\n description: `Getting file ${filePath} at ref ${ref}`,\n ...options,\n });\n return result.success ? result.stdout : undefined;\n}\n"],"names":["commit","fetchRemote","fetchRemoteBranch","getBranchChanges","getBranchName","getChanges","getChangesBetweenRefs","getCurrentHash","getDefaultBranch","getFileAddedHash","getFileFromVersion","getFullBranchRef","getParentBranch","getRecentCommitMessages","getRemoteBranch","getShortBranchName","getStagedChanges","getUnstagedChanges","getUntrackedChanges","getUserEmail","init","listAllTrackedFiles","parseRemoteBranch","revertLocalChanges","stage","stageAndCommit","diffArgs","cwdOrOptions","options","cwd","results","git","description","throwOnError","processGitOutput","excludeNodeModules","remoteOrOptions","remote","remoteBranch","gitOptions","Error","fetchArgs","branch","fromRef","branchOrOptions","toRef","pattern","range","getConfigValue","key","success","stdout","showRefResults","split","refOrOptions","fullBranchRef","filenameOrOptions","filename","trim","undefined","_email","_username","email","username","patternsOrOptions","patterns","Array","isArray","messageOrOptions","_cwd","_options","message","commitOptions","stash","Date","getTime","matched","find","line","includes","match","branchName","showBranchResult","showBranchLines","parentLine","firstSlashPos","indexOf","substring","knownRemotes","r","startsWith","remotes","slice","length","params","filePath","ref","result"],"mappings":"AAAA,EAAE;AACF,+BAA+B;AAC/B,wDAAwD;AACxD,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAmYcA;eAAAA;;QApVAC;eAAAA;;QAgCAC;eAAAA;;QA+CAC;eAAAA;;QA+GAC;eAAAA;;QA7HAC;eAAAA;;QAqCAC;eAAAA;;QAuJAC;eAAAA;;QA4PAC;eAAAA;;QAzOAC;eAAAA;;QA+QAC;eAAAA;;QA9UAC;eAAAA;;QA6MAC;eAAAA;;QAlQAC;eAAAA;;Q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O9C,MAAM,GAAGQ;AAC1C"}
|
|
1
|
+
{"version":3,"sources":["../../src/git/gitUtilities.ts"],"sourcesContent":["// File preserved for compatibility with existing imports.\n// New utilities don't need to be added here.\n\nexport { getBranchName, getFullBranchRef, getRemoteBranch, getShortBranchName } from \"./branchRefs.js\";\nexport { 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 { getFileAddedHash } from \"./getFileAddedHash.js\";\nexport { getRecentCommitMessages } from \"./getRecentCommitMessages.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\nimport { getBranchName } from \"./branchRefs.js\";\nimport { git } from \"./git.js\";\n\n/**\n * Attempts to determine the parent branch of the current branch using `git show-branch`.\n * @returns The parent branch name if found, null otherwise\n * @deprecated Does not appear to be used\n */\nexport function getParentBranch(cwd: string): string | null {\n const branchName = getBranchName({ cwd });\n\n if (!branchName || branchName === \"HEAD\") {\n return null;\n }\n\n const showBranchResult = git([\"show-branch\", \"-a\"], { cwd });\n\n if (showBranchResult.success) {\n const showBranchLines = showBranchResult.stdout.split(/\\n/);\n const parentLine = showBranchLines.find(\n (line) => line.includes(\"*\") && !line.includes(branchName) && !line.includes(\"publish_\")\n );\n\n const matched = parentLine?.match(/\\[(.*)\\]/);\n return matched ? matched[1] : null;\n }\n\n return null;\n}\n"],"names":["commit","fetchRemote","fetchRemoteBranch","getBranchChanges","getBranchName","getChanges","getChangesBetweenRefs","getCurrentHash","getDefaultBranch","getFileAddedHash","getFullBranchRef","getParentBranch","getRecentCommitMessages","getRemoteBranch","getShortBranchName","getStagedChanges","getUnstagedChanges","getUntrackedChanges","getUserEmail","init","listAllTrackedFiles","parseRemoteBranch","revertLocalChanges","stage","stageAndCommit","cwd","branchName","showBranchResult","git","success","showBranchLines","stdout","split","parentLine","find","line","includes","matched","match"],"mappings":"AAAA,0DAA0D;AAC1D,6CAA6C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAoBpCA;eAAAA,sBAAM;;QAhBNC;eAAAA,wBAAW;;QAAEC;eAAAA,8BAAiB;;QAErCC;eAAAA,4BAAgB;;QAJTC;eAAAA,yBAAa;;QAKpBC;eAAAA,sBAAU;;QACVC;eAAAA,iCAAqB;;QAKdC;eAAAA,8BAAc;;QAVdC;eAAAA,wBAAgB;;QAWhBC;eAAAA,kCAAgB;;QAZDC;eAAAA,4BAAgB;;QA4BxBC;eAAAA;;QAfPC;eAAAA,gDAAuB;;QAbUC;eAAAA,2BAAe;;QAAEC;eAAAA,8BAAkB;;QAO3EC;eAAAA,4BAAgB;;QAChBC;eAAAA,8BAAkB;;QAClBC;eAAAA,+BAAmB;;QARMC;eAAAA,oBAAY;;QAa9BC;eAAAA,UAAI;;QACJC;eAAAA,wCAAmB;;QACnBC;eAAAA,oCAAiB;;QACjBC;eAAAA,sCAAkB;;QACVC;eAAAA,qBAAK;;QAAEC;eAAAA,8BAAc;;;4BAlB+C;wBACtC;6BACA;4BAQxC;gCACwB;kCACE;yCACO;sBACnB;qCACe;mCACF;oCACC;gCACW;qBAG1B;AAOb,SAASb,gBAAgBc,GAAW;IACzC,MAAMC,aAAatB,IAAAA,yBAAa,EAAC;QAAEqB;IAAI;IAEvC,IAAI,CAACC,cAAcA,eAAe,QAAQ;QACxC,OAAO;IACT;IAEA,MAAMC,mBAAmBC,IAAAA,QAAG,EAAC;QAAC;QAAe;KAAK,EAAE;QAAEH;IAAI;IAE1D,IAAIE,iBAAiBE,OAAO,EAAE;QAC5B,MAAMC,kBAAkBH,iBAAiBI,MAAM,CAACC,KAAK,CAAC;QACtD,MAAMC,aAAaH,gBAAgBI,IAAI,CACrC,CAACC,OAASA,KAAKC,QAAQ,CAAC,QAAQ,CAACD,KAAKC,QAAQ,CAACV,eAAe,CAACS,KAAKC,QAAQ,CAAC;QAG/E,MAAMC,UAAUJ,YAAYK,MAAM;QAClC,OAAOD,UAAUA,OAAO,CAAC,EAAE,GAAG;IAChC;IAEA,OAAO;AACT"}
|
package/lib/git/index.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { getConfigValue } from "./config.js";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
1
|
+
export { getBranchName, getFullBranchRef, getRemoteBranch, getShortBranchName } from "./branchRefs.js";
|
|
2
|
+
export { getConfigValue, getDefaultBranch, getUserEmail } from "./config.js";
|
|
3
|
+
export { fetchRemote, fetchRemoteBranch } from "./fetchRemote.js";
|
|
4
|
+
export { getBranchChanges, getChanges, getChangesBetweenRefs, getStagedChanges, getUnstagedChanges, getUntrackedChanges, } from "./getChanges.js";
|
|
5
|
+
export { getCurrentHash } from "./getCurrentHash.js";
|
|
6
|
+
export { getDefaultRemote, type GetDefaultRemoteOptions } from "./getDefaultRemote.js";
|
|
7
|
+
export { getDefaultRemoteBranch, type GetDefaultRemoteBranchOptions, resolveRemoteBranch, } from "./getDefaultRemoteBranch.js";
|
|
8
|
+
export { getFileAddedHash } from "./getFileAddedHash.js";
|
|
9
|
+
export { getFileFromRef } from "./getFileFromRef.js";
|
|
10
|
+
export { getRecentCommitMessages } from "./getRecentCommitMessages.js";
|
|
11
|
+
export { addGitObserver, clearGitObservers, git, gitFailFast, type GitError, type GitObserver, type GitOptions, type GitProcessOutput, } from "./git.js";
|
|
12
|
+
export { getParentBranch } from "./gitUtilities.js";
|
|
13
|
+
export { init } from "./init.js";
|
|
14
|
+
export { listAllTrackedFiles } from "./listAllTrackedFiles.js";
|
|
15
|
+
export { parseRemoteBranch } from "./parseRemoteBranch.js";
|
|
16
|
+
export { revertLocalChanges } from "./revertLocalChanges.js";
|
|
17
|
+
export { commit, stage, stageAndCommit } from "./stageAndCommit.js";
|