puppetlabs / r10k

Smarter Puppet deployment
Other
802 stars 355 forks source link

shellgit: Ensure the passed filepath to diff-index is interpreted as filepath #1367

Closed bastelfreak closed 7 months ago

bastelfreak commented 7 months ago

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
justinstoller commented 7 months ago

@bastelfreak , do you want us to do a 4.0.1 release with this change or do you want to wait a bit to see what else comes up?

bastelfreak commented 7 months ago

@justinstoller Please make a 4.0.1 release (and if that could be vendored in PE 2023 that would be awesome).