fix(nx): git-hasher should fetch files from git submodules (#11334)

* fix: git-hasher should fetch files from git submodules

* chore(repo): format

* fix(git-hasher): get untracked files by calling git submodule foreach

* fix(git-hasher): get untracked files in both parent repo and submodules

* chore(git-hasher): format focument

* fix(git-hasher): fix formatting

* fix(core): make git-hasher read all files from parent repo and nested submodules

* fix(core): call git submodule foreach for unstaged files

Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com>
This commit is contained in:
Rami Hanano 2022-09-30 00:18:30 +03:00 committed by GitHub
parent 20c3951b8d
commit 65e5e148db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,7 +105,7 @@ async function spawnProcess(
async function getStagedFiles(path: string) {
const { stdout: staged } = await spawnProcess(
'git',
['ls-files', '-s', '-z', '--exclude-standard', '.'],
['ls-files', '--recurse-submodules', '-s', '-z', '--exclude-standard', '.'],
path
);
const res = new Map();
@ -121,23 +121,52 @@ async function getStagedFiles(path: string) {
}
async function getUnstagedFiles(path: string) {
//this command will list all parent repo's modefied files
const { stdout: unstaged } = await spawnProcess(
'git',
['ls-files', '-m', '-z', '--exclude-standard', '.'],
path
);
//and this command will only list nested submodules modefied files
const { stdout: unstagedInSubModules } = await spawnProcess(
'git',
[
'submodule',
'foreach',
'--recursive',
'--quiet',
'git ls-files -m -z --exclude-standard .',
],
path
);
const lines = unstaged.split('\0').filter((f) => !!f);
return getGitHashForFiles(lines, path);
const additionalLines = unstagedInSubModules.split('\0').filter((f) => !!f);
return getGitHashForFiles([...lines, ...additionalLines], path);
}
async function getUntrackedFiles(path: string) {
//this command will list all parent repo's untracked files
const { stdout: untracked } = await spawnProcess(
'git',
['ls-files', '--other', '-z', '--exclude-standard', '.'],
path
);
//and this command will only list nested submodules untracked files
const { stdout: untrackedInSubModules } = await spawnProcess(
'git',
[
'submodule',
'foreach',
'--recursive',
'--quiet',
'git ls-files --other -z --exclude-standard .',
],
path
);
const lines = untracked.split('\0').filter((f) => !!f);
return getGitHashForFiles(lines, path);
const additionalLines = untrackedInSubModules.split('\0').filter((f) => !!f);
return getGitHashForFiles([...lines, ...additionalLines], path);
}
export async function getFileHashes(path: string): Promise<{