{"thread":{"id":"36026","subject":"[BUGLET] resuming git am when using applypatch-msg hook","startedAt":"2014-03-02T22:30:57Z","lastAt":"2014-03-02T22:30:57Z","messageCount":1,"participants":["Chris Packham"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"235812","messageId":"CAFOYHZDmhp9orTJPaPfeLDqNzWPuMuwKhujfRD7rET5_Akrh5A@mail.gmail.com","threadId":"36026","inReplyTo":null,"subject":"[BUGLET] resuming git am when using applypatch-msg hook","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2014-03-02T22:30:57Z","receivedAt":"2014-03-02T22:30:57Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"Hi,\n\nI don't know if this really counts as a bug but it is a little\nannoying from a user experience point of view.\n\nWe're using an applypatch-msg hook to check that certain things\n(reviewer, bug entry etc) are recorded correctly in commit messages.\nMy expectation is that if our applypatch-msg hook rejects a patch then\nwe should be able to invoke 'git am -i --continue' edit the message to\nfixup the content and resume applying. However it seems even though I\ncan invoke 'git am -i --continue' to edit the message, the actual\npatch contents are lost.\n\nI'm guessing the problem is that the applypatch-msg hook is invoked\nafter the message part is saved but before the patch part is saved.\nAlternatively the \"problem\" could be that I'm using a hook that is not\nintended for this purpose, however the man page does say\n\"[applypatch-msg] can also be used to refuse the commit after\ninspecting the message file\".\n\nBelow is an example of this (if anyone has an idea on how to automate\nthe 'git am -i' part I'll be able to turn this into a proper test).\n\nThanks,\nChris\n--\n\n  git --version\n    git version 1.9.0.rc3.21.g475c52b\n\n  mkdir test && cd test && git init\n\n  cat >.git/hooks/applypatch-msg <<EOF\n  #!/bin/sh\n  grep -q \"foo\" \"\\$1\" && echo \"Rejecting patch message\" && exit 1\n  EOF\n  chmod +x .git/hooks/applypatch-msg\n\n  echo \"hello world\" > a.txt && git add a.txt && git commit -m \"Initial commit\"\n\n  git checkout -b temp\n  echo \"Hello world!\"  > a.txt && git add a.txt && git commit -m \"foo:\nupdate text\"\n\n  git checkout master\n  git format-patch temp -1 --stdout | git am\n    Rejecting patch message\n\n  GIT_EDITOR=\"sed -i 's/foo: //'\" git am -i --continue\n    Commit Body is:\n    --------------------------\n    foo: update text\n    --------------------------\n    Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all e\n    Commit Body is:\n    --------------------------\n    update text\n    --------------------------\n    Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all y\n\n  git status\n    On branch master\n    You are in the middle of an am session.\n    The current patch is empty.\n      (use \"git am --skip\" to skip this patch)\n      (use \"git am --abort\" to restore the original branch)\n\n  stat -c\"%s\" .git/rebase-apply/patch\n    0\n"}]}