Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git post commit: skip --amend and rebase

I have a post-commit hook that does stuff in ruby. It works very well but in some cases I would like to skip the code execution when I do a git rebase or git commit --amend.

Does someone have an idea how I could not trigger the post-commit hook in these cases or any work around?

like image 617
Gregory Avatar asked Jul 06 '12 18:07

Gregory


2 Answers

When rebasing, there's a directory called rebase-merge present in the .git folder. That could be an approach to disable the hook during a rebase (the start of a rebase btw is indicated by the pre-rebase hook).

Regarding the --amend however, I can't help you.

like image 86
eckes Avatar answered Oct 06 '22 10:10

eckes


If you want to detect git commit --amend from a hook, this is your best option

bash

if [[ $(ps -ocommand= -p $PPID) == "git commit --amend" ]]; then
    echo "always allow git commit --amend"
    exit 0
fi

ruby

parent=`ps -ocommand= -p #{Process.ppid}`.chomp
if parent == "git commit --amend"
  # Always allow an amend
  puts "always allow git commit --amend"
  exit 0
end

git and shell aliases are expanded in the shell output, so this covers those cases too

Inspiration: https://github.com/brigade/overcommit/issues/146

like image 37
Marchy Avatar answered Oct 06 '22 10:10

Marchy