{"thread":{"id":"11053","subject":"[PATCH] scripts: do not get confused with HEAD in work tree","startedAt":"2007-11-29T00:15:04Z","lastAt":"2007-11-29T07:02:57Z","messageCount":2,"participants":["Junio C Hamano","Mike Hommey"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"61336","messageId":"7vbq9d29h3.fsf@gitster.siamese.dyndns.org","threadId":"11053","inReplyTo":null,"subject":"[PATCH] scripts: do not get confused with HEAD in work tree","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-29T00:15:04Z","receivedAt":"2007-11-29T00:15:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When you have a file called HEAD in your work tree, many commands that\nour scripts feed \"HEAD\" to would complain about the rev vs path\nambiguity.  A solution is to form command line more carefully by\nappending -- to them, which makes it clear that we mean HEAD rev not\nHEAD file.\n\nThis patch would apply to maint.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n git-am.sh                  |    8 ++++----\n git-filter-branch.sh       |    2 +-\n git-merge-ours.sh          |    2 +-\n git-rebase--interactive.sh |    4 ++--\n git-rebase.sh              |    4 ++--\n git-stash.sh               |    2 +-\n 6 files changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 32c46d7..5792631 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -214,7 +214,7 @@ fi\n \n case \"$resolved\" in\n '')\n-\tfiles=$(git diff-index --cached --name-only HEAD) || exit\n+\tfiles=$(git diff-index --cached --name-only HEAD --) || exit\n \tif [ \"$files\" ]; then\n \t   echo \"Dirty index: cannot apply patches (dirty: $files)\" >&2\n \t   exit 1\n@@ -348,7 +348,7 @@ do\n \t\tcase \"$resolved$interactive\" in\n \t\ttt)\n \t\t\t# This is used only for interactive view option.\n-\t\t\tgit diff-index -p --cached HEAD >\"$dotest/patch\"\n+\t\t\tgit diff-index -p --cached HEAD -- >\"$dotest/patch\"\n \t\t\t;;\n \t\tesac\n \tesac\n@@ -409,7 +409,7 @@ do\n \t\t# trust what the user has in the index file and the\n \t\t# working tree.\n \t\tresolved=\n-\t\tgit diff-index --quiet --cached HEAD && {\n+\t\tgit diff-index --quiet --cached HEAD -- && {\n \t\t\techo \"No changes - did you forget to use 'git add'?\"\n \t\t\tstop_here_user_resolve $this\n \t\t}\n@@ -431,7 +431,7 @@ do\n \t\tthen\n \t\t    # Applying the patch to an earlier tree and merging the\n \t\t    # result may have produced the same tree as ours.\n-\t\t    git diff-index --quiet --cached HEAD && {\n+\t\t    git diff-index --quiet --cached HEAD -- && {\n \t\t\techo No changes -- Patch already applied.\n \t\t\tgo_next\n \t\t\tcontinue\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex ffcc408..dbab1a9 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -95,7 +95,7 @@ USAGE=\"[--env-filter <command>] [--tree-filter <command>] \\\n . git-sh-setup\n \n git diff-files --quiet &&\n-\tgit diff-index --cached --quiet HEAD ||\n+\tgit diff-index --cached --quiet HEAD -- ||\n \tdie \"Cannot rewrite branch(es) with a dirty working directory.\"\n \n tempdir=.git-rewrite\ndiff --git a/git-merge-ours.sh b/git-merge-ours.sh\nindex c81a790..29dba4b 100755\n--- a/git-merge-ours.sh\n+++ b/git-merge-ours.sh\n@@ -9,6 +9,6 @@\n # because the current index is what we will be committing as the\n # merge result.\n \n-git diff-index --quiet --cached HEAD || exit 2\n+git diff-index --quiet --cached HEAD -- || exit 2\n \n exit 0\ndiff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh\nindex d65df2c..ff38a22 100755\n--- a/git-rebase--interactive.sh\n+++ b/git-rebase--interactive.sh\n@@ -52,7 +52,7 @@ require_clean_work_tree () {\n \tgit rev-parse --verify HEAD > /dev/null &&\n \tgit update-index --refresh &&\n \tgit diff-files --quiet &&\n-\tgit diff-index --cached --quiet HEAD ||\n+\tgit diff-index --cached --quiet HEAD -- ||\n \tdie \"Working tree is dirty\"\n }\n \n@@ -331,7 +331,7 @@ do\n \t\tgit rev-parse --verify HEAD > /dev/null &&\n \t\tgit update-index --refresh &&\n \t\tgit diff-files --quiet &&\n-\t\t! git diff-index --cached --quiet HEAD &&\n+\t\t! git diff-index --cached --quiet HEAD -- &&\n \t\t. \"$DOTEST\"/author-script &&\n \t\texport GIT_AUTHOR_NAME GIT_AUTHOR_NAME GIT_AUTHOR_DATE &&\n \t\tgit commit -F \"$DOTEST\"/message -e\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex b0c8ac1..c9b284c 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -60,7 +60,7 @@ continue_merge () {\n \tfi\n \n \tcmt=`cat \"$dotest/current\"`\n-\tif ! git diff-index --quiet HEAD\n+\tif ! git diff-index --quiet HEAD --\n \tthen\n \t\tif ! git-commit -C \"$cmt\"\n \t\tthen\n@@ -253,7 +253,7 @@ fi\n \n # The tree must be really really clean.\n git update-index --refresh || exit\n-diff=$(git diff-index --cached --name-status -r HEAD)\n+diff=$(git diff-index --cached --name-status -r HEAD --)\n case \"$diff\" in\n ?*)\techo \"cannot rebase: your index is not up-to-date\"\n \techo \"$diff\"\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 5bbda47..77c9421 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -14,7 +14,7 @@ trap 'rm -f \"$TMP-*\"' 0\n ref_stash=refs/stash\n \n no_changes () {\n-\tgit diff-index --quiet --cached HEAD &&\n+\tgit diff-index --quiet --cached HEAD -- &&\n \tgit diff-files --quiet\n }\n \n"},{"id":"61370","messageId":"20071129070257.GB5144@glandium.org","threadId":"11053","inReplyTo":"7vbq9d29h3.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] scripts: do not get confused with HEAD in work tree","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2007-11-29T07:02:57Z","receivedAt":"2007-11-29T07:02:57Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"On Wed, Nov 28, 2007 at 04:15:04PM -0800, Junio C Hamano wrote:\n> When you have a file called HEAD in your work tree, many commands that\n> our scripts feed \"HEAD\" to would complain about the rev vs path\n> ambiguity.  A solution is to form command line more carefully by\n> appending -- to them, which makes it clear that we mean HEAD rev not\n> HEAD file.\n\nShouldn't this be done for anything else, then ? You could have a file\nwith the same name as a branch and have some commands using branch names\nfail too.\n\nMike\n"}]}