0

While doing lots of branch-management via rebasing I have a number of common situations that cause merge conflicts to occur for which I have developed helper scripts that resolve the situation.

When it breaks I can essentially run:

checkpatch.sh && git rebase --continue 

for most scenarios and continue.

Is there a hook to attach such that git could run checkpatch.sh automagically when it halts after a merge conflict?


(Minor clarification - when I say "hook" I mean in the general (emacs) sense of being able to attach my code to run, though obviously git-hooks would count. In this sense --exec in rebase would be a hook to run my code (just the hook I require))

5
  • Is your script idempotent? That is, would it be OK to run even if there is no conflict? stackoverflow.com/questions/62985544/… Commented Oct 23 at 23:34
  • 1
    It seems like there is no merge conflict hook according to the docs git-scm.com/book/ms/v2/Customizing-Git-Git-Hooks If I have understood your problem correctly, it might be that git rerere is what you're after git-scm.com/book/it/v2/Git-Tools-Rerere This will allow you to automatically resolve the same conflicting hunks. Commented Oct 24 at 6:08
  • @STerliakov - Thanks for your question - I believe that reference is only for running at the end of the rebase script. I could just use --exec to run it on every commit except that only happens after the conflict as been resolved on the previous pick step. Or have I misunderstood your suggestion? Commented Oct 24 at 22:42
  • @dani-vta - Thanks for your suggestion: rerere isn't what I need in this case, though if I could hook a conflict I could even automate some of the rerere incantations. Commented Oct 24 at 22:44
  • Yep, sorry, you can add exec lines after every commit during interactive rebase, but --exec would do the same. You're right, it only runs after successfully applying the commit. I have a weird idea but need to check it first Commented Oct 24 at 23:25

1 Answer 1

1

No, there isn't a built-in Git hook that triggers specifically when a rebase halts due to a conflict.

Git's post-rewrite hook, or similar ones, only run after a rebase or other history-rewriting command has fully completed successfully. When a rebase hits a conflict, it's actually paused, waiting for you to fix things. It hasn't finished its job yet, so no "post-operation" hook will run at that point.

Because of this, you generally have to handle running your checkpatch.sh script manually after a conflict, or by setting up a custom wrapper script around your git rebase command that can detect when a conflict occurs.

Sign up to request clarification or add additional context in comments.

1 Comment

You've helped clarify my thoughts. The wrapper script idea seems plausible, though potentially fragile, thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.