Search code examples
gitversion-controlgithookscollaboration

Setting up a hook for git add


As I am currently working on a rather large software development project (we are still in the planning phase) we have been thinking about a proper VCS. For some features we want to have for collaborating with the whole team it will be needed that we can execute a shell script whenever something is added to the staging area.

I have read through different websites and the Git Book as well as the man pages for Git, but could not find a solution.

There are all kinds of hooks; Pre-Commit, Prepare-commitmsg etc. but unfortunately there's nothing (AFAIK) that responds to changes in the staging area.

Thanks in advance for any help provided.

EDIT: From the comment I've got (and I've tried out) I now know that a git clean filter would be what I want to use. It lets me do the operations I want to perform and cancel the stage by supplying a non-zero return value. This doesn't really help, though, because I would need something that's interactive or at least that provides output to the user which seems impossible by using filters.


Solution

  • Use git filters as you already found out yourself.

    To output a message to the user you can redirect stdout to stderr like echo "message to user" >&2 in a shell script.