Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Hook: Take action when a branch is advanced

Tags:

git

githooks

hook

I'm looking to build and publish a latex document every time I advance the tip of a specific branch.

I'm looking at what hook I should be putting my build script and which conditions I need to check for.

like image 909
Flame Avatar asked Nov 09 '09 22:11

Flame


People also ask

How do you enforce a pre-commit hook?

If you want enforcement, use an update hook in the central repo. If the hook is doing per-commit verification, you can still provide a pre-commit hook; developers will likely adopt it voluntarily, so that they can find out right away when they've done something wrong, rather than waiting until they try to push.

How do you ignore a pre-commit hook?

Use the --no-verify option to skip git commit hooks, e.g. git commit -m "commit message" --no-verify . When the --no-verify option is used, the pre-commit and commit-msg hooks are bypassed.

What is pre-commit hook in git?

The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code.


2 Answers

Probably a little late... but you can find out which branch was committed to by using

if [ `git rev-parse --abbrev-ref HEAD` = "master" ]; then
  ...
fi

in you script when you checked out the branch to commit in it.

like image 196
msmart Avatar answered Oct 03 '22 10:10

msmart


If changes are coming in via a push to a remote, then on the remote server you'll want to use the post-receive hook (though if you use pre-receive then you can reject the push if, say, latex fails).

If you're using your local repository you should use post-commit (or pre-commit if you want to be able to reject the commit).

The hooks are documented in the git hooks man page.

like image 20
Pat Notz Avatar answered Oct 03 '22 10:10

Pat Notz