1

Is there a way to prevent running post-commit hook after cherry pick? I would like to run post commit hook specifically only after git commit. Or is there a way to figure out inside the hook that the commit has been cherry-picked? This is possible for example for rebase, but that's a different case.

Jaa-c
  • 5,017
  • 4
  • 34
  • 64

2 Answers2

1

For git cherry-pick the file seems to be CHERRY_PICK_HEAD. git uses it in the same sequencer used for cherry-pick/rebase/revert. git status uses it to report "cherry-pick is in progress".

phd
  • 82,685
  • 13
  • 120
  • 165
  • 1
    I tried your idea but it seems like the `CHERRY_PICK_HEAD` disapear before the commit, for examplewhile resolving some conflict, I can se the file, but when I run `git cherry-pick --continue` with the following `post-commit` checking for the file existance like this `[[ -f "$(git rev-parse --git-dir)/CHERRY_PICK_HEAD" ]] && echo "Cherry-Picking, Skip..." || "Post committing"`, I still get "Post committing". – lee-pai-long Nov 26 '19 at 22:36
  • I see the same behavior, `CHERRY_PICK_HEAD` doesn't exist any more when hook is run. – Jaa-c Nov 27 '19 at 09:10
0

I've finally solved this inside the hook itself. I check the output of git reflog -n 1, which is something like e06ca29a23 HEAD@{0}: cherry-pick: commit message. It's not bulletproof, if you ammend the commit during cherry-pick, there is a new entry in reflog for the ammend, but apart from that, it seems to work.

Jaa-c
  • 5,017
  • 4
  • 34
  • 64