Skip to content

Commit

Permalink
scripts: do not get confused with HEAD in work tree
Browse files Browse the repository at this point in the history
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 <gitster@pobox.com>
  • Loading branch information
gitster committed Nov 29, 2007
1 parent 1e72a40 commit 38762c4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions git-am.sh
Expand Up @@ -214,7 +214,7 @@ fi

case "$resolved" in
'')
files=$(git diff-index --cached --name-only HEAD) || exit
files=$(git diff-index --cached --name-only HEAD --) || exit
if [ "$files" ]; then
echo "Dirty index: cannot apply patches (dirty: $files)" >&2
exit 1
Expand Down Expand Up @@ -348,7 +348,7 @@ do
case "$resolved$interactive" in
tt)
# This is used only for interactive view option.
git diff-index -p --cached HEAD >"$dotest/patch"
git diff-index -p --cached HEAD -- >"$dotest/patch"
;;
esac
esac
Expand Down Expand Up @@ -409,7 +409,7 @@ do
# trust what the user has in the index file and the
# working tree.
resolved=
git diff-index --quiet --cached HEAD && {
git diff-index --quiet --cached HEAD -- && {
echo "No changes - did you forget to use 'git add'?"
stop_here_user_resolve $this
}
Expand All @@ -431,7 +431,7 @@ do
then
# Applying the patch to an earlier tree and merging the
# result may have produced the same tree as ours.
git diff-index --quiet --cached HEAD && {
git diff-index --quiet --cached HEAD -- && {
echo No changes -- Patch already applied.
go_next
continue
Expand Down
2 changes: 1 addition & 1 deletion git-filter-branch.sh
Expand Up @@ -95,7 +95,7 @@ USAGE="[--env-filter <command>] [--tree-filter <command>] \
. git-sh-setup

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

tempdir=.git-rewrite
Expand Down
2 changes: 1 addition & 1 deletion git-merge-ours.sh
Expand Up @@ -9,6 +9,6 @@
# because the current index is what we will be committing as the
# merge result.

git diff-index --quiet --cached HEAD || exit 2
git diff-index --quiet --cached HEAD -- || exit 2

exit 0
4 changes: 2 additions & 2 deletions git-rebase--interactive.sh
Expand Up @@ -52,7 +52,7 @@ require_clean_work_tree () {
git rev-parse --verify HEAD > /dev/null &&
git update-index --refresh &&
git diff-files --quiet &&
git diff-index --cached --quiet HEAD ||
git diff-index --cached --quiet HEAD -- ||
die "Working tree is dirty"
}

Expand Down Expand Up @@ -331,7 +331,7 @@ do
git rev-parse --verify HEAD > /dev/null &&
git update-index --refresh &&
git diff-files --quiet &&
! git diff-index --cached --quiet HEAD &&
! git diff-index --cached --quiet HEAD -- &&
. "$DOTEST"/author-script &&
export GIT_AUTHOR_NAME GIT_AUTHOR_NAME GIT_AUTHOR_DATE &&
git commit -F "$DOTEST"/message -e
Expand Down
4 changes: 2 additions & 2 deletions git-rebase.sh
Expand Up @@ -60,7 +60,7 @@ continue_merge () {
fi

cmt=`cat "$dotest/current"`
if ! git diff-index --quiet HEAD
if ! git diff-index --quiet HEAD --
then
if ! git-commit -C "$cmt"
then
Expand Down Expand Up @@ -253,7 +253,7 @@ fi

# The tree must be really really clean.
git update-index --refresh || exit
diff=$(git diff-index --cached --name-status -r HEAD)
diff=$(git diff-index --cached --name-status -r HEAD --)
case "$diff" in
?*) echo "cannot rebase: your index is not up-to-date"
echo "$diff"
Expand Down
2 changes: 1 addition & 1 deletion git-stash.sh
Expand Up @@ -14,7 +14,7 @@ trap 'rm -f "$TMP-*"' 0
ref_stash=refs/stash

no_changes () {
git diff-index --quiet --cached HEAD &&
git diff-index --quiet --cached HEAD -- &&
git diff-files --quiet
}

Expand Down

0 comments on commit 38762c4

Please sign in to comment.