Protect get_author_ident_from_commit() from filenames in work tree
We used to use "cat-file commit $commit" to extract the original author information from existing commit, but an earlier commit 5ac2715 (Consistent message encoding while reusing log from an existing commit) changed it to use "git show -s $commit". If you have a file in your work tree that can be interpreted as a valid object name (e.g. "HEAD"), this conversion will not work. Disambiguate by marking the end of revision parameter on the comand line with an explicit "--" to fix this. This breakage is most visible with rebase when a file called "HEAD" exists in the worktree. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Feb 13, 2008 at 13:13 UTC
077b725f0bbe2b6ca2deb569c22a6f0d7a374dd3
2 files changed
+23
-1
git-sh-setup.sh
+1
-1
@@ -119,7 +119,7 @@ get_author_ident_from_commit () {
119
}
120
'
121
encoding=$(git config i18n.commitencoding || echo UTF-8)
122
- git show -s --pretty=raw --encoding="$encoding" "$1" |
122
+ git show -s --pretty=raw --encoding="$encoding" "$1" -- |
123
LANG=C LC_ALL=C sed -ne "$pick_author_script"
124
}
125
t/t3404-rebase-interactive.sh
+22
@@ -340,4 +340,26 @@ test_expect_success 'rebase a commit violating pre-commit' '
340
341
'
342
343
+test_expect_success 'rebase with a file named HEAD in worktree' '
344
+
345
+ rm -fr .git/hooks &&
346
+ git reset --hard &&
347
+ git checkout -b branch3 A &&
348
+
349
+ (
350
+ GIT_AUTHOR_NAME="Squashed Away" &&
351
+ export GIT_AUTHOR_NAME &&
352
+ >HEAD &&
353
+ git add HEAD &&
354
+ git commit -m "Add head" &&
355
+ >BODY &&
356
+ git add BODY &&
357
+ git commit -m "Add body"
358
+ ) &&
359
+
360
+ FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
361
+ test "$(git show -s --pretty=format:%an)" = "Squashed Away"
362
+
363
+'
364
+
365
test_done