diff --git a/packages/nx/src/hasher/git-hasher.ts b/packages/nx/src/hasher/git-hasher.ts index e93ce44f15..0cd1146b21 100644 --- a/packages/nx/src/hasher/git-hasher.ts +++ b/packages/nx/src/hasher/git-hasher.ts @@ -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<{