Skip to content

Commit

Permalink
Protect get_author_ident_from_commit() from filenames in work tree
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Feb 13, 2008
1 parent 04b3305 commit 077b725
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion git-sh-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ get_author_ident_from_commit () {
}
'
encoding=$(git config i18n.commitencoding || echo UTF-8)
git show -s --pretty=raw --encoding="$encoding" "$1" |
git show -s --pretty=raw --encoding="$encoding" "$1" -- |
LANG=C LC_ALL=C sed -ne "$pick_author_script"
}

Expand Down
22 changes: 22 additions & 0 deletions t/t3404-rebase-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,26 @@ test_expect_success 'rebase a commit violating pre-commit' '
'

test_expect_success 'rebase with a file named HEAD in worktree' '
rm -fr .git/hooks &&
git reset --hard &&
git checkout -b branch3 A &&
(
GIT_AUTHOR_NAME="Squashed Away" &&
export GIT_AUTHOR_NAME &&
>HEAD &&
git add HEAD &&
git commit -m "Add head" &&
>BODY &&
git add BODY &&
git commit -m "Add body"
) &&
FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
test "$(git show -s --pretty=format:%an)" = "Squashed Away"
'

test_done

0 comments on commit 077b725

Please sign in to comment.