@rushstack/package-deps-hash 4.6.0 → 4.6.1
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 +12 -0
- package/CHANGELOG.md +8 -1
- package/lib/getRepoState.d.ts.map +1 -1
- package/lib/getRepoState.js +9 -7
- package/lib/getRepoState.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/package-deps-hash",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "4.6.1",
|
|
6
|
+
"tag": "@rushstack/package-deps-hash_v4.6.1",
|
|
7
|
+
"date": "Mon, 29 Dec 2025 22:42:58 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Update MINIMUM_GIT_VERSION to 2.35.0 to account for usage of the --format argument with git ls-files"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "4.6.0",
|
|
6
18
|
"tag": "@rushstack/package-deps-hash_v4.6.0",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Change Log - @rushstack/package-deps-hash
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 29 Dec 2025 22:42:58 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.6.1
|
|
6
|
+
Mon, 29 Dec 2025 22:42:58 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Update MINIMUM_GIT_VERSION to 2.35.0 to account for usage of the --format argument with git ls-files
|
|
4
11
|
|
|
5
12
|
## 4.6.0
|
|
6
13
|
Fri, 12 Dec 2025 01:12:05 GMT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRepoState.d.ts","sourceRoot":"","sources":["../src/getRepoState.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getRepoState.d.ts","sourceRoot":"","sources":["../src/getRepoState.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAyBD,UAAU,aAAa;IACrB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAoD5D;AAED;;;;GAIG;AACH,wBAAiB,kBAAkB,CACjC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,GAC/B,gBAAgB,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA4BpC;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,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GAAG,IAAI,CAe9D;AAkBD,wBAAgB,eAAe,CAAC,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAyBrE"}
|
package/lib/getRepoState.js
CHANGED
|
@@ -15,10 +15,11 @@ exports.ensureGitMinimumVersion = ensureGitMinimumVersion;
|
|
|
15
15
|
exports.parseGitVersion = parseGitVersion;
|
|
16
16
|
const node_events_1 = require("node:events");
|
|
17
17
|
const node_stream_1 = require("node:stream");
|
|
18
|
-
const
|
|
18
|
+
const Executable_1 = require("@rushstack/node-core-library/lib/Executable");
|
|
19
|
+
const FileSystem_1 = require("@rushstack/node-core-library/lib/FileSystem");
|
|
19
20
|
const MINIMUM_GIT_VERSION = {
|
|
20
21
|
major: 2,
|
|
21
|
-
minor:
|
|
22
|
+
minor: 35,
|
|
22
23
|
patch: 0
|
|
23
24
|
};
|
|
24
25
|
const STANDARD_GIT_OPTIONS = [
|
|
@@ -192,7 +193,7 @@ const repoRootCache = new Map();
|
|
|
192
193
|
function getRepoRoot(currentWorkingDirectory, gitPath) {
|
|
193
194
|
let cachedResult = repoRootCache.get(currentWorkingDirectory);
|
|
194
195
|
if (!cachedResult) {
|
|
195
|
-
const result =
|
|
196
|
+
const result = Executable_1.Executable.spawnSync(gitPath || 'git', ['--no-optional-locks', 'rev-parse', '--show-toplevel'], {
|
|
196
197
|
currentWorkingDirectory
|
|
197
198
|
});
|
|
198
199
|
if (result.status !== 0) {
|
|
@@ -220,7 +221,7 @@ async function spawnGitAsync(gitPath, args, currentWorkingDirectory, stdin) {
|
|
|
220
221
|
};
|
|
221
222
|
let stdout = '';
|
|
222
223
|
let stderr = '';
|
|
223
|
-
const proc =
|
|
224
|
+
const proc = Executable_1.Executable.spawn(gitPath || 'git', args, spawnOptions);
|
|
224
225
|
proc.stdout.setEncoding('utf-8');
|
|
225
226
|
proc.stderr.setEncoding('utf-8');
|
|
226
227
|
proc.stdout.on('data', (chunk) => {
|
|
@@ -239,6 +240,7 @@ async function spawnGitAsync(gitPath, args, currentWorkingDirectory, stdin) {
|
|
|
239
240
|
}
|
|
240
241
|
const [status] = await (0, node_events_1.once)(proc, 'close');
|
|
241
242
|
if (status !== 0) {
|
|
243
|
+
ensureGitMinimumVersion(gitPath);
|
|
242
244
|
throw new Error(`git ${args[0]} exited with code ${status}:\n${stderr}`);
|
|
243
245
|
}
|
|
244
246
|
return stdout;
|
|
@@ -357,7 +359,7 @@ async function getDetailedRepoStateAsync(rootDirectory, additionalRelativePathsT
|
|
|
357
359
|
files.set(filePath, hash);
|
|
358
360
|
}
|
|
359
361
|
// Existence check for the .gitmodules file
|
|
360
|
-
const hasSubmodules = submodules.size > 0 &&
|
|
362
|
+
const hasSubmodules = submodules.size > 0 && FileSystem_1.FileSystem.exists(`${rootDirectory}/.gitmodules`);
|
|
361
363
|
if (hasSubmodules) {
|
|
362
364
|
// Submodules are not the normal critical path. Accept serial performance rather than investing in complexity.
|
|
363
365
|
// Can revisit if submodules become more commonly used.
|
|
@@ -386,7 +388,7 @@ async function getDetailedRepoStateAsync(rootDirectory, additionalRelativePathsT
|
|
|
386
388
|
*/
|
|
387
389
|
function getRepoChanges(currentWorkingDirectory, revision = 'HEAD', gitPath) {
|
|
388
390
|
const rootDirectory = getRepoRoot(currentWorkingDirectory, gitPath);
|
|
389
|
-
const result =
|
|
391
|
+
const result = Executable_1.Executable.spawnSync(gitPath || 'git', STANDARD_GIT_OPTIONS.concat([
|
|
390
392
|
'diff-index',
|
|
391
393
|
'--color=never',
|
|
392
394
|
'--no-renames',
|
|
@@ -423,7 +425,7 @@ function ensureGitMinimumVersion(gitPath) {
|
|
|
423
425
|
}
|
|
424
426
|
}
|
|
425
427
|
function getGitVersion(gitPath) {
|
|
426
|
-
const result =
|
|
428
|
+
const result = Executable_1.Executable.spawnSync(gitPath || 'git', STANDARD_GIT_OPTIONS.concat(['version']));
|
|
427
429
|
if (result.status !== 0) {
|
|
428
430
|
throw new Error(`While validating the Git installation, the "git version" command failed with ` +
|
|
429
431
|
`status ${result.status}: ${result.st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,+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,CAAC;QACX,MAAM,IAAI,KAAK,CACb,4EAA4E;YAC1E,uBAAuB,gBAAgB,GAAG,CAC7C,CAAC;IACJ,CAAC;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","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 'node:child_process';\nimport { once } from 'node:events';\nimport { Readable, pipeline } from 'node:stream';\n\nimport { Executable, FileSystem, type IExecutableSpawnOptions } 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\nconst STANDARD_GIT_OPTIONS: readonly string[] = [\n // Don't request any optional file locks\n '--no-optional-locks',\n // Ensure that commands don't run automatic maintenance, since performance of the command itself is paramount\n '-c',\n 'maintenance.auto=false'\n];\n\nconst OBJECTMODE_SUBMODULE: '160000' = '160000';\nconst OBJECTMODE_SYMLINK: '120000' = '120000';\nconst OBJECTMODE_FILE_NONEXECUTABLE: '100644' = '100644';\nconst OBJECTMODE_FILE_EXECUTABLE: '100755' = '100755';\n\n// Note that `type` is a stub that is being ignored by the parser in favor of using `mode` to infer, since `%(objecttype)` requires git 2.51.0+\n// e.g. 10644 blob <hash>\\t<path>\nconst GIT_LSTREE_FORMAT: string = '%(objectmode) type %(objectname)%x09%(path)';\n\ninterface IGitTreeState {\n files: Map<string, string>; // type \"blob\"\n symlinks: Map<string, string>; // type \"link\"\n submodules: Map<string, string>; // type \"commit\"\n}\n\n/**\n * Parses the output of the \"git ls-tree -r -z\" command or of other commands that have been coerced to match its format.\n * @internal\n */\nexport function parseGitLsTree(output: string): IGitTreeState {\n const files: Map<string, string> = new Map();\n const symlinks: 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 mode: string = item.slice(0, item.indexOf(' '));\n\n switch (mode) {\n case OBJECTMODE_SUBMODULE: {\n // This is a submodule\n submodules.set(filePath, hash);\n break;\n }\n case OBJECTMODE_SYMLINK: {\n // This is a symbolic link\n symlinks.set(filePath, hash);\n break;\n }\n case OBJECTMODE_FILE_NONEXECUTABLE:\n case OBJECTMODE_FILE_EXECUTABLE:\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 symlinks,\n submodules\n };\n}\n\n/**\n * Parses the output of `git hash-object`\n * yields [filePath, hash] pairs.\n * @internal\n */\nexport function* parseGitHashObject(\n output: string,\n filePaths: ReadonlyArray<string>\n): IterableIterator<[string, string]> {\n const expected: number = filePaths.length;\n if (expected === 0) {\n return;\n }\n\n output = output.trim();\n\n let last: number = 0;\n let i: number = 0;\n let index: number = output.indexOf('\\n', last);\n for (; i < expected && index > 0; i++) {\n const hash: string = output.slice(last, index);\n yield [filePaths[i], hash];\n last = index + 1;\n index = output.indexOf('\\n', last);\n }\n\n // Handle last line. Will be non-empty to due trim() call.\n if (index < 0) {\n const hash: string = output.slice(last);\n yield [filePaths[i], hash];\n i++;\n }\n\n if (i !== expected) {\n throw new Error(`Expected ${expected} hashes from \"git hash-object\" but received ${i}`);\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 cachedResult = result.stdout.trim();\n\n repoRootCache.set(currentWorkingDirectory, cachedResult);\n // To ensure that calling getRepoRoot on the result is a no-op.\n repoRootCache.set(cachedResult, cachedResult);\n }\n\n return cachedResult;\n}\n\n/**\n * Helper function for async process invocation with optional stdin support.\n * @param gitPath - Path to the Git executable\n * @param args - The process arguments\n * @param currentWorkingDirectory - The working directory. Should be the repository root.\n * @param stdin - An optional Readable stream to use as stdin to the process.\n */\nasync function spawnGitAsync(\n gitPath: string | undefined,\n args: string[],\n currentWorkingDirectory: string,\n stdin?: Readable\n): Promise<string> {\n const spawnOptions: IExecutableSpawnOptions = {\n currentWorkingDirectory,\n stdio: ['pipe', 'pipe', 'pipe']\n };\n\n let stdout: string = '';\n let stderr: string = '';\n\n const proc: child_process.ChildProcess = Executable.spawn(gitPath || 'git', args, spawnOptions);\n proc.stdout!.setEncoding('utf-8');\n proc.stderr!.setEncoding('utf-8');\n\n proc.stdout!.on('data', (chunk: string) => {\n stdout += chunk.toString();\n });\n proc.stderr!.on('data', (chunk: string) => {\n stderr += chunk.toString();\n });\n\n if (stdin) {\n /**\n * For `git hash-object` data is piped in asynchronously. In the event that one of the\n * passed filenames cannot be hashed, subsequent writes to `proc.stdin` will error.\n * Silence this error since it will be handled by the non-zero exit code of the process.\n */\n pipeline(stdin, proc.stdin!, (err) => {});\n }\n\n const [status] = await once(proc, 'close');\n if (status !== 0) {\n throw new Error(`git ${args[0]} exited with code ${status}:\\n${stderr}`);\n }\n\n return stdout;\n}\n\nfunction isIterable<T>(value: Iterable<T> | AsyncIterable<T>): value is Iterable<T> {\n return Symbol.iterator in value;\n}\n\n/**\n * Uses `git hash-object` to hash the provided files. Unlike `getGitHashForFiles`, this API is asynchronous, and also allows for\n * the input file paths to be specified as an async iterable.\n *\n * @param rootDirectory - The root directory to which paths are specified relative. Must be the root of the Git repository.\n * @param filesToHash - The file paths to hash using `git hash-object`\n * @param gitPath - The path to the Git executable\n * @returns An iterable of [filePath, hash] pairs\n *\n * @remarks\n * The input file paths must be specified relative to the Git repository root, or else be absolute paths.\n * @beta\n */\nexport async function hashFilesAsync(\n rootDirectory: string,\n filesToHash: Iterable<string> | AsyncIterable<string>,\n gitPath?: string\n): Promise<Iterable<[string, string]>> {\n const hashPaths: string[] = [];\n\n const input: Readable = Readable.from(\n isIterable(filesToHash)\n ? (function* (): IterableIterator<string> {\n for (const file of filesToHash) {\n hashPaths.push(file);\n yield `${file}\\n`;\n }\n })()\n : (async function* (): AsyncIterableIterator<string> {\n for await (const file of filesToHash) {\n hashPaths.push(file);\n yield `${file}\\n`;\n }\n })(),\n {\n encoding: 'utf-8',\n objectMode: false,\n autoDestroy: true\n }\n );\n\n const hashObjectResult: string = await spawnGitAsync(\n gitPath,\n STANDARD_GIT_OPTIONS.concat(['hash-object', '--stdin-paths']),\n rootDirectory,\n input\n );\n\n return parseGitHashObject(hashObjectResult, hashPaths);\n}\n\n/**\n * Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.\n * Uses async operations and runs all primary Git calls in parallel.\n * @param rootDirectory - The root directory of the Git repository\n * @param additionalRelativePathsToHash - Root-relative file paths to have Git hash and include in the results\n * @param gitPath - The path to the Git executable\n * @beta\n */\nexport async function getRepoStateAsync(\n rootDirectory: string,\n additionalRelativePathsToHash?: string[],\n gitPath?: string,\n filterPath?: string[]\n): Promise<Map<string, string>> {\n const { files } = await getDetailedRepoStateAsync(\n rootDirectory,\n additionalRelativePathsToHash,\n gitPath,\n filterPath\n );\n\n return files;\n}\n\n/**\n * Information about the detailed state of the Git repository.\n * @beta\n */\nexport interface IDetailedRepoState {\n /**\n * The Git file hashes for all files in the repository, including uncommitted changes.\n */\n files: Map<string, string>;\n /**\n * The Git file hashes for all symbolic links in the repository, including uncommitted changes.\n */\n symlinks: Map<string, string>;\n /**\n * A boolean indicating whether the repository has submodules.\n */\n hasSubmodules: boolean;\n /**\n * A boolean indicating whether the repository has uncommitted changes.\n */\n hasUncommittedChanges: boolean;\n}\n\n/**\n * Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.\n * Uses async operations and runs all primary Git calls in parallel.\n * @param rootDirectory - The root directory of the Git repository\n * @param additionalRelativePathsToHash - Root-relative file paths to have Git hash and include in the results\n * @param gitPath - The path to the Git executable\n * @beta\n */\nexport async function getDetailedRepoStateAsync(\n rootDirectory: string,\n additionalRelativePathsToHash?: string[],\n gitPath?: string,\n filterPath?: string[]\n): Promise<IDetailedRepoState> {\n const statePromise: Promise<IGitTreeState> = spawnGitAsync(\n gitPath,\n STANDARD_GIT_OPTIONS.concat([\n 'ls-files',\n // Read from the index only\n '--cached',\n // Use NUL as the separator\n '-z',\n // Specify the full path to files relative to the root\n '--full-name',\n // Match the format of \"git ls-tree\". The %(objecttype) placeholder requires git 2.51.0+, so not using yet.\n `--format=${GIT_LSTREE_FORMAT}`,\n '--',\n ...(filterPath ?? [])\n ]),\n rootDirectory\n ).then(parseGitLsTree);\n const locallyModifiedPromise: Promise<Map<string, boolean>> = spawnGitAsync(\n gitPath,\n STANDARD_GIT_OPTIONS.concat([\n 'status',\n // Use NUL as the separator\n '-z',\n // Include untracked files\n '-u',\n // Disable rename detection so that renames show up as add + delete\n '--no-renames',\n // Don't process submodules with this command; they'll be handled individually\n '--ignore-submodules',\n // Don't compare against the remote\n '--no-ahead-behind',\n '--',\n ...(filterPath ?? [])\n ]),\n rootDirectory\n ).then(parseGitStatus);\n\n async function* getFilesToHash(): AsyncIterableIterator<string> {\n if (additionalRelativePathsToHash) {\n for (const file of additionalRelativePathsToHash) {\n yield file;\n }\n }\n\n const [{ files, symlinks }, locallyModified] = await Promise.all([statePromise, locallyModifiedPromise]);\n\n for (const [filePath, exists] of locallyModified) {\n if (exists && !symlinks.has(filePath)) {\n yield filePath;\n } else {\n files.delete(filePath);\n symlinks.delete(filePath);\n }\n }\n }\n\n const hashObjectPromise: Promise<Iterable<[string, string]>> = hashFilesAsync(\n rootDirectory,\n getFilesToHash(),\n gitPath\n );\n\n const [{ files, symlinks, submodules }, locallyModifiedFiles] = await Promise.all([\n statePromise,\n locallyModifiedPromise\n ]);\n\n // The result of \"git hash-object\" will be a list of file hashes delimited by newlines\n for (const [filePath, hash] of await hashObjectPromise) {\n files.set(filePath, hash);\n }\n\n // Existence check for the .gitmodules file\n const hasSubmodules: boolean = submodules.size > 0 && FileSystem.exists(`${rootDirectory}/.gitmodules`);\n\n if (hasSubmodules) {\n // Submodules are not the normal critical path. Accept serial performance rather than investing in complexity.\n // Can revisit if submodules become more commonly used.\n for (const submodulePath of submodules.keys()) {\n const submoduleState: Map<string, string> = await getRepoStateAsync(\n `${rootDirectory}/${submodulePath}`,\n [],\n gitPath\n );\n for (const [filePath, hash] of submoduleState) {\n files.set(`${submodulePath}/${filePath}`, hash);\n }\n }\n }\n\n return {\n hasSubmodules,\n hasUncommittedChanges: locallyModifiedFiles.size > 0,\n files,\n symlinks\n };\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 STANDARD_GIT_OPTIONS.concat([\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(\n gitPath || 'git',\n STANDARD_GIT_OPTIONS.concat(['version'])\n );\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;;AAgD3D,wCAoDC;AAOD,gDA+BC;AAkBD,8C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C,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,4EAA4E;YAC1E,uBAAuB,gBAAgB,GAAG,CAC7C,CAAC;IACJ,CAAC;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","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 'node:child_process';\nimport { once } from 'node:events';\nimport { Readable, pipeline } from 'node:stream';\n\nimport { Executable, type IExecutableSpawnOptions } from '@rushstack/node-core-library/lib/Executable';\nimport { FileSystem } from '@rushstack/node-core-library/lib/FileSystem';\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: 35,\n patch: 0\n};\n\nconst STANDARD_GIT_OPTIONS: readonly string[] = [\n // Don't request any optional file locks\n '--no-optional-locks',\n // Ensure that commands don't run automatic maintenance, since performance of the command itself is paramount\n '-c',\n 'maintenance.auto=false'\n];\n\nconst OBJECTMODE_SUBMODULE: '160000' = '160000';\nconst OBJECTMODE_SYMLINK: '120000' = '120000';\nconst OBJECTMODE_FILE_NONEXECUTABLE: '100644' = '100644';\nconst OBJECTMODE_FILE_EXECUTABLE: '100755' = '100755';\n\n// Note that `type` is a stub that is being ignored by the parser in favor of using `mode` to infer, since `%(objecttype)` requires git 2.51.0+\n// e.g. 10644 blob <hash>\\t<path>\nconst GIT_LSTREE_FORMAT: string = '%(objectmode) type %(objectname)%x09%(path)';\n\ninterface IGitTreeState {\n files: Map<string, string>; // type \"blob\"\n symlinks: Map<string, string>; // type \"link\"\n submodules: Map<string, string>; // type \"commit\"\n}\n\n/**\n * Parses the output of the \"git ls-tree -r -z\" command or of other commands that have been coerced to match its format.\n * @internal\n */\nexport function parseGitLsTree(output: string): IGitTreeState {\n const files: Map<string, string> = new Map();\n const symlinks: 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 mode: string = item.slice(0, item.indexOf(' '));\n\n switch (mode) {\n case OBJECTMODE_SUBMODULE: {\n // This is a submodule\n submodules.set(filePath, hash);\n break;\n }\n case OBJECTMODE_SYMLINK: {\n // This is a symbolic link\n symlinks.set(filePath, hash);\n break;\n }\n case OBJECTMODE_FILE_NONEXECUTABLE:\n case OBJECTMODE_FILE_EXECUTABLE:\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 symlinks,\n submodules\n };\n}\n\n/**\n * Parses the output of `git hash-object`\n * yields [filePath, hash] pairs.\n * @internal\n */\nexport function* parseGitHashObject(\n output: string,\n filePaths: ReadonlyArray<string>\n): IterableIterator<[string, string]> {\n const expected: number = filePaths.length;\n if (expected === 0) {\n return;\n }\n\n output = output.trim();\n\n let last: number = 0;\n let i: number = 0;\n let index: number = output.indexOf('\\n', last);\n for (; i < expected && index > 0; i++) {\n const hash: string = output.slice(last, index);\n yield [filePaths[i], hash];\n last = index + 1;\n index = output.indexOf('\\n', last);\n }\n\n // Handle last line. Will be non-empty to due trim() call.\n if (index < 0) {\n const hash: string = output.slice(last);\n yield [filePaths[i], hash];\n i++;\n }\n\n if (i !== expected) {\n throw new Error(`Expected ${expected} hashes from \"git hash-object\" but received ${i}`);\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 cachedResult = result.stdout.trim();\n\n repoRootCache.set(currentWorkingDirectory, cachedResult);\n // To ensure that calling getRepoRoot on the result is a no-op.\n repoRootCache.set(cachedResult, cachedResult);\n }\n\n return cachedResult;\n}\n\n/**\n * Helper function for async process invocation with optional stdin support.\n * @param gitPath - Path to the Git executable\n * @param args - The process arguments\n * @param currentWorkingDirectory - The working directory. Should be the repository root.\n * @param stdin - An optional Readable stream to use as stdin to the process.\n */\nasync function spawnGitAsync(\n gitPath: string | undefined,\n args: string[],\n currentWorkingDirectory: string,\n stdin?: Readable\n): Promise<string> {\n const spawnOptions: IExecutableSpawnOptions = {\n currentWorkingDirectory,\n stdio: ['pipe', 'pipe', 'pipe']\n };\n\n let stdout: string = '';\n let stderr: string = '';\n\n const proc: child_process.ChildProcess = Executable.spawn(gitPath || 'git', args, spawnOptions);\n proc.stdout!.setEncoding('utf-8');\n proc.stderr!.setEncoding('utf-8');\n\n proc.stdout!.on('data', (chunk: string) => {\n stdout += chunk.toString();\n });\n proc.stderr!.on('data', (chunk: string) => {\n stderr += chunk.toString();\n });\n\n if (stdin) {\n /**\n * For `git hash-object` data is piped in asynchronously. In the event that one of the\n * passed filenames cannot be hashed, subsequent writes to `proc.stdin` will error.\n * Silence this error since it will be handled by the non-zero exit code of the process.\n */\n pipeline(stdin, proc.stdin!, (err) => {});\n }\n\n const [status] = await once(proc, 'close');\n if (status !== 0) {\n ensureGitMinimumVersion(gitPath);\n\n throw new Error(`git ${args[0]} exited with code ${status}:\\n${stderr}`);\n }\n\n return stdout;\n}\n\nfunction isIterable<T>(value: Iterable<T> | AsyncIterable<T>): value is Iterable<T> {\n return Symbol.iterator in value;\n}\n\n/**\n * Uses `git hash-object` to hash the provided files. Unlike `getGitHashForFiles`, this API is asynchronous, and also allows for\n * the input file paths to be specified as an async iterable.\n *\n * @param rootDirectory - The root directory to which paths are specified relative. Must be the root of the Git repository.\n * @param filesToHash - The file paths to hash using `git hash-object`\n * @param gitPath - The path to the Git executable\n * @returns An iterable of [filePath, hash] pairs\n *\n * @remarks\n * The input file paths must be specified relative to the Git repository root, or else be absolute paths.\n * @beta\n */\nexport async function hashFilesAsync(\n rootDirectory: string,\n filesToHash: Iterable<string> | AsyncIterable<string>,\n gitPath?: string\n): Promise<Iterable<[string, string]>> {\n const hashPaths: string[] = [];\n\n const input: Readable = Readable.from(\n isIterable(filesToHash)\n ? (function* (): IterableIterator<string> {\n for (const file of filesToHash) {\n hashPaths.push(file);\n yield `${file}\\n`;\n }\n })()\n : (async function* (): AsyncIterableIterator<string> {\n for await (const file of filesToHash) {\n hashPaths.push(file);\n yield `${file}\\n`;\n }\n })(),\n {\n encoding: 'utf-8',\n objectMode: false,\n autoDestroy: true\n }\n );\n\n const hashObjectResult: string = await spawnGitAsync(\n gitPath,\n STANDARD_GIT_OPTIONS.concat(['hash-object', '--stdin-paths']),\n rootDirectory,\n input\n );\n\n return parseGitHashObject(hashObjectResult, hashPaths);\n}\n\n/**\n * Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.\n * Uses async operations and runs all primary Git calls in parallel.\n * @param rootDirectory - The root directory of the Git repository\n * @param additionalRelativePathsToHash - Root-relative file paths to have Git hash and include in the results\n * @param gitPath - The path to the Git executable\n * @beta\n */\nexport async function getRepoStateAsync(\n rootDirectory: string,\n additionalRelativePathsToHash?: string[],\n gitPath?: string,\n filterPath?: string[]\n): Promise<Map<string, string>> {\n const { files } = await getDetailedRepoStateAsync(\n rootDirectory,\n additionalRelativePathsToHash,\n gitPath,\n filterPath\n );\n\n return files;\n}\n\n/**\n * Information about the detailed state of the Git repository.\n * @beta\n */\nexport interface IDetailedRepoState {\n /**\n * The Git file hashes for all files in the repository, including uncommitted changes.\n */\n files: Map<string, string>;\n /**\n * The Git file hashes for all symbolic links in the repository, including uncommitted changes.\n */\n symlinks: Map<string, string>;\n /**\n * A boolean indicating whether the repository has submodules.\n */\n hasSubmodules: boolean;\n /**\n * A boolean indicating whether the repository has uncommitted changes.\n */\n hasUncommittedChanges: boolean;\n}\n\n/**\n * Gets the object hashes for all files in the Git repo, combining the current commit with working tree state.\n * Uses async operations and runs all primary Git calls in parallel.\n * @param rootDirectory - The root directory of the Git repository\n * @param additionalRelativePathsToHash - Root-relative file paths to have Git hash and include in the results\n * @param gitPath - The path to the Git executable\n * @beta\n */\nexport async function getDetailedRepoStateAsync(\n rootDirectory: string,\n additionalRelativePathsToHash?: string[],\n gitPath?: string,\n filterPath?: string[]\n): Promise<IDetailedRepoState> {\n const statePromise: Promise<IGitTreeState> = spawnGitAsync(\n gitPath,\n STANDARD_GIT_OPTIONS.concat([\n 'ls-files',\n // Read from the index only\n '--cached',\n // Use NUL as the separator\n '-z',\n // Specify the full path to files relative to the root\n '--full-name',\n // Match the format of \"git ls-tree\". The %(objecttype) placeholder requires git 2.51.0+, so not using yet.\n `--format=${GIT_LSTREE_FORMAT}`,\n '--',\n ...(filterPath ?? [])\n ]),\n rootDirectory\n ).then(parseGitLsTree);\n const locallyModifiedPromise: Promise<Map<string, boolean>> = spawnGitAsync(\n gitPath,\n STANDARD_GIT_OPTIONS.concat([\n 'status',\n // Use NUL as the separator\n '-z',\n // Include untracked files\n '-u',\n // Disable rename detection so that renames show up as add + delete\n '--no-renames',\n // Don't process submodules with this command; they'll be handled individually\n '--ignore-submodules',\n // Don't compare against the remote\n '--no-ahead-behind',\n '--',\n ...(filterPath ?? [])\n ]),\n rootDirectory\n ).then(parseGitStatus);\n\n async function* getFilesToHash(): AsyncIterableIterator<string> {\n if (additionalRelativePathsToHash) {\n for (const file of additionalRelativePathsToHash) {\n yield file;\n }\n }\n\n const [{ files, symlinks }, locallyModified] = await Promise.all([statePromise, locallyModifiedPromise]);\n\n for (const [filePath, exists] of locallyModified) {\n if (exists && !symlinks.has(filePath)) {\n yield filePath;\n } else {\n files.delete(filePath);\n symlinks.delete(filePath);\n }\n }\n }\n\n const hashObjectPromise: Promise<Iterable<[string, string]>> = hashFilesAsync(\n rootDirectory,\n getFilesToHash(),\n gitPath\n );\n\n const [{ files, symlinks, submodules }, locallyModifiedFiles] = await Promise.all([\n statePromise,\n locallyModifiedPromise\n ]);\n\n // The result of \"git hash-object\" will be a list of file hashes delimited by newlines\n for (const [filePath, hash] of await hashObjectPromise) {\n files.set(filePath, hash);\n }\n\n // Existence check for the .gitmodules file\n const hasSubmodules: boolean = submodules.size > 0 && FileSystem.exists(`${rootDirectory}/.gitmodules`);\n\n if (hasSubmodules) {\n // Submodules are not the normal critical path. Accept serial performance rather than investing in complexity.\n // Can revisit if submodules become more commonly used.\n for (const submodulePath of submodules.keys()) {\n const submoduleState: Map<string, string> = await getRepoStateAsync(\n `${rootDirectory}/${submodulePath}`,\n [],\n gitPath\n );\n for (const [filePath, hash] of submoduleState) {\n files.set(`${submodulePath}/${filePath}`, hash);\n }\n }\n }\n\n return {\n hasSubmodules,\n hasUncommittedChanges: locallyModifiedFiles.size > 0,\n files,\n symlinks\n };\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 STANDARD_GIT_OPTIONS.concat([\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(\n gitPath || 'git',\n STANDARD_GIT_OPTIONS.concat(['version'])\n );\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"]}
|