@@ -118,15 +118,37 @@ export async function getUncommittedHash(deps: Pick<Deps, 'log'>) {
118118 const listStagedFiles = 'git diff --name-only --no-relative --diff-filter=d --cached' ;
119119 const listUnstagedFiles = 'git diff --name-only --no-relative --diff-filter=d' ;
120120 const listUntrackedFiles = 'git ls-files --others --exclude-standard' ;
121- const listUncommittedFiles = [ listStagedFiles , listUnstagedFiles , listUntrackedFiles ] . join ( ';' ) ;
122121
123- const uncommittedHashWithPadding = await execGitCommand (
124- deps ,
125- // Pass the combined list of filenames to hash-object to retrieve a list of hashes. Then pass
126- // the list of hashes to hash-object again to retrieve a single hash of all hashes. We use
127- // stdin to avoid the limit on command line arguments.
128- `(${ listUncommittedFiles } ) | git hash-object --stdin-paths | git hash-object --stdin`
129- ) ;
122+ // Use `all: false` so only stdout is captured and we can ignore stderr output that doesn't impact
123+ // the result.
124+ const stdoutOnly = { all : false } ;
125+ const [ stagedOutput , unstagedOutput , untrackedOutput ] = await Promise . all ( [
126+ execGitCommand ( deps , listStagedFiles , stdoutOnly ) ,
127+ execGitCommand ( deps , listUnstagedFiles , stdoutOnly ) ,
128+ execGitCommand ( deps , listUntrackedFiles , stdoutOnly ) ,
129+ ] ) ;
130+
131+ // Combine file listings into one path per line, stripping empty lines (including trailing
132+ // newlines from each output).
133+ const files = [ stagedOutput , unstagedOutput , untrackedOutput ]
134+ . flatMap ( ( output ) => output ?. split ( newline ) ?? [ ] )
135+ . filter ( Boolean )
136+ . join ( '\n' ) ;
137+
138+ if ( ! files ) {
139+ return '' ;
140+ }
141+
142+ // Pass the combined list of filenames to hash-object to retrieve a list of hashes. Then pass
143+ // the list of hashes to hash-object again to retrieve a single hash of all hashes. We use
144+ // stdin to avoid the limit on command line arguments.
145+ const fileHashes = await execGitCommand ( deps , 'git hash-object --stdin-paths' , {
146+ input : files ,
147+ } ) ;
148+
149+ const uncommittedHashWithPadding = await execGitCommand ( deps , 'git hash-object --stdin' , {
150+ input : fileHashes ,
151+ } ) ;
130152 const uncommittedHash = uncommittedHashWithPadding ?. trim ( ) ;
131153
132154 // In case there are no uncommited changes (empty list), we always get this same hash.
0 commit comments