{"thread":{"id":"23889","subject":"'git pull --dry-run' accepted, but moves HEAD and changes working tree","startedAt":"2010-05-24T13:58:23Z","lastAt":"2010-05-26T05:07:28Z","messageCount":3,"participants":["Jeff Epler","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"142203","messageId":"20100524135823.GC19861@unpythonic.net","threadId":"23889","inReplyTo":null,"subject":"'git pull --dry-run' accepted, but moves HEAD and changes working tree","fromName":"Jeff Epler","fromEmail":"jepler@unpythonic.net","sentAt":"2010-05-24T13:58:23Z","receivedAt":"2010-05-24T13:58:23Z","isPatch":false,"sender":{"key":"jepler@unpythonic.net","avatar":"https://avatars.githubusercontent.com/u/1517291?v=4"},"body":"I don't recall why I initially typed it, I was surprised to discover\nthat 'git pull --dry-run' moves HEAD and modifies the working tree.\n\nHere's an example:\n$ git reset --hard HEAD^  # so there's something on origin to merge\nHEAD is now at c26a08d fix clearing of mesa components\n$ git rev-parse HEAD; git pull --dry-run; git rev-parse HEAD\nc26a08d1535a02ec044efd0d1fa50205d2da03fa\nUpdating c26a08d..41c8ee3\nFast-forward\n docs/man/man9/hostmot2.9                |    7 +++++--\n src/hal/drivers/mesa-hostmot2/stepgen.c |    5 +++++\n 2 files changed, 10 insertions(+), 2 deletions(-)\n41c8ee3e19ffb13cc357375d87940cac4769e029\n$ git --version\ngit version 1.7.1\n\nOn IRC, jast points out that 'git pull --dry-run' is not explicitly\ndocumented, but unfortunately it is accepted and then does something\nthat is really counter to the user's expectations. (I assume it's\npassing --dry-run to fetch, which does accept it, but that doesn't\nensure that there's nothing at all to merge)\n\nMaybe 'git pull --dry-run' should just be forbidden, or maybe it could\ntell the user whether the result of the pull would be a merge, FF, or no\nchange.\n\nJeff\n"},{"id":"142235","messageId":"20100525060725.GA10898@coredump.intra.peff.net","threadId":"23889","inReplyTo":"20100524135823.GC19861@unpythonic.net","subject":"Re: 'git pull --dry-run' accepted, but moves HEAD and changes working tree","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-05-25T06:07:25Z","receivedAt":"2010-05-25T06:07:25Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, May 24, 2010 at 08:58:23AM -0500, Jeff Epler wrote:\n\n> I don't recall why I initially typed it, I was surprised to discover\n> that 'git pull --dry-run' moves HEAD and modifies the working tree.\n\nYeah, that's bad.\n\n> (I assume it's passing --dry-run to fetch, which does accept it, but\n> that doesn't ensure that there's nothing at all to merge)\n\nThat is exactly what is happening.\n\n> Maybe 'git pull --dry-run' should just be forbidden, or maybe it could\n> tell the user whether the result of the pull would be a merge, FF, or no\n> change.\n\nWe can't tell what would have happened, because the dry-run fetch\ndoesn't write anything into FETCH_HEAD (which is where we would look to\nsee what was merge-able or not). But we can at least stop at the fetch\ndry-run to prevent any further damage.\n\nI have no problem with simply reporting an error, but it is easy enough\nto also just have it stop after doing the fetch dry-run, as below.\n\n-- >8 --\nSubject: [PATCH] pull: do nothing on --dry-run\n\nPull was never meant to take --dry-run at all. However, it\npasses unknown arguments to git-fetch, which does do a\ndry-run. Unfortunately, pull then attempts to merge whatever\ncruft was in FETCH_HEAD (which the dry-run fetch will not\nhave written to).\n\nEven though we never advertise --dry-run as something that\nshould work, it is still worth being defensive because:\n\n  1. Other commands (including fetch) take --dry-run, so a\n     user might try it.\n\n  2. Rather than simply producing an error, it actually\n     changes the repository in totally unexpected ways.\n\nThis patch makes \"pull --dry-run\" equivalent to \"fetch\n--dry-run\".\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n git-pull.sh |    7 ++++++-\n 1 files changed, 6 insertions(+), 1 deletions(-)\n\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 1a4729f..a09a44e 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -43,6 +43,7 @@ merge_args=\n curr_branch=$(git symbolic-ref -q HEAD)\n curr_branch_short=\"${curr_branch#refs/heads/}\"\n rebase=$(git config --bool branch.$curr_branch_short.rebase)\n+dry_run=\n while :\n do\n \tcase \"$1\" in\n@@ -104,6 +105,9 @@ do\n \t--no-r|--no-re|--no-reb|--no-reba|--no-rebas|--no-rebase)\n \t\trebase=false\n \t\t;;\n+\t--d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run)\n+\t\tdry_run=--dry-run\n+\t\t;;\n \t-h|--h|--he|--hel|--help)\n \t\tusage\n \t\t;;\n@@ -216,7 +220,8 @@ test true = \"$rebase\" && {\n \tdone\n }\n orig_head=$(git rev-parse -q --verify HEAD)\n-git fetch $verbosity $progress --update-head-ok \"$@\" || exit 1\n+git fetch $verbosity $progress $dry_run --update-head-ok \"$@\" || exit 1\n+test -z \"$dry_run\" || exit 0\n \n curr_head=$(git rev-parse -q --verify HEAD)\n if test -n \"$orig_head\" && test \"$curr_head\" != \"$orig_head\"\n-- \n1.7.1.226.g770c5.dirty\n"},{"id":"142308","messageId":"7vd3wjqmi7.fsf@alter.siamese.dyndns.org","threadId":"23889","inReplyTo":"20100525060725.GA10898@coredump.intra.peff.net","subject":"Re: 'git pull --dry-run' accepted, but moves HEAD and changes working tree","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-26T05:07:28Z","receivedAt":"2010-05-26T05:07:28Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}