@rushstack/package-deps-hash 3.2.62 → 3.2.64
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/getRepoState.d.ts +6 -15
- package/lib/getRepoState.d.ts.map +1 -1
- package/lib/getRepoState.js +33 -104
- package/lib/getRepoState.js.map +1 -1
- package/package.json +2 -2
package/lib/getRepoState.d.ts
CHANGED
|
@@ -3,11 +3,15 @@ export interface IGitVersion {
|
|
|
3
3
|
minor: number;
|
|
4
4
|
patch: number;
|
|
5
5
|
}
|
|
6
|
+
interface IGitTreeState {
|
|
7
|
+
files: Map<string, string>;
|
|
8
|
+
submodules: Map<string, string>;
|
|
9
|
+
}
|
|
6
10
|
/**
|
|
7
11
|
* Parses the output of the "git ls-tree -r -z" command
|
|
8
12
|
* @internal
|
|
9
13
|
*/
|
|
10
|
-
export declare function parseGitLsTree(output: string):
|
|
14
|
+
export declare function parseGitLsTree(output: string): IGitTreeState;
|
|
11
15
|
/**
|
|
12
16
|
* Information about the changes to a file.
|
|
13
17
|
* @beta
|
|
@@ -50,20 +54,6 @@ export declare function getRepoRoot(currentWorkingDirectory: string, gitPath?: s
|
|
|
50
54
|
* @internal
|
|
51
55
|
*/
|
|
52
56
|
export declare function applyWorkingTreeState(rootDirectory: string, state: Map<string, string>, gitPath?: string): void;
|
|
53
|
-
/**
|
|
54
|
-
* Parse the list of all git submodule paths from the output of "git submodule status"
|
|
55
|
-
*
|
|
56
|
-
* @param output - The raw output from Git
|
|
57
|
-
* @internal
|
|
58
|
-
*/
|
|
59
|
-
export declare function _parseGitSubmoduleStatus(output: string): string[];
|
|
60
|
-
/**
|
|
61
|
-
* Parse the state of all git submodule from the output of "git submodule foreach git --no-optional-locks ls-tree -r --full-name HEAD --"
|
|
62
|
-
*
|
|
63
|
-
* @param output - The raw output from Git
|
|
64
|
-
* @internal
|
|
65
|
-
*/
|
|
66
|
-
export declare function _parseGitSubmoduleForEachGitLsTree(output: string): Record<string, Record<string, string>>;
|
|
67
57
|
/**
|
|
68
58
|
* Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.
|
|
69
59
|
* @param currentWorkingDirectory - The working directory. Only used to find the repository root.
|
|
@@ -88,4 +78,5 @@ export declare function getRepoChanges(currentWorkingDirectory: string, revision
|
|
|
88
78
|
*/
|
|
89
79
|
export declare function ensureGitMinimumVersion(gitPath?: string): void;
|
|
90
80
|
export declare function parseGitVersion(gitVersionOutput: string): IGitVersion;
|
|
81
|
+
export {};
|
|
91
82
|
//# sourceMappingURL=getRepoState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepoState.d.ts","sourceRoot":"","sources":["../src/getRepoState.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAQD
|
|
1
|
+
{"version":3,"file":"getRepoState.d.ts","sourceRoot":"","sources":["../src/getRepoState.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAQD,UAAU,aAAa;IACrB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CA6C5D;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAoC9E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CA2BnE;AAID;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,uBAAuB,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAqBrF;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1B,OAAO,CAAC,EAAE,MAAM,GACf,IAAI,CA6DN;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,uBAAuB,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAoCnG;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,uBAAuB,EAAE,MAAM,EAC/B,QAAQ,GAAE,MAAe,EACzB,OAAO,CAAC,EAAE,MAAM,GACf,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CA8B9B;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAe9D;AAeD,wBAAgB,eAAe,CAAC,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAyBrE"}
|
package/lib/getRepoState.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
3
|
// See LICENSE in the project root for license information.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.parseGitVersion = exports.ensureGitMinimumVersion = exports.getRepoChanges = exports.getRepoState = exports.
|
|
5
|
+
exports.parseGitVersion = exports.ensureGitMinimumVersion = exports.getRepoChanges = exports.getRepoState = exports.applyWorkingTreeState = exports.getRepoRoot = exports.parseGitStatus = exports.parseGitDiffIndex = exports.parseGitLsTree = void 0;
|
|
6
6
|
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
7
7
|
const MINIMUM_GIT_VERSION = {
|
|
8
8
|
major: 2,
|
|
@@ -14,7 +14,8 @@ const MINIMUM_GIT_VERSION = {
|
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
16
|
function parseGitLsTree(output) {
|
|
17
|
-
const
|
|
17
|
+
const files = new Map();
|
|
18
|
+
const submodules = new Map();
|
|
18
19
|
// Parse the output
|
|
19
20
|
// With the -z modifier, paths are delimited by nulls
|
|
20
21
|
// A line looks like:
|
|
@@ -28,11 +29,26 @@ function parseGitLsTree(output) {
|
|
|
28
29
|
const filePath = item.slice(tabIndex + 1);
|
|
29
30
|
// The newHash will be all zeros if the file is deleted, or a hash if it exists
|
|
30
31
|
const hash = item.slice(tabIndex - 40, tabIndex);
|
|
31
|
-
|
|
32
|
+
const spaceIndex = item.lastIndexOf(' ', tabIndex - 42);
|
|
33
|
+
const type = item.slice(spaceIndex + 1, tabIndex - 41);
|
|
34
|
+
switch (type) {
|
|
35
|
+
case 'commit': {
|
|
36
|
+
submodules.set(filePath, hash);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case 'blob':
|
|
40
|
+
default: {
|
|
41
|
+
files.set(filePath, hash);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
32
45
|
last = index + 1;
|
|
33
46
|
index = output.indexOf('\0', last);
|
|
34
47
|
}
|
|
35
|
-
return
|
|
48
|
+
return {
|
|
49
|
+
files,
|
|
50
|
+
submodules
|
|
51
|
+
};
|
|
36
52
|
}
|
|
37
53
|
exports.parseGitLsTree = parseGitLsTree;
|
|
38
54
|
/**
|
|
@@ -175,103 +191,6 @@ function applyWorkingTreeState(rootDirectory, state, gitPath) {
|
|
|
175
191
|
}
|
|
176
192
|
}
|
|
177
193
|
exports.applyWorkingTreeState = applyWorkingTreeState;
|
|
178
|
-
/**
|
|
179
|
-
* Parse the list of all git submodule paths from the output of "git submodule status"
|
|
180
|
-
*
|
|
181
|
-
* @param output - The raw output from Git
|
|
182
|
-
* @internal
|
|
183
|
-
*/
|
|
184
|
-
function _parseGitSubmoduleStatus(output) {
|
|
185
|
-
const submodulePaths = [];
|
|
186
|
-
// <hash> <path> (heads/main)\n
|
|
187
|
-
output.split('\n').forEach((line) => {
|
|
188
|
-
if (line) {
|
|
189
|
-
const [, submodulePath] = line.trim().split(' ');
|
|
190
|
-
submodulePaths.push(submodulePath);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
return submodulePaths;
|
|
194
|
-
}
|
|
195
|
-
exports._parseGitSubmoduleStatus = _parseGitSubmoduleStatus;
|
|
196
|
-
/**
|
|
197
|
-
* Get the list of all git submodule paths
|
|
198
|
-
* @param rootDirectory - The root directory of the Git repository
|
|
199
|
-
* @param gitPath - The path to the Git executable
|
|
200
|
-
* @internal
|
|
201
|
-
*/
|
|
202
|
-
function getSubmodulePaths(rootDirectory, gitPath) {
|
|
203
|
-
const submoduleStatusResult = node_core_library_1.Executable.spawnSync(gitPath || 'git', ['submodule', 'status'], {
|
|
204
|
-
currentWorkingDirectory: rootDirectory
|
|
205
|
-
});
|
|
206
|
-
if (submoduleStatusResult.status !== 0) {
|
|
207
|
-
ensureGitMinimumVersion(gitPath);
|
|
208
|
-
throw new Error(`git submodule status exited with status ${submoduleStatusResult.status}: ${submoduleStatusResult.stderr}`);
|
|
209
|
-
}
|
|
210
|
-
// <hash> <path> (heads/main)\n
|
|
211
|
-
return _parseGitSubmoduleStatus(submoduleStatusResult.stdout);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Parse the state of all git submodule from the output of "git submodule foreach git --no-optional-locks ls-tree -r --full-name HEAD --"
|
|
215
|
-
*
|
|
216
|
-
* @param output - The raw output from Git
|
|
217
|
-
* @internal
|
|
218
|
-
*/
|
|
219
|
-
function _parseGitSubmoduleForEachGitLsTree(output) {
|
|
220
|
-
const stateBySubmodulePath = {};
|
|
221
|
-
let currentSubmodulePath = '';
|
|
222
|
-
// Note: Entering maybe translated to other languages by Git
|
|
223
|
-
// Entering '<submoduleFolder>'\n
|
|
224
|
-
// <mode> <type> <newhash>\t<path>\n
|
|
225
|
-
output.split('\n').forEach((line) => {
|
|
226
|
-
var _a;
|
|
227
|
-
if (line) {
|
|
228
|
-
line = line.trim();
|
|
229
|
-
const submodulePath = (_a = line.match(/\s'(.*)'$/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
230
|
-
if (submodulePath) {
|
|
231
|
-
currentSubmodulePath = submodulePath;
|
|
232
|
-
stateBySubmodulePath[currentSubmodulePath] = {};
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
const tabIndex = line.indexOf('\t');
|
|
236
|
-
const filePath = line.slice(tabIndex + 1);
|
|
237
|
-
// The newHash will be all zeros if the file is deleted, or a hash if it exists
|
|
238
|
-
const hash = line.slice(tabIndex - 40, tabIndex);
|
|
239
|
-
if (stateBySubmodulePath[currentSubmodulePath] === undefined) {
|
|
240
|
-
stateBySubmodulePath[currentSubmodulePath] = {};
|
|
241
|
-
}
|
|
242
|
-
stateBySubmodulePath[currentSubmodulePath][filePath] = hash;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
return stateBySubmodulePath;
|
|
247
|
-
}
|
|
248
|
-
exports._parseGitSubmoduleForEachGitLsTree = _parseGitSubmoduleForEachGitLsTree;
|
|
249
|
-
/**
|
|
250
|
-
* Augments the state value with modifications that are in git submodules
|
|
251
|
-
* @param rootDirectory - The root directory of the Git repository
|
|
252
|
-
* @param state - The current map of git path -> object hash. Will be mutated.
|
|
253
|
-
* @param gitPath - The path to the Git executable
|
|
254
|
-
* @internal
|
|
255
|
-
*/
|
|
256
|
-
function applySubmodulesTreeState(rootDirectory, state, gitPath) {
|
|
257
|
-
const submodulePaths = getSubmodulePaths(rootDirectory, gitPath);
|
|
258
|
-
if (submodulePaths.length === 0) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
const submoduleLsTreeResult = node_core_library_1.Executable.spawnSync(gitPath || 'git', ['submodule', 'foreach', 'git', '--no-optional-locks', 'ls-tree', '-r', '--full-name', 'HEAD', '--'], {
|
|
262
|
-
currentWorkingDirectory: rootDirectory
|
|
263
|
-
});
|
|
264
|
-
if (submoduleLsTreeResult.status !== 0) {
|
|
265
|
-
ensureGitMinimumVersion(gitPath);
|
|
266
|
-
throw new Error(`git ls-tree for submodules exited with status ${submoduleLsTreeResult.status}: ${submoduleLsTreeResult.stderr}`);
|
|
267
|
-
}
|
|
268
|
-
const stateBySubmodulePath = _parseGitSubmoduleForEachGitLsTree(submoduleLsTreeResult.stdout);
|
|
269
|
-
for (const submodulePath of submodulePaths) {
|
|
270
|
-
for (const [filePath, hash] of Object.entries(stateBySubmodulePath[submodulePath])) {
|
|
271
|
-
state.set(`${submodulePath}/${filePath}`, hash);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
194
|
/**
|
|
276
195
|
* Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.
|
|
277
196
|
* @param currentWorkingDirectory - The working directory. Only used to find the repository root.
|
|
@@ -287,9 +206,19 @@ function getRepoState(currentWorkingDirectory, gitPath) {
|
|
|
287
206
|
ensureGitMinimumVersion(gitPath);
|
|
288
207
|
throw new Error(`git ls-tree exited with status ${lsTreeResult.status}: ${lsTreeResult.stderr}`);
|
|
289
208
|
}
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
209
|
+
const { files, submodules } = parseGitLsTree(lsTreeResult.stdout);
|
|
210
|
+
applyWorkingTreeState(rootDirectory, files, gitPath);
|
|
211
|
+
const state = files;
|
|
212
|
+
// Existence check for the .gitmodules file
|
|
213
|
+
const hasSubmodules = submodules.size > 0 && node_core_library_1.FileSystem.exists(`${rootDirectory}/.gitmodules`);
|
|
214
|
+
if (hasSubmodules) {
|
|
215
|
+
for (const submodulePath of submodules.keys()) {
|
|
216
|
+
const submoduleState = getRepoState(`${rootDirectory}/${submodulePath}`, gitPath);
|
|
217
|
+
for (const [filePath, hash] of submoduleState) {
|
|
218
|
+
state.set(`${submodulePath}/${filePath}`, hash);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
293
222
|
return state;
|
|
294
223
|
}
|
|
295
224
|
exports.getRepoState = getRepoState;
|
package/lib/getRepoState.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepoState.js","sourceRoot":"","sources":["../src/getRepoState.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,oEAA0D;AAQ1D,MAAM,mBAAmB,GAAgB;IACvC,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,CAAC;CACT,CAAC;AAEF;;;GAGG;AACH,SAAgB,cAAc,CAAC,MAAc;IAC3C,MAAM,MAAM,GAAwB,IAAI,GAAG,EAAE,CAAC;IAE9C,mBAAmB;IACnB,qDAAqD;IACrD,qBAAqB;IACrB,oCAAoC;IACpC,6FAA6F;IAE7F,IAAI,IAAI,GAAW,CAAC,CAAC;IACrB,IAAI,KAAK,GAAW,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/C,OAAO,KAAK,IAAI,CAAC,EAAE;QACjB,MAAM,IAAI,GAAW,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAE/C,MAAM,QAAQ,GAAW,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAW,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QAElD,+EAA+E;QAC/E,MAAM,IAAI,GAAW,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,EAAE,QAAQ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,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE7C,OAAO;QACL,KAAK;QACL,KAAK;QACL,KAAK;KACN,CAAC;AACJ,CAAC;AAzBD,0CAyBC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type * as child_process from 'child_process';\nimport { Executable } from '@rushstack/node-core-library';\n\nexport interface IGitVersion {\n major: number;\n minor: number;\n patch: number;\n}\n\nconst MINIMUM_GIT_VERSION: IGitVersion = {\n major: 2,\n minor: 20,\n patch: 0\n};\n\n/**\n * Parses the output of the \"git ls-tree -r -z\" command\n * @internal\n */\nexport function parseGitLsTree(output: string): Map<string, string> {\n const result: Map<string, string> = new Map();\n\n // Parse the output\n // With the -z modifier, paths are delimited by nulls\n // A line looks like:\n // <mode> <type> <newhash>\\t<path>\\0\n // 100644 blob a300ccb0b36bd2c85ef18e3c619a2c747f95959e\\ttools/prettier-git/prettier-git.js\\0\n\n let last: number = 0;\n let index: number = output.indexOf('\\0', last);\n while (index >= 0) {\n const item: string = output.slice(last, index);\n\n const tabIndex: number = item.indexOf('\\t');\n const filePath: string = item.slice(tabIndex + 1);\n\n // The newHash will be all zeros if the file is deleted, or a hash if it exists\n const hash: string = item.slice(tabIndex - 40, tabIndex);\n result.set(filePath, hash);\n\n last = index + 1;\n index = output.indexOf('\\0', last);\n }\n\n return result;\n}\n\n/**\n * Information about the changes to a file.\n * @beta\n */\nexport interface IFileDiffStatus {\n mode: string;\n oldhash: string;\n newhash: string;\n status: 'A' | 'D' | 'M';\n}\n\n/**\n * Parses the output of `git diff-index --color=never --no-renames --no-commit-id -z <REVISION> --\n * Returns a map of file path to diff\n * @internal\n */\nexport function parseGitDiffIndex(output: string): Map<string, IFileDiffStatus> {\n const result: Map<string, IFileDiffStatus> = new Map();\n\n // Parse the output\n // With the -z modifier, paths are delimited by nulls\n // A line looks like:\n // :<oldmode> <newmode> <oldhash> <newhash> <status>\\0<path>\\0\n // :100644 100644 a300ccb0b36bd2c85ef18e3c619a2c747f95959e 0000000000000000000000000000000000000000 M\\0tools/prettier-git/prettier-git.js\\0\n\n let last: number = 0;\n let index: number = output.indexOf('\\0', last);\n while (index >= 0) {\n const header: string = output.slice(last, index);\n const status: IFileDiffStatus['status'] = header.slice(-1) as IFileDiffStatus['status'];\n\n last = index + 1;\n index = output.indexOf('\\0', last);\n const filePath: string = output.slice(last, index);\n\n // We passed --no-renames above, so a rename will be a delete of the old location and an add at the new.\n // The newHash will be all zeros if the file is deleted, or a hash if it exists\n const mode: string = header.slice(8, 14);\n const oldhash: string = header.slice(-83, -43);\n const newhash: string = header.slice(-42, -2);\n result.set(filePath, {\n mode,\n oldhash,\n newhash,\n status\n });\n\n last = index + 1;\n index = output.indexOf('\\0', last);\n }\n\n return result;\n}\n\n/**\n * Parses the output of `git status -z -u` to extract the set of files that have changed since HEAD.\n *\n * @param output - The raw output from Git\n * @returns a map of file path to if it exists\n * @internal\n */\nexport function parseGitStatus(output: string): Map<string, boolean> {\n const result: Map<string, boolean> = new Map();\n\n // Parse the output\n // With the -z modifier, paths are delimited by nulls\n // A line looks like:\n // XY <path>\\0\n // M tools/prettier-git/prettier-git.js\\0\n\n let startOfLine: number = 0;\n let eolIndex: number = output.indexOf('\\0', startOfLine);\n while (eolIndex >= 0) {\n // We passed --no-renames above, so a rename will be a delete of the old location and an add at the new.\n // charAt(startOfLine) is the index status, charAt(startOfLine + 1) is the working tree status\n const workingTreeStatus: string = output.charAt(startOfLine + 1);\n // Deleted in working tree, or not modified in working tree and deleted in index\n const deleted: boolean =\n workingTreeStatus === 'D' || (workingTreeStatus === ' ' && output.charAt(startOfLine) === 'D');\n\n const filePath: string = output.slice(startOfLine + 3, eolIndex);\n result.set(filePath, !deleted);\n\n startOfLine = eolIndex + 1;\n eolIndex = output.indexOf('\\0', startOfLine);\n }\n\n return result;\n}\n\nconst repoRootCache: Map<string, string> = new Map();\n\n/**\n * Finds the root of the current Git repository\n *\n * @param currentWorkingDirectory - The working directory for which to locate the repository\n * @param gitPath - The path to the Git executable\n *\n * @returns The full path to the root directory of the Git repository\n * @beta\n */\nexport function getRepoRoot(currentWorkingDirectory: string, gitPath?: string): string {\n let cachedResult: string | undefined = repoRootCache.get(currentWorkingDirectory);\n if (!cachedResult) {\n const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n ['--no-optional-locks', 'rev-parse', '--show-toplevel'],\n {\n currentWorkingDirectory\n }\n );\n\n if (result.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(`git rev-parse exited with status ${result.status}: ${result.stderr}`);\n }\n\n repoRootCache.set(currentWorkingDirectory, (cachedResult = result.stdout.trim()));\n }\n\n return cachedResult;\n}\n\n/**\n * Augments the state value with modifications that are not in the index.\n * @param rootDirectory - The root directory of the Git repository\n * @param state - The current map of git path -> object hash. Will be mutated.\n * @param gitPath - The path to the Git executable\n * @internal\n */\nexport function applyWorkingTreeState(\n rootDirectory: string,\n state: Map<string, string>,\n gitPath?: string\n): void {\n const statusResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n ['--no-optional-locks', 'status', '-z', '-u', '--no-renames', '--ignore-submodules', '--'],\n {\n currentWorkingDirectory: rootDirectory\n }\n );\n\n if (statusResult.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(`git status exited with status ${statusResult.status}: ${statusResult.stderr}`);\n }\n\n const locallyModified: Map<string, boolean> = parseGitStatus(statusResult.stdout);\n\n const filesToHash: string[] = [];\n for (const [filePath, exists] of locallyModified) {\n if (exists) {\n filesToHash.push(filePath);\n } else {\n state.delete(filePath);\n }\n }\n\n if (filesToHash.length) {\n // Use --stdin-paths arg to pass the list of files to git in order to avoid issues with\n // command length\n const hashObjectResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n ['hash-object', '--stdin-paths'],\n { currentWorkingDirectory: rootDirectory, input: filesToHash.join('\\n') }\n );\n\n if (hashObjectResult.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(\n `git hash-object exited with status ${hashObjectResult.status}: ${hashObjectResult.stderr}`\n );\n }\n\n const hashStdout: string = hashObjectResult.stdout.trim();\n\n // The result of \"git hash-object\" will be a list of file hashes delimited by newlines\n const hashes: string[] = hashStdout.split('\\n');\n\n if (hashes.length !== filesToHash.length) {\n throw new Error(\n `Passed ${filesToHash.length} file paths to Git to hash, but received ${hashes.length} hashes.`\n );\n }\n\n const len: number = hashes.length;\n for (let i: number = 0; i < len; i++) {\n const hash: string = hashes[i];\n const filePath: string = filesToHash[i];\n state.set(filePath, hash);\n }\n }\n}\n\n/**\n * Parse the list of all git submodule paths from the output of \"git submodule status\"\n *\n * @param output - The raw output from Git\n * @internal\n */\nexport function _parseGitSubmoduleStatus(output: string): string[] {\n const submodulePaths: string[] = [];\n\n // <hash> <path> (heads/main)\\n\n output.split('\\n').forEach((line) => {\n if (line) {\n const [, submodulePath] = line.trim().split(' ');\n submodulePaths.push(submodulePath);\n }\n });\n return submodulePaths;\n}\n\n/**\n * Get the list of all git submodule paths\n * @param rootDirectory - The root directory of the Git repository\n * @param gitPath - The path to the Git executable\n * @internal\n */\nfunction getSubmodulePaths(rootDirectory: string, gitPath?: string): string[] {\n const submoduleStatusResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n ['submodule', 'status'],\n {\n currentWorkingDirectory: rootDirectory\n }\n );\n\n if (submoduleStatusResult.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(\n `git submodule status exited with status ${submoduleStatusResult.status}: ${submoduleStatusResult.stderr}`\n );\n }\n\n // <hash> <path> (heads/main)\\n\n return _parseGitSubmoduleStatus(submoduleStatusResult.stdout);\n}\n\n/**\n * Parse the state of all git submodule from the output of \"git submodule foreach git --no-optional-locks ls-tree -r --full-name HEAD --\"\n *\n * @param output - The raw output from Git\n * @internal\n */\nexport function _parseGitSubmoduleForEachGitLsTree(output: string): Record<string, Record<string, string>> {\n const stateBySubmodulePath: Record<string, Record<string, string>> = {};\n\n let currentSubmodulePath: string = '';\n\n // Note: Entering maybe translated to other languages by Git\n // Entering '<submoduleFolder>'\\n\n // <mode> <type> <newhash>\\t<path>\\n\n output.split('\\n').forEach((line) => {\n if (line) {\n line = line.trim();\n const submodulePath: string | undefined = line.match(/\\s'(.*)'$/)?.[1];\n if (submodulePath) {\n currentSubmodulePath = submodulePath;\n stateBySubmodulePath[currentSubmodulePath] = {};\n } else {\n const tabIndex: number = line.indexOf('\\t');\n const filePath: string = line.slice(tabIndex + 1);\n\n // The newHash will be all zeros if the file is deleted, or a hash if it exists\n const hash: string = line.slice(tabIndex - 40, tabIndex);\n if (stateBySubmodulePath[currentSubmodulePath] === undefined) {\n stateBySubmodulePath[currentSubmodulePath] = {};\n }\n stateBySubmodulePath[currentSubmodulePath][filePath] = hash;\n }\n }\n });\n\n return stateBySubmodulePath;\n}\n\n/**\n * Augments the state value with modifications that are in git submodules\n * @param rootDirectory - The root directory of the Git repository\n * @param state - The current map of git path -> object hash. Will be mutated.\n * @param gitPath - The path to the Git executable\n * @internal\n */\nfunction applySubmodulesTreeState(rootDirectory: string, state: Map<string, string>, gitPath?: string): void {\n const submodulePaths: string[] = getSubmodulePaths(rootDirectory, gitPath);\n\n if (submodulePaths.length === 0) {\n return;\n }\n\n const submoduleLsTreeResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n ['submodule', 'foreach', 'git', '--no-optional-locks', 'ls-tree', '-r', '--full-name', 'HEAD', '--'],\n {\n currentWorkingDirectory: rootDirectory\n }\n );\n\n if (submoduleLsTreeResult.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(\n `git ls-tree for submodules exited with status ${submoduleLsTreeResult.status}: ${submoduleLsTreeResult.stderr}`\n );\n }\n\n const stateBySubmodulePath: Record<string, Record<string, string>> = _parseGitSubmoduleForEachGitLsTree(\n submoduleLsTreeResult.stdout\n );\n\n for (const submodulePath of submodulePaths) {\n for (const [filePath, hash] of Object.entries(stateBySubmodulePath[submodulePath])) {\n state.set(`${submodulePath}/${filePath}`, hash);\n }\n }\n}\n\n/**\n * Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.\n * @param currentWorkingDirectory - The working directory. Only used to find the repository root.\n * @param gitPath - The path to the Git executable\n * @beta\n */\nexport function getRepoState(currentWorkingDirectory: string, gitPath?: string): Map<string, string> {\n const rootDirectory: string = getRepoRoot(currentWorkingDirectory, gitPath);\n\n const lsTreeResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n ['--no-optional-locks', 'ls-tree', '-r', '-z', '--full-name', 'HEAD', '--'],\n {\n currentWorkingDirectory: rootDirectory\n }\n );\n\n if (lsTreeResult.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(`git ls-tree exited with status ${lsTreeResult.status}: ${lsTreeResult.stderr}`);\n }\n\n const state: Map<string, string> = parseGitLsTree(lsTreeResult.stdout);\n\n applySubmodulesTreeState(rootDirectory, state, gitPath);\n\n applyWorkingTreeState(rootDirectory, state, gitPath);\n\n return state;\n}\n\n/**\n * Find all changed files tracked by Git, their current hashes, and the nature of the change. Only useful if all changes are staged or committed.\n * @param currentWorkingDirectory - The working directory. Only used to find the repository root.\n * @param revision - The Git revision specifier to detect changes relative to. Defaults to HEAD (i.e. will compare staged vs. committed)\n * If comparing against a different branch, call `git merge-base` first to find the target commit.\n * @param gitPath - The path to the Git executable\n * @returns A map from the Git file path to the corresponding file change metadata\n * @beta\n */\nexport function getRepoChanges(\n currentWorkingDirectory: string,\n revision: string = 'HEAD',\n gitPath?: string\n): Map<string, IFileDiffStatus> {\n const rootDirectory: string = getRepoRoot(currentWorkingDirectory, gitPath);\n\n const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n [\n '--no-optional-locks',\n 'diff-index',\n '--color=never',\n '--no-renames',\n '--no-commit-id',\n '--cached',\n '-z',\n revision,\n '--'\n ],\n {\n currentWorkingDirectory: rootDirectory\n }\n );\n\n if (result.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(`git diff-index exited with status ${result.status}: ${result.stderr}`);\n }\n\n const changes: Map<string, IFileDiffStatus> = parseGitDiffIndex(result.stdout);\n\n return changes;\n}\n\n/**\n * Checks the git version and throws an error if it is less than the minimum required version.\n *\n * @public\n */\nexport function ensureGitMinimumVersion(gitPath?: string): void {\n const gitVersion: IGitVersion = getGitVersion(gitPath);\n if (\n gitVersion.major < MINIMUM_GIT_VERSION.major ||\n (gitVersion.major === MINIMUM_GIT_VERSION.major && gitVersion.minor < MINIMUM_GIT_VERSION.minor) ||\n (gitVersion.major === MINIMUM_GIT_VERSION.major &&\n gitVersion.minor === MINIMUM_GIT_VERSION.minor &&\n gitVersion.patch < MINIMUM_GIT_VERSION.patch)\n ) {\n throw new Error(\n `The minimum Git version required is ` +\n `${MINIMUM_GIT_VERSION.major}.${MINIMUM_GIT_VERSION.minor}.${MINIMUM_GIT_VERSION.patch}. ` +\n `Your version is ${gitVersion.major}.${gitVersion.minor}.${gitVersion.patch}.`\n );\n }\n}\n\nfunction getGitVersion(gitPath?: string): IGitVersion {\n const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(gitPath || 'git', ['version']);\n\n if (result.status !== 0) {\n throw new Error(\n `While validating the Git installation, the \"git version\" command failed with ` +\n `status ${result.status}: ${result.stderr}`\n );\n }\n\n return parseGitVersion(result.stdout);\n}\n\nexport function parseGitVersion(gitVersionOutput: string): IGitVersion {\n // This regexp matches output of \"git version\" that looks like `git version <number>.<number>.<number>(+whatever)`\n // Examples:\n // - git version 1.2.3\n // - git version 1.2.3.4.5\n // - git version 1.2.3windows.1\n // - git version 1.2.3.windows.1\n const versionRegex: RegExp = /^git version (\\d+)\\.(\\d+)\\.(\\d+)/;\n const match: RegExpMatchArray | null = versionRegex.exec(gitVersionOutput);\n if (!match) {\n throw new Error(\n `While validating the Git installation, the \"git version\" command produced ` +\n `unexpected output: \"${gitVersionOutput}\"`\n );\n }\n\n const major: number = parseInt(match[1], 10);\n const minor: number = parseInt(match[2], 10);\n const patch: number = parseInt(match[3], 10);\n\n return {\n major,\n minor,\n patch\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getRepoState.js","sourceRoot":"","sources":["../src/getRepoState.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,oEAAsE;AAQtE,MAAM,mBAAmB,GAAgB;IACvC,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,CAAC;CACT,CAAC;AAOF;;;GAGG;AACH,SAAgB,cAAc,CAAC,MAAc;IAC3C,MAAM,KAAK,GAAwB,IAAI,GAAG,EAAE,CAAC;IAC7C,MAAM,UAAU,GAAwB,IAAI,GAAG,EAAE,CAAC;IAElD,mBAAmB;IACnB,qDAAqD;IACrD,qBAAqB;IACrB,oCAAoC;IACpC,6FAA6F;IAE7F,IAAI,IAAI,GAAW,CAAC,CAAC;IACrB,IAAI,KAAK,GAAW,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/C,OAAO,KAAK,IAAI,CAAC,EAAE;QACjB,MAAM,IAAI,GAAW,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAE/C,MAAM,QAAQ,GAAW,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAW,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QAElD,+EAA+E;QAC/E,MAAM,IAAI,GAAW,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,EAAE,EAAE,QAAQ,CAAC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AA0B;IAC1B,+BAA+B;IAC/B,gCAAgC;IAChC,MAAM,YAAY,GAAW,kCAAkC,CAAC;IAChE,MAAM,KAAK,GAA4B,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC3E,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,4EAA4E;YAC1E,uBAAuB,gBAAgB,GAAG,CAC7C,CAAC;KACH;IAED,MAAM,KAAK,GAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAW,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE7C,OAAO;QACL,KAAK;QACL,KAAK;QACL,KAAK;KACN,CAAC;AACJ,CAAC;AAzBD,0CAyBC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type * as child_process from 'child_process';\nimport { Executable, FileSystem } from '@rushstack/node-core-library';\n\nexport interface IGitVersion {\n major: number;\n minor: number;\n patch: number;\n}\n\nconst MINIMUM_GIT_VERSION: IGitVersion = {\n major: 2,\n minor: 20,\n patch: 0\n};\n\ninterface IGitTreeState {\n files: Map<string, string>; // type \"blob\"\n submodules: Map<string, string>; // type \"commit\"\n}\n\n/**\n * Parses the output of the \"git ls-tree -r -z\" command\n * @internal\n */\nexport function parseGitLsTree(output: string): IGitTreeState {\n const files: Map<string, string> = new Map();\n const submodules: Map<string, string> = new Map();\n\n // Parse the output\n // With the -z modifier, paths are delimited by nulls\n // A line looks like:\n // <mode> <type> <newhash>\\t<path>\\0\n // 100644 blob a300ccb0b36bd2c85ef18e3c619a2c747f95959e\\ttools/prettier-git/prettier-git.js\\0\n\n let last: number = 0;\n let index: number = output.indexOf('\\0', last);\n while (index >= 0) {\n const item: string = output.slice(last, index);\n\n const tabIndex: number = item.indexOf('\\t');\n const filePath: string = item.slice(tabIndex + 1);\n\n // The newHash will be all zeros if the file is deleted, or a hash if it exists\n const hash: string = item.slice(tabIndex - 40, tabIndex);\n\n const spaceIndex: number = item.lastIndexOf(' ', tabIndex - 42);\n\n const type: string = item.slice(spaceIndex + 1, tabIndex - 41);\n\n switch (type) {\n case 'commit': {\n submodules.set(filePath, hash);\n break;\n }\n case 'blob':\n default: {\n files.set(filePath, hash);\n break;\n }\n }\n\n last = index + 1;\n index = output.indexOf('\\0', last);\n }\n\n return {\n files,\n submodules\n };\n}\n\n/**\n * Information about the changes to a file.\n * @beta\n */\nexport interface IFileDiffStatus {\n mode: string;\n oldhash: string;\n newhash: string;\n status: 'A' | 'D' | 'M';\n}\n\n/**\n * Parses the output of `git diff-index --color=never --no-renames --no-commit-id -z <REVISION> --\n * Returns a map of file path to diff\n * @internal\n */\nexport function parseGitDiffIndex(output: string): Map<string, IFileDiffStatus> {\n const result: Map<string, IFileDiffStatus> = new Map();\n\n // Parse the output\n // With the -z modifier, paths are delimited by nulls\n // A line looks like:\n // :<oldmode> <newmode> <oldhash> <newhash> <status>\\0<path>\\0\n // :100644 100644 a300ccb0b36bd2c85ef18e3c619a2c747f95959e 0000000000000000000000000000000000000000 M\\0tools/prettier-git/prettier-git.js\\0\n\n let last: number = 0;\n let index: number = output.indexOf('\\0', last);\n while (index >= 0) {\n const header: string = output.slice(last, index);\n const status: IFileDiffStatus['status'] = header.slice(-1) as IFileDiffStatus['status'];\n\n last = index + 1;\n index = output.indexOf('\\0', last);\n const filePath: string = output.slice(last, index);\n\n // We passed --no-renames above, so a rename will be a delete of the old location and an add at the new.\n // The newHash will be all zeros if the file is deleted, or a hash if it exists\n const mode: string = header.slice(8, 14);\n const oldhash: string = header.slice(-83, -43);\n const newhash: string = header.slice(-42, -2);\n result.set(filePath, {\n mode,\n oldhash,\n newhash,\n status\n });\n\n last = index + 1;\n index = output.indexOf('\\0', last);\n }\n\n return result;\n}\n\n/**\n * Parses the output of `git status -z -u` to extract the set of files that have changed since HEAD.\n *\n * @param output - The raw output from Git\n * @returns a map of file path to if it exists\n * @internal\n */\nexport function parseGitStatus(output: string): Map<string, boolean> {\n const result: Map<string, boolean> = new Map();\n\n // Parse the output\n // With the -z modifier, paths are delimited by nulls\n // A line looks like:\n // XY <path>\\0\n // M tools/prettier-git/prettier-git.js\\0\n\n let startOfLine: number = 0;\n let eolIndex: number = output.indexOf('\\0', startOfLine);\n while (eolIndex >= 0) {\n // We passed --no-renames above, so a rename will be a delete of the old location and an add at the new.\n // charAt(startOfLine) is the index status, charAt(startOfLine + 1) is the working tree status\n const workingTreeStatus: string = output.charAt(startOfLine + 1);\n // Deleted in working tree, or not modified in working tree and deleted in index\n const deleted: boolean =\n workingTreeStatus === 'D' || (workingTreeStatus === ' ' && output.charAt(startOfLine) === 'D');\n\n const filePath: string = output.slice(startOfLine + 3, eolIndex);\n result.set(filePath, !deleted);\n\n startOfLine = eolIndex + 1;\n eolIndex = output.indexOf('\\0', startOfLine);\n }\n\n return result;\n}\n\nconst repoRootCache: Map<string, string> = new Map();\n\n/**\n * Finds the root of the current Git repository\n *\n * @param currentWorkingDirectory - The working directory for which to locate the repository\n * @param gitPath - The path to the Git executable\n *\n * @returns The full path to the root directory of the Git repository\n * @beta\n */\nexport function getRepoRoot(currentWorkingDirectory: string, gitPath?: string): string {\n let cachedResult: string | undefined = repoRootCache.get(currentWorkingDirectory);\n if (!cachedResult) {\n const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n ['--no-optional-locks', 'rev-parse', '--show-toplevel'],\n {\n currentWorkingDirectory\n }\n );\n\n if (result.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(`git rev-parse exited with status ${result.status}: ${result.stderr}`);\n }\n\n repoRootCache.set(currentWorkingDirectory, (cachedResult = result.stdout.trim()));\n }\n\n return cachedResult;\n}\n\n/**\n * Augments the state value with modifications that are not in the index.\n * @param rootDirectory - The root directory of the Git repository\n * @param state - The current map of git path -> object hash. Will be mutated.\n * @param gitPath - The path to the Git executable\n * @internal\n */\nexport function applyWorkingTreeState(\n rootDirectory: string,\n state: Map<string, string>,\n gitPath?: string\n): void {\n const statusResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n ['--no-optional-locks', 'status', '-z', '-u', '--no-renames', '--ignore-submodules', '--'],\n {\n currentWorkingDirectory: rootDirectory\n }\n );\n\n if (statusResult.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(`git status exited with status ${statusResult.status}: ${statusResult.stderr}`);\n }\n\n const locallyModified: Map<string, boolean> = parseGitStatus(statusResult.stdout);\n\n const filesToHash: string[] = [];\n for (const [filePath, exists] of locallyModified) {\n if (exists) {\n filesToHash.push(filePath);\n } else {\n state.delete(filePath);\n }\n }\n\n if (filesToHash.length) {\n // Use --stdin-paths arg to pass the list of files to git in order to avoid issues with\n // command length\n const hashObjectResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n ['hash-object', '--stdin-paths'],\n { currentWorkingDirectory: rootDirectory, input: filesToHash.join('\\n') }\n );\n\n if (hashObjectResult.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(\n `git hash-object exited with status ${hashObjectResult.status}: ${hashObjectResult.stderr}`\n );\n }\n\n const hashStdout: string = hashObjectResult.stdout.trim();\n\n // The result of \"git hash-object\" will be a list of file hashes delimited by newlines\n const hashes: string[] = hashStdout.split('\\n');\n\n if (hashes.length !== filesToHash.length) {\n throw new Error(\n `Passed ${filesToHash.length} file paths to Git to hash, but received ${hashes.length} hashes.`\n );\n }\n\n const len: number = hashes.length;\n for (let i: number = 0; i < len; i++) {\n const hash: string = hashes[i];\n const filePath: string = filesToHash[i];\n state.set(filePath, hash);\n }\n }\n}\n\n/**\n * Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.\n * @param currentWorkingDirectory - The working directory. Only used to find the repository root.\n * @param gitPath - The path to the Git executable\n * @beta\n */\nexport function getRepoState(currentWorkingDirectory: string, gitPath?: string): Map<string, string> {\n const rootDirectory: string = getRepoRoot(currentWorkingDirectory, gitPath);\n\n const lsTreeResult: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n ['--no-optional-locks', 'ls-tree', '-r', '-z', '--full-name', 'HEAD', '--'],\n {\n currentWorkingDirectory: rootDirectory\n }\n );\n\n if (lsTreeResult.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(`git ls-tree exited with status ${lsTreeResult.status}: ${lsTreeResult.stderr}`);\n }\n\n const { files, submodules } = parseGitLsTree(lsTreeResult.stdout);\n\n applyWorkingTreeState(rootDirectory, files, gitPath);\n\n const state: Map<string, string> = files;\n\n // Existence check for the .gitmodules file\n const hasSubmodules: boolean = submodules.size > 0 && FileSystem.exists(`${rootDirectory}/.gitmodules`);\n\n if (hasSubmodules) {\n for (const submodulePath of submodules.keys()) {\n const submoduleState: Map<string, string> = getRepoState(`${rootDirectory}/${submodulePath}`, gitPath);\n for (const [filePath, hash] of submoduleState) {\n state.set(`${submodulePath}/${filePath}`, hash);\n }\n }\n }\n\n return state;\n}\n\n/**\n * Find all changed files tracked by Git, their current hashes, and the nature of the change. Only useful if all changes are staged or committed.\n * @param currentWorkingDirectory - The working directory. Only used to find the repository root.\n * @param revision - The Git revision specifier to detect changes relative to. Defaults to HEAD (i.e. will compare staged vs. committed)\n * If comparing against a different branch, call `git merge-base` first to find the target commit.\n * @param gitPath - The path to the Git executable\n * @returns A map from the Git file path to the corresponding file change metadata\n * @beta\n */\nexport function getRepoChanges(\n currentWorkingDirectory: string,\n revision: string = 'HEAD',\n gitPath?: string\n): Map<string, IFileDiffStatus> {\n const rootDirectory: string = getRepoRoot(currentWorkingDirectory, gitPath);\n\n const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(\n gitPath || 'git',\n [\n '--no-optional-locks',\n 'diff-index',\n '--color=never',\n '--no-renames',\n '--no-commit-id',\n '--cached',\n '-z',\n revision,\n '--'\n ],\n {\n currentWorkingDirectory: rootDirectory\n }\n );\n\n if (result.status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(`git diff-index exited with status ${result.status}: ${result.stderr}`);\n }\n\n const changes: Map<string, IFileDiffStatus> = parseGitDiffIndex(result.stdout);\n\n return changes;\n}\n\n/**\n * Checks the git version and throws an error if it is less than the minimum required version.\n *\n * @public\n */\nexport function ensureGitMinimumVersion(gitPath?: string): void {\n const gitVersion: IGitVersion = getGitVersion(gitPath);\n if (\n gitVersion.major < MINIMUM_GIT_VERSION.major ||\n (gitVersion.major === MINIMUM_GIT_VERSION.major && gitVersion.minor < MINIMUM_GIT_VERSION.minor) ||\n (gitVersion.major === MINIMUM_GIT_VERSION.major &&\n gitVersion.minor === MINIMUM_GIT_VERSION.minor &&\n gitVersion.patch < MINIMUM_GIT_VERSION.patch)\n ) {\n throw new Error(\n `The minimum Git version required is ` +\n `${MINIMUM_GIT_VERSION.major}.${MINIMUM_GIT_VERSION.minor}.${MINIMUM_GIT_VERSION.patch}. ` +\n `Your version is ${gitVersion.major}.${gitVersion.minor}.${gitVersion.patch}.`\n );\n }\n}\n\nfunction getGitVersion(gitPath?: string): IGitVersion {\n const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(gitPath || 'git', ['version']);\n\n if (result.status !== 0) {\n throw new Error(\n `While validating the Git installation, the \"git version\" command failed with ` +\n `status ${result.status}: ${result.stderr}`\n );\n }\n\n return parseGitVersion(result.stdout);\n}\n\nexport function parseGitVersion(gitVersionOutput: string): IGitVersion {\n // This regexp matches output of \"git version\" that looks like `git version <number>.<number>.<number>(+whatever)`\n // Examples:\n // - git version 1.2.3\n // - git version 1.2.3.4.5\n // - git version 1.2.3windows.1\n // - git version 1.2.3.windows.1\n const versionRegex: RegExp = /^git version (\\d+)\\.(\\d+)\\.(\\d+)/;\n const match: RegExpMatchArray | null = versionRegex.exec(gitVersionOutput);\n if (!match) {\n throw new Error(\n `While validating the Git installation, the \"git version\" command produced ` +\n `unexpected output: \"${gitVersionOutput}\"`\n );\n }\n\n const major: number = parseInt(match[1], 10);\n const minor: number = parseInt(match[2], 10);\n const patch: number = parseInt(match[3], 10);\n\n return {\n major,\n minor,\n patch\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/package-deps-hash",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.64",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "dist/package-deps-hash.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@rushstack/eslint-config": "3.1.1",
|
|
15
15
|
"@rushstack/heft": "0.48.8",
|
|
16
|
-
"@rushstack/heft-node-rig": "1.11.
|
|
16
|
+
"@rushstack/heft-node-rig": "1.11.9",
|
|
17
17
|
"@rushstack/node-core-library": "3.53.2",
|
|
18
18
|
"@types/heft-jest": "1.0.1",
|
|
19
19
|
"@types/node": "12.20.24"
|