Skip to content

Commit baab3f5

Browse files
committed
shellgit: Ensure the passed filepath to diff-index is interpreted as filepath
Simplified, the code in the past was like this (data/roles/pe_primary.yaml is a random test file): `git diff-index -p HEAD data/roles/pe_primary.yaml` Which results in the following error if the file is tracked in git but was deleted locally: ``` $ git status HEAD detached at 3140475 Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) deleted: data/roles/pe_primary.yaml Untracked files: (use "git add <file>..." to include in what will be committed) .r10k-deploy.json .resource_types/ modules/ no changes added to commit (use "git add" and/or "git commit -a") $ git diff-index -p HEAD data/roles/pe_primary.yaml fatal: ambiguous argument 'data/roles/pe_primary.yaml': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' $ echo $? 128 ``` With adding `--` to the command, we ensure it's interpreted as path. This changes the exit code to 0. ``` $ git status HEAD detached at 3140475 Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) deleted: data/roles/pe_primary.yaml Untracked files: (use "git add <file>..." to include in what will be committed) .r10k-deploy.json .resource_types/ modules/ no changes added to commit (use "git add" and/or "git commit -a") $ git diff-index -p HEAD -- data/roles/pe_primary.yaml diff --git a/data/roles/pe_primary.yaml b/data/roles/pe_primary.yaml deleted file mode 100644 index b827047..0000000 --- a/data/roles/pe_primary.yaml +++ /dev/null @@ -1,48 +0,0 @@ ---- -classes: - - profiles::nftables $ echo $? 0 ``` Why do we do this change? This ensures r10k can properly handle checkouts that were modified.
1 parent fc02338 commit baab3f5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/r10k/git/shellgit/working_repository.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def dirty?(exclude_spec=true)
101101
logger.debug(_("Found local modifications in %{file_path}" % {file_path: File.join(@path, file)}))
102102

103103
# Do this in a block so that the extra subprocess only gets invoked when needed.
104-
logger.debug1 { git(['diff-index', '-p', 'HEAD', file], :path => @path.to_s, :raise_on_fail => false).stdout }
104+
logger.debug1 { git(['diff-index', '-p', 'HEAD', '--', file], :path => @path.to_s, :raise_on_fail => false).stdout }
105105
end
106106

107107
return dirty_files.size > 0

0 commit comments

Comments
 (0)