diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2007-03-07 16:52:05 -0500 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-03-07 15:03:33 -0800 |
commit | 05ef58ec1f2fb69d6e7ae7fca84163f75bd95050 (patch) | |
tree | 82e444216aef4ce945e8b5d6dac4b5adfedb4f39 /receive-pack.c | |
parent | 8aaf7d6410119ee221f5d3ebdc4fc5a57f862665 (diff) | |
download | git-05ef58ec1f2fb69d6e7ae7fca84163f75bd95050.tar.gz |
Teach receive-pack to run pre-receive/post-receive hooks
Bill Lear pointed out that it is easy to send out notifications of
changes with the update hook, but successful execution of the update
hook does not necessarily mean that the ref was actually updated.
Lock contention on the ref or being unable to append to the reflog
may prevent the ref from being changed. Sending out notifications
prior to the ref actually changing is very misleading.
To help this situation I am introducing two new hooks to the
receive-pack flow: pre-receive and post-receive. These new hooks
are invoked only once per receive-pack execution and are passed
three arguments per ref (refname, old-sha1, new-sha1).
The new post-receive hook is ideal for sending out notifications,
as it has the complete list of all refnames that were successfully
updated as well as the old and new SHA-1 values. This allows more
interesting notifications to be sent. Multiple ref updates could
be easily summarized into one email, for example.
The new pre-receive hook is ideal for logging update attempts, as it
is run only once for the entire receive-pack operation. It can also
be used to verify multiple updates happen at once, e.g. an update
to the `maint` head must also be accompained by a new annotated tag.
Lots of documentation improvements for receive-pack are included
in this change, as we want to make sure the new hooks are clearly
explained.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'receive-pack.c')
-rw-r--r-- | receive-pack.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/receive-pack.c b/receive-pack.c index ff746e7d56..675c88f492 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -68,6 +68,8 @@ struct command { static struct command *commands; static const char update_hook[] = "hooks/update"; +static const char pre_receive_hook[] = "hooks/pre-receive"; +static const char post_receive_hook[] = "hooks/post-receive"; static int run_hook(const char *hook_name, struct command *first_cmd, @@ -236,6 +238,14 @@ static void execute_commands(const char *unpacker_error) return; } + if (run_hook(pre_receive_hook, commands, 0)) { + while (cmd) { + cmd->error_string = "pre-receive hook declined"; + cmd = cmd->next; + } + return; + } + while (cmd) { cmd->error_string = update(cmd); cmd = cmd->next; @@ -483,6 +493,7 @@ int main(int argc, char **argv) unlink(pack_lockfile); if (report_status) report(unpack_status); + run_hook(post_receive_hook, commands, 0); run_update_post_hook(commands); } return 0; |