Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 27, 2023

Conversation

bastelfreak
Copy link
Contributor

@bastelfreak bastelfreak commented Nov 24, 2023

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

…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.
@justinstoller justinstoller merged commit c404955 into puppetlabs:main Nov 27, 2023
9 checks passed
@justinstoller
Copy link
Member

@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 bastelfreak deleted the foo branch November 27, 2023 21:00
@bastelfreak
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants