workspace-tools 0.23.1 → 0.24.0
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/CHANGELOG.json +46 -1
- package/CHANGELOG.md +26 -2
- package/lib/git/getDefaultRemote.d.ts +28 -0
- package/lib/git/getDefaultRemote.js +79 -0
- package/lib/git/getDefaultRemoteBranch.d.ts +18 -0
- package/lib/git/getDefaultRemoteBranch.js +35 -0
- package/lib/git/getRepositoryName.d.ts +9 -0
- package/lib/git/getRepositoryName.js +55 -0
- package/lib/git/git.d.ts +29 -0
- package/lib/git/git.js +72 -0
- package/lib/{git.d.ts → git/gitUtilities.d.ts} +3 -27
- package/lib/git/gitUtilities.js +286 -0
- package/lib/git/index.d.ts +4 -0
- package/lib/git/index.js +17 -0
- package/lib/graph/index.d.ts +7 -2
- package/lib/graph/index.js +9 -1
- package/lib/helpers/setupFixture.d.ts +8 -2
- package/lib/helpers/setupFixture.js +32 -15
- package/lib/types/PackageInfo.d.ts +7 -4
- package/lib/workspaces/getChangedPackages.js +1 -1
- package/package.json +1 -1
- package/lib/git.js +0 -442
package/lib/git.js
DELETED
|
@@ -1,442 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.listAllTrackedFiles = exports.getDefaultRemote = exports.getDefaultBranch = exports.getDefaultRemoteBranch = 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 = exports.gitFailFast = exports.git = exports.addGitObserver = void 0;
|
|
7
|
-
const child_process_1 = require("child_process");
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const paths_1 = require("./paths");
|
|
11
|
-
const git_url_parse_1 = __importDefault(require("git-url-parse"));
|
|
12
|
-
function gitError(message, e) {
|
|
13
|
-
if (e && e instanceof Error) {
|
|
14
|
-
return new Error(`${message}: ${e.message}`);
|
|
15
|
-
}
|
|
16
|
-
return new Error(message);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* A global maxBuffer override for all git operations.
|
|
20
|
-
* Bumps up the default to 500MB instead of 1MB.
|
|
21
|
-
* Override this value with the `GIT_MAX_BUFFER` environment variable.
|
|
22
|
-
*/
|
|
23
|
-
const defaultMaxBuffer = process.env.GIT_MAX_BUFFER ? parseInt(process.env.GIT_MAX_BUFFER) : 500 * 1024 * 1024;
|
|
24
|
-
const observers = [];
|
|
25
|
-
let observing;
|
|
26
|
-
/**
|
|
27
|
-
* Adds an observer for the git operations, e.g. for testing
|
|
28
|
-
* @param observer
|
|
29
|
-
*/
|
|
30
|
-
function addGitObserver(observer) {
|
|
31
|
-
observers.push(observer);
|
|
32
|
-
}
|
|
33
|
-
exports.addGitObserver = addGitObserver;
|
|
34
|
-
/**
|
|
35
|
-
* Runs git command - use this for read-only commands
|
|
36
|
-
*/
|
|
37
|
-
function git(args, options) {
|
|
38
|
-
const results = (0, child_process_1.spawnSync)("git", args, Object.assign({ maxBuffer: defaultMaxBuffer }, options));
|
|
39
|
-
const output = {
|
|
40
|
-
stderr: results.stderr.toString().trimRight(),
|
|
41
|
-
stdout: results.stdout.toString().trimRight(),
|
|
42
|
-
success: results.status === 0
|
|
43
|
-
};
|
|
44
|
-
// notify observers, flipping the observing bit to prevent infinite loops
|
|
45
|
-
if (!observing) {
|
|
46
|
-
observing = true;
|
|
47
|
-
for (const observer of observers) {
|
|
48
|
-
observer(args, output);
|
|
49
|
-
}
|
|
50
|
-
observing = false;
|
|
51
|
-
}
|
|
52
|
-
return output;
|
|
53
|
-
}
|
|
54
|
-
exports.git = git;
|
|
55
|
-
/**
|
|
56
|
-
* Runs git command - use this for commands that make changes to the filesystem
|
|
57
|
-
*/
|
|
58
|
-
function gitFailFast(args, options) {
|
|
59
|
-
const gitResult = git(args, options);
|
|
60
|
-
if (!gitResult.success) {
|
|
61
|
-
process.exitCode = 1;
|
|
62
|
-
throw gitError(`CRITICAL ERROR: running git command: git ${args.join(" ")}!
|
|
63
|
-
${gitResult.stdout && gitResult.stdout.toString().trimRight()}
|
|
64
|
-
${gitResult.stderr && gitResult.stderr.toString().trimRight()}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.gitFailFast = gitFailFast;
|
|
68
|
-
function getUntrackedChanges(cwd) {
|
|
69
|
-
try {
|
|
70
|
-
const results = git(["status", "--short"], { cwd });
|
|
71
|
-
if (!results.success) {
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
const changes = results.stdout;
|
|
75
|
-
if (changes.length == 0) {
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
const lines = changes.split(/[\r\n]+/).filter((line) => line) || [];
|
|
79
|
-
const untracked = [];
|
|
80
|
-
for (let i = 0; i < lines.length; i++) {
|
|
81
|
-
const line = lines[i];
|
|
82
|
-
if (line[0] === " " || line[0] === "?") {
|
|
83
|
-
untracked.push(line.substr(3));
|
|
84
|
-
}
|
|
85
|
-
else if (line[0] === "R") {
|
|
86
|
-
i++;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return untracked;
|
|
90
|
-
}
|
|
91
|
-
catch (e) {
|
|
92
|
-
throw gitError(`Cannot gather information about untracked changes`, e);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.getUntrackedChanges = getUntrackedChanges;
|
|
96
|
-
function fetchRemote(remote, cwd) {
|
|
97
|
-
const results = git(["fetch", "--", remote], { cwd });
|
|
98
|
-
if (!results.success) {
|
|
99
|
-
throw gitError(`Cannot fetch remote: ${remote}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.fetchRemote = fetchRemote;
|
|
103
|
-
function fetchRemoteBranch(remote, remoteBranch, cwd) {
|
|
104
|
-
const results = git(["fetch", "--", remote, remoteBranch], { cwd });
|
|
105
|
-
if (!results.success) {
|
|
106
|
-
throw gitError(`Cannot fetch remote: ${remote} ${remoteBranch}`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
exports.fetchRemoteBranch = fetchRemoteBranch;
|
|
110
|
-
/**
|
|
111
|
-
* Gets all the changes that have not been staged yet
|
|
112
|
-
* @param cwd
|
|
113
|
-
*/
|
|
114
|
-
function getUnstagedChanges(cwd) {
|
|
115
|
-
try {
|
|
116
|
-
return processGitOutput(git(["--no-pager", "diff", "--name-only", "--relative"], { cwd }));
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
throw gitError(`Cannot gather information about unstaged changes`, e);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
exports.getUnstagedChanges = getUnstagedChanges;
|
|
123
|
-
function getChanges(branch, cwd) {
|
|
124
|
-
try {
|
|
125
|
-
return processGitOutput(git(["--no-pager", "diff", "--relative", "--name-only", branch + "..."], { cwd }));
|
|
126
|
-
}
|
|
127
|
-
catch (e) {
|
|
128
|
-
throw gitError(`Cannot gather information about changes`, e);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
exports.getChanges = getChanges;
|
|
132
|
-
/**
|
|
133
|
-
* Gets all the changes between the branch and the merge-base
|
|
134
|
-
* @param branch
|
|
135
|
-
* @param cwd
|
|
136
|
-
*/
|
|
137
|
-
function getBranchChanges(branch, cwd) {
|
|
138
|
-
return getChangesBetweenRefs(branch, "", [], "", cwd);
|
|
139
|
-
}
|
|
140
|
-
exports.getBranchChanges = getBranchChanges;
|
|
141
|
-
function getChangesBetweenRefs(fromRef, toRef, options, pattern, cwd) {
|
|
142
|
-
try {
|
|
143
|
-
return processGitOutput(git(["--no-pager", "diff", "--name-only", "--relative", ...options, `${fromRef}...${toRef}`, ...(pattern ? ["--", pattern] : [])], {
|
|
144
|
-
cwd,
|
|
145
|
-
}));
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
throw gitError(`Cannot gather information about change between refs changes (${fromRef} to ${toRef})`, e);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
exports.getChangesBetweenRefs = getChangesBetweenRefs;
|
|
152
|
-
function getStagedChanges(cwd) {
|
|
153
|
-
try {
|
|
154
|
-
return processGitOutput(git(["--no-pager", "diff", "--relative", "--staged", "--name-only"], { cwd }));
|
|
155
|
-
}
|
|
156
|
-
catch (e) {
|
|
157
|
-
throw gitError(`Cannot gather information about staged changes`, e);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
exports.getStagedChanges = getStagedChanges;
|
|
161
|
-
function getRecentCommitMessages(branch, cwd) {
|
|
162
|
-
try {
|
|
163
|
-
const results = git(["log", "--decorate", "--pretty=format:%s", `${branch}..HEAD`], { cwd });
|
|
164
|
-
if (!results.success) {
|
|
165
|
-
return [];
|
|
166
|
-
}
|
|
167
|
-
let changes = results.stdout;
|
|
168
|
-
let lines = changes.split(/\n/) || [];
|
|
169
|
-
return lines.map((line) => line.trim());
|
|
170
|
-
}
|
|
171
|
-
catch (e) {
|
|
172
|
-
throw gitError(`Cannot gather information about recent commits`, e);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
exports.getRecentCommitMessages = getRecentCommitMessages;
|
|
176
|
-
function getUserEmail(cwd) {
|
|
177
|
-
try {
|
|
178
|
-
const results = git(["config", "user.email"], { cwd });
|
|
179
|
-
if (!results.success) {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
return results.stdout;
|
|
183
|
-
}
|
|
184
|
-
catch (e) {
|
|
185
|
-
throw gitError(`Cannot gather information about user.email`, e);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
exports.getUserEmail = getUserEmail;
|
|
189
|
-
function getBranchName(cwd) {
|
|
190
|
-
try {
|
|
191
|
-
const results = git(["rev-parse", "--abbrev-ref", "HEAD"], { cwd });
|
|
192
|
-
if (results.success) {
|
|
193
|
-
return results.stdout;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
catch (e) {
|
|
197
|
-
throw gitError(`Cannot get branch name`, e);
|
|
198
|
-
}
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
exports.getBranchName = getBranchName;
|
|
202
|
-
function getFullBranchRef(branch, cwd) {
|
|
203
|
-
const showRefResults = git(["show-ref", "--heads", branch], { cwd });
|
|
204
|
-
if (showRefResults.success) {
|
|
205
|
-
return showRefResults.stdout.split(" ")[1];
|
|
206
|
-
}
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
exports.getFullBranchRef = getFullBranchRef;
|
|
210
|
-
function getShortBranchName(fullBranchRef, cwd) {
|
|
211
|
-
const showRefResults = git(["name-rev", "--name-only", fullBranchRef], {
|
|
212
|
-
cwd,
|
|
213
|
-
});
|
|
214
|
-
if (showRefResults.success) {
|
|
215
|
-
return showRefResults.stdout;
|
|
216
|
-
}
|
|
217
|
-
return null;
|
|
218
|
-
}
|
|
219
|
-
exports.getShortBranchName = getShortBranchName;
|
|
220
|
-
function getCurrentHash(cwd) {
|
|
221
|
-
try {
|
|
222
|
-
const results = git(["rev-parse", "HEAD"], { cwd });
|
|
223
|
-
if (results.success) {
|
|
224
|
-
return results.stdout;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
catch (e) {
|
|
228
|
-
throw gitError(`Cannot get current git hash`, e);
|
|
229
|
-
}
|
|
230
|
-
return null;
|
|
231
|
-
}
|
|
232
|
-
exports.getCurrentHash = getCurrentHash;
|
|
233
|
-
/**
|
|
234
|
-
* Get the commit hash in which the file was first added.
|
|
235
|
-
*/
|
|
236
|
-
function getFileAddedHash(filename, cwd) {
|
|
237
|
-
const results = git(["rev-list", "HEAD", filename], { cwd });
|
|
238
|
-
if (results.success) {
|
|
239
|
-
return results.stdout.trim().split("\n").slice(-1)[0];
|
|
240
|
-
}
|
|
241
|
-
return undefined;
|
|
242
|
-
}
|
|
243
|
-
exports.getFileAddedHash = getFileAddedHash;
|
|
244
|
-
function init(cwd, email, username) {
|
|
245
|
-
git(["init"], { cwd });
|
|
246
|
-
const configLines = git(["config", "--list"], { cwd }).stdout.split("\n");
|
|
247
|
-
if (!configLines.find((line) => line.includes("user.name"))) {
|
|
248
|
-
if (!username) {
|
|
249
|
-
throw gitError("must include a username when initializing git repo");
|
|
250
|
-
}
|
|
251
|
-
git(["config", "user.name", username], { cwd });
|
|
252
|
-
}
|
|
253
|
-
if (!configLines.find((line) => line.includes("user.email"))) {
|
|
254
|
-
if (!email) {
|
|
255
|
-
throw new Error("must include a email when initializing git repo");
|
|
256
|
-
}
|
|
257
|
-
git(["config", "user.email", email], { cwd });
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
exports.init = init;
|
|
261
|
-
function stage(patterns, cwd) {
|
|
262
|
-
try {
|
|
263
|
-
patterns.forEach((pattern) => {
|
|
264
|
-
git(["add", pattern], { cwd });
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
catch (e) {
|
|
268
|
-
throw gitError(`Cannot stage changes`, e);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
exports.stage = stage;
|
|
272
|
-
function commit(message, cwd, options = []) {
|
|
273
|
-
try {
|
|
274
|
-
const commitResults = git(["commit", "-m", message, ...options], { cwd });
|
|
275
|
-
if (!commitResults.success) {
|
|
276
|
-
throw new Error(`Cannot commit changes: ${commitResults.stdout} ${commitResults.stderr}`);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
catch (e) {
|
|
280
|
-
throw gitError(`Cannot commit changes`, e);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
exports.commit = commit;
|
|
284
|
-
function stageAndCommit(patterns, message, cwd, commitOptions = []) {
|
|
285
|
-
stage(patterns, cwd);
|
|
286
|
-
commit(message, cwd, commitOptions);
|
|
287
|
-
}
|
|
288
|
-
exports.stageAndCommit = stageAndCommit;
|
|
289
|
-
function revertLocalChanges(cwd) {
|
|
290
|
-
const stash = `beachball_${new Date().getTime()}`;
|
|
291
|
-
git(["stash", "push", "-u", "-m", stash], { cwd });
|
|
292
|
-
const results = git(["stash", "list"]);
|
|
293
|
-
if (results.success) {
|
|
294
|
-
const lines = results.stdout.split(/\n/);
|
|
295
|
-
const foundLine = lines.find((line) => line.includes(stash));
|
|
296
|
-
if (foundLine) {
|
|
297
|
-
const matched = foundLine.match(/^[^:]+/);
|
|
298
|
-
if (matched) {
|
|
299
|
-
git(["stash", "drop", matched[0]]);
|
|
300
|
-
return true;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
exports.revertLocalChanges = revertLocalChanges;
|
|
307
|
-
function getParentBranch(cwd) {
|
|
308
|
-
const branchName = getBranchName(cwd);
|
|
309
|
-
if (!branchName || branchName === "HEAD") {
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
const showBranchResult = git(["show-branch", "-a"], { cwd });
|
|
313
|
-
if (showBranchResult.success) {
|
|
314
|
-
const showBranchLines = showBranchResult.stdout.split(/\n/);
|
|
315
|
-
const parentLine = showBranchLines.find((line) => line.indexOf("*") > -1 && line.indexOf(branchName) < 0 && line.indexOf("publish_") < 0);
|
|
316
|
-
if (!parentLine) {
|
|
317
|
-
return null;
|
|
318
|
-
}
|
|
319
|
-
const matched = parentLine.match(/\[(.*)\]/);
|
|
320
|
-
if (!matched) {
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
return matched[1];
|
|
324
|
-
}
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
exports.getParentBranch = getParentBranch;
|
|
328
|
-
function getRemoteBranch(branch, cwd) {
|
|
329
|
-
const results = git(["rev-parse", "--abbrev-ref", "--symbolic-full-name", `${branch}@\{u\}`], { cwd });
|
|
330
|
-
if (results.success) {
|
|
331
|
-
return results.stdout.trim();
|
|
332
|
-
}
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
exports.getRemoteBranch = getRemoteBranch;
|
|
336
|
-
function parseRemoteBranch(branch) {
|
|
337
|
-
const firstSlashPos = branch.indexOf("/", 0);
|
|
338
|
-
const remote = branch.substring(0, firstSlashPos);
|
|
339
|
-
const remoteBranch = branch.substring(firstSlashPos + 1);
|
|
340
|
-
return {
|
|
341
|
-
remote,
|
|
342
|
-
remoteBranch,
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
exports.parseRemoteBranch = parseRemoteBranch;
|
|
346
|
-
function normalizeRepoUrl(repositoryUrl) {
|
|
347
|
-
try {
|
|
348
|
-
const parsed = (0, git_url_parse_1.default)(repositoryUrl);
|
|
349
|
-
return parsed
|
|
350
|
-
.toString("https")
|
|
351
|
-
.replace(/\.git$/, "")
|
|
352
|
-
.toLowerCase();
|
|
353
|
-
}
|
|
354
|
-
catch (e) {
|
|
355
|
-
return "";
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
function getDefaultRemoteBranch(branch, cwd) {
|
|
359
|
-
const defaultRemote = getDefaultRemote(cwd);
|
|
360
|
-
const showRemote = git(["remote", "show", defaultRemote], { cwd });
|
|
361
|
-
/**
|
|
362
|
-
* The `showRemote` returns something like this in stdout:
|
|
363
|
-
*
|
|
364
|
-
* * remote origin
|
|
365
|
-
* Fetch URL: ../monorepo-upstream/
|
|
366
|
-
* Push URL: ../monorepo-upstream/
|
|
367
|
-
* HEAD branch: main
|
|
368
|
-
*
|
|
369
|
-
*/
|
|
370
|
-
const headBranchLine = showRemote.stdout.split(/\n/).find((line) => line.includes("HEAD branch"));
|
|
371
|
-
let remoteDefaultBranch;
|
|
372
|
-
if (headBranchLine) {
|
|
373
|
-
remoteDefaultBranch = headBranchLine.replace(/^\s*HEAD branch:\s+/, "");
|
|
374
|
-
}
|
|
375
|
-
branch = branch || remoteDefaultBranch || getDefaultBranch(cwd);
|
|
376
|
-
return `${defaultRemote}/${branch}`;
|
|
377
|
-
}
|
|
378
|
-
exports.getDefaultRemoteBranch = getDefaultRemoteBranch;
|
|
379
|
-
function getDefaultBranch(cwd) {
|
|
380
|
-
const result = git(["config", "init.defaultBranch"], { cwd });
|
|
381
|
-
if (!result.success) {
|
|
382
|
-
// Default to the legacy 'master' for backwards compat and old git clients
|
|
383
|
-
return "master";
|
|
384
|
-
}
|
|
385
|
-
return result.stdout.trim();
|
|
386
|
-
}
|
|
387
|
-
exports.getDefaultBranch = getDefaultBranch;
|
|
388
|
-
function getDefaultRemote(cwd) {
|
|
389
|
-
let packageJson;
|
|
390
|
-
try {
|
|
391
|
-
packageJson = JSON.parse(fs_1.default.readFileSync(path_1.default.join((0, paths_1.findGitRoot)(cwd), "package.json")).toString());
|
|
392
|
-
}
|
|
393
|
-
catch (e) {
|
|
394
|
-
throw new Error("invalid package.json detected");
|
|
395
|
-
}
|
|
396
|
-
const { repository } = packageJson;
|
|
397
|
-
let repositoryUrl = "";
|
|
398
|
-
if (typeof repository === "string") {
|
|
399
|
-
repositoryUrl = repository;
|
|
400
|
-
}
|
|
401
|
-
else if (repository && repository.url) {
|
|
402
|
-
repositoryUrl = repository.url;
|
|
403
|
-
}
|
|
404
|
-
const normalizedUrl = normalizeRepoUrl(repositoryUrl);
|
|
405
|
-
const remotesResult = git(["remote", "-v"], { cwd });
|
|
406
|
-
if (remotesResult.success) {
|
|
407
|
-
const allRemotes = {};
|
|
408
|
-
remotesResult.stdout.split("\n").forEach((line) => {
|
|
409
|
-
const parts = line.split(/\s+/);
|
|
410
|
-
allRemotes[normalizeRepoUrl(parts[1])] = parts[0];
|
|
411
|
-
});
|
|
412
|
-
if (Object.keys(allRemotes).length > 0) {
|
|
413
|
-
const remote = allRemotes[normalizedUrl];
|
|
414
|
-
if (remote) {
|
|
415
|
-
return remote;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
return "origin";
|
|
420
|
-
}
|
|
421
|
-
exports.getDefaultRemote = getDefaultRemote;
|
|
422
|
-
function listAllTrackedFiles(patterns, cwd) {
|
|
423
|
-
if (patterns) {
|
|
424
|
-
const results = git(["ls-files", ...patterns], { cwd });
|
|
425
|
-
if (results.success) {
|
|
426
|
-
return results.stdout.split(/\n/);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
return [];
|
|
430
|
-
}
|
|
431
|
-
exports.listAllTrackedFiles = listAllTrackedFiles;
|
|
432
|
-
function processGitOutput(output) {
|
|
433
|
-
if (!output.success) {
|
|
434
|
-
return [];
|
|
435
|
-
}
|
|
436
|
-
let stdout = output.stdout;
|
|
437
|
-
let lines = stdout.split(/\n/) || [];
|
|
438
|
-
return lines
|
|
439
|
-
.filter((line) => line.trim() !== "")
|
|
440
|
-
.map((line) => line.trim())
|
|
441
|
-
.filter((line) => !line.includes("node_modules"));
|
|
442
|
-
}
|