git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUGLET] resuming git am when using applypatch-msg hook

From
Chris Packham <judge.packham@gmail.com>
Date
Mar 2, 2014, 22:30 UTC
Message-ID
<CAFOYHZDmhp9orTJPaPfeLDqNzWPuMuwKhujfRD7rET5_Akrh5A@mail.gmail.com>
Hi,

I don't know if this really counts as a bug but it is a little annoying from a user experience point of view.

We're using an applypatch-msg hook to check that certain things (reviewer, bug entry etc) are recorded correctly in commit messages. My expectation is that if our applypatch-msg hook rejects a patch then we should be able to invoke 'git am -i --continue' edit the message to fixup the content and resume applying. However it seems even though I can invoke 'git am -i --continue' to edit the message, the actual patch contents are lost.

I'm guessing the problem is that the applypatch-msg hook is invoked after the message part is saved but before the patch part is saved. Alternatively the "problem" could be that I'm using a hook that is not intended for this purpose, however the man page does say "[applypatch-msg] can also be used to refuse the commit after inspecting the message file".

Below is an example of this (if anyone has an idea on how to automate the 'git am -i' part I'll be able to turn this into a proper test).

Thanks, Chris --

  git --version
    git version 1.9.0.rc3.21.g475c52b
  mkdir test && cd test && git init
  cat >.git/hooks/applypatch-msg <<EOF
  #!/bin/sh
  grep -q "foo" "\$1" && echo "Rejecting patch message" && exit 1
  EOF
  chmod +x .git/hooks/applypatch-msg
  echo "hello world" > a.txt && git add a.txt && git commit -m "Initial commit"
  git checkout -b temp
  echo "Hello world!"  > a.txt && git add a.txt && git commit -m "foo:
update text"
  git checkout master
  git format-patch temp -1 --stdout | git am
    Rejecting patch message
  GIT_EDITOR="sed -i 's/foo: //'" git am -i --continue
    Commit Body is:
    --------------------------
    foo: update text
    --------------------------
    Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all e
    Commit Body is:
    --------------------------
    update text
    --------------------------
    Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all y
  git status
    On branch master
    You are in the middle of an am session.
    The current patch is empty.
      (use "git am --skip" to skip this patch)
      (use "git am --abort" to restore the original branch)
  stat -c"%s" .git/rebase-apply/patch
    0
Message 1 of 1 in “[BUGLET] resuming git am when using applypatch-msg hook”
  1. Chris PackhamMar 2, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.