Skip to content

Commit 38762c4

Browse files
committed
scripts: do not get confused with HEAD in work tree
When you have a file called HEAD in your work tree, many commands that our scripts feed "HEAD" to would complain about the rev vs path ambiguity. A solution is to form command line more carefully by appending -- to them, which makes it clear that we mean HEAD rev not HEAD file. This patch would apply to maint. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1e72a40 commit 38762c4

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

git-am.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fi
214214

215215
case "$resolved" in
216216
'')
217-
files=$(git diff-index --cached --name-only HEAD) || exit
217+
files=$(git diff-index --cached --name-only HEAD --) || exit
218218
if [ "$files" ]; then
219219
echo "Dirty index: cannot apply patches (dirty: $files)" >&2
220220
exit 1
@@ -348,7 +348,7 @@ do
348348
case "$resolved$interactive" in
349349
tt)
350350
# This is used only for interactive view option.
351-
git diff-index -p --cached HEAD >"$dotest/patch"
351+
git diff-index -p --cached HEAD -- >"$dotest/patch"
352352
;;
353353
esac
354354
esac
@@ -409,7 +409,7 @@ do
409409
# trust what the user has in the index file and the
410410
# working tree.
411411
resolved=
412-
git diff-index --quiet --cached HEAD && {
412+
git diff-index --quiet --cached HEAD -- && {
413413
echo "No changes - did you forget to use 'git add'?"
414414
stop_here_user_resolve $this
415415
}
@@ -431,7 +431,7 @@ do
431431
then
432432
# Applying the patch to an earlier tree and merging the
433433
# result may have produced the same tree as ours.
434-
git diff-index --quiet --cached HEAD && {
434+
git diff-index --quiet --cached HEAD -- && {
435435
echo No changes -- Patch already applied.
436436
go_next
437437
continue

git-filter-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ USAGE="[--env-filter <command>] [--tree-filter <command>] \
9595
. git-sh-setup
9696

9797
git diff-files --quiet &&
98-
git diff-index --cached --quiet HEAD ||
98+
git diff-index --cached --quiet HEAD -- ||
9999
die "Cannot rewrite branch(es) with a dirty working directory."
100100

101101
tempdir=.git-rewrite

git-merge-ours.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
# because the current index is what we will be committing as the
1010
# merge result.
1111

12-
git diff-index --quiet --cached HEAD || exit 2
12+
git diff-index --quiet --cached HEAD -- || exit 2
1313

1414
exit 0

git-rebase--interactive.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ require_clean_work_tree () {
5252
git rev-parse --verify HEAD > /dev/null &&
5353
git update-index --refresh &&
5454
git diff-files --quiet &&
55-
git diff-index --cached --quiet HEAD ||
55+
git diff-index --cached --quiet HEAD -- ||
5656
die "Working tree is dirty"
5757
}
5858

@@ -331,7 +331,7 @@ do
331331
git rev-parse --verify HEAD > /dev/null &&
332332
git update-index --refresh &&
333333
git diff-files --quiet &&
334-
! git diff-index --cached --quiet HEAD &&
334+
! git diff-index --cached --quiet HEAD -- &&
335335
. "$DOTEST"/author-script &&
336336
export GIT_AUTHOR_NAME GIT_AUTHOR_NAME GIT_AUTHOR_DATE &&
337337
git commit -F "$DOTEST"/message -e

git-rebase.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ continue_merge () {
6060
fi
6161

6262
cmt=`cat "$dotest/current"`
63-
if ! git diff-index --quiet HEAD
63+
if ! git diff-index --quiet HEAD --
6464
then
6565
if ! git-commit -C "$cmt"
6666
then
@@ -253,7 +253,7 @@ fi
253253

254254
# The tree must be really really clean.
255255
git update-index --refresh || exit
256-
diff=$(git diff-index --cached --name-status -r HEAD)
256+
diff=$(git diff-index --cached --name-status -r HEAD --)
257257
case "$diff" in
258258
?*) echo "cannot rebase: your index is not up-to-date"
259259
echo "$diff"

git-stash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trap 'rm -f "$TMP-*"' 0
1414
ref_stash=refs/stash
1515

1616
no_changes () {
17-
git diff-index --quiet --cached HEAD &&
17+
git diff-index --quiet --cached HEAD -- &&
1818
git diff-files --quiet
1919
}
2020

0 commit comments

Comments
 (0)