Skip to content

Commit bc9c219

Browse files
committed
Merge branch 'jx/proc-receive-hook' into pu
* jx/proc-receive-hook: doc: add documentation for the proc-receive hook t5412: test the proc-receive hook on HTTP protocol receive-pack: refactor report for proc-receive receive-pack: new config receive.procReceiveRefs refs.c: refactor to reuse ref_is_hidden() receive-pack: add new proc-receive hook transport: not report a non-head push as a branch
2 parents 49e19e1 + 34ed404 commit bc9c219

14 files changed

+2521
-66
lines changed

Documentation/config/receive.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ receive.hideRefs::
114114
An attempt to update or delete a hidden ref by `git push` is
115115
rejected.
116116

117+
receive.procReceiveRefs::
118+
This is a multi-valued variable that defines reference prefixes
119+
to match the commands in `receive-pack`. Commands matching the
120+
prefixes will be executed by an external hooks "proc-receive",
121+
instead of the internal `execute_commands` function. If this
122+
variable is not defined, the "proc-receive" hook will never be
123+
used, and all commands will be executed by the internal
124+
`execute_commands` function.
125+
126+
For example, if this variable is set to "refs/for/", pushing to
127+
reference such as "refs/for/master" will not create or update a
128+
reference named "refs/for/master", but may create or update a
129+
pull request directly by running an external hook.
130+
117131
receive.updateServerInfo::
118132
If set to true, git-receive-pack will run git-update-server-info
119133
after receiving data from git-push and updating refs.

Documentation/githooks.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,76 @@ The default 'update' hook, when enabled--and with
333333
`hooks.allowunannotated` config option unset or set to false--prevents
334334
unannotated tags to be pushed.
335335

336+
[[proc-receive]]
337+
proc-receive
338+
~~~~~~~~~~~~
339+
This hook is invoked by linkgit:git-receive-pack[1] when it reacts to
340+
special `git push` command. According to refnames of the commands which
341+
`git push` sends to 'git-receive-pack', the commands will be devided
342+
into two groups by matching what the `receive.procReceiveRefs`
343+
configuration variable defines. One group of the commands will execute
344+
the internal `execute_commands` function to update the corresponding
345+
refnames, and the other group of commands which have matching refnames
346+
will execute this 'proc-receive' hook to create pull requests, etc.
347+
If there is no `receive.procReceiveRefs` settings, this hook won't
348+
execute at all, and all commands are sent to the internal
349+
`execute_commands` function.
350+
351+
Its exit status only determines the success or failure of the group of
352+
commands with special refnames, unless atomic push is in use.
353+
354+
This hook executes once for the receive operation. It takes no
355+
arguments, but will talk a protocol in pkt-line format with the
356+
'receive-pack' for reading commands, push-options (optional), and
357+
sending result. In the following example, The letter "S" stands for
358+
"receive-pack" and letter "H" stands for the hook.
359+
360+
# Version and capabilities negotiation.
361+
S: PKT-LINE(version=1\0push-options atomic...)
362+
S: flush-pkt
363+
H: PKT-LINE(version=1\0push-options...)
364+
H: flush-pkt
365+
366+
# Send commands from server to the hook.
367+
S: PKT-LINE(old-oid new-oid ref)
368+
S: ... ...
369+
S: flush-pkt
370+
# Only if push-options have been negotiated.
371+
S: PKT-LINE(push-option)
372+
S: ... ...
373+
S: flush-pkt
374+
375+
# Receive result from the hook.
376+
# OK, run this command successfully.
377+
H: PKT-LINE(old-oid new-oid ref ok)
378+
# NO, I reject it.
379+
H: PKT-LINE(old-oid new-oid ref ng reason)
380+
# OK, but use an alternate reference.
381+
H: PKT-LINE(old-oid new-oid ref ok ref:alt-ref)
382+
# It will fallthrough to receive-pack to execute.
383+
H: PKT-LINE(old-oid new-oid ref ft)
384+
H: ... ...
385+
H: flush-pkt
386+
387+
The "proc-receive" hook may update one or more references, and will send
388+
its result one by one in pkt-line format. Each line of the result has
389+
four fields and one optional message field, like "<old-oid> <new-oid>
390+
<ref> <status> [<message>]".
391+
392+
The first three fields are the same as those of the commands for
393+
"receive-pack".
394+
395+
The forth field has a two-letter status code. Available status codes:
396+
397+
* ok: The command runs successfully. If the optional message has a
398+
prefix "ref:", the hook has created/updated an alternate reference
399+
instead.
400+
401+
* ng: Fail to run the command. Error message is given in the optional
402+
message field.
403+
404+
* ft: Will fallthrough to receive-pack to execute.
405+
336406
[[post-receive]]
337407
post-receive
338408
~~~~~~~~~~~~

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
722722
TEST_BUILTINS_OBJS += test-path-utils.o
723723
TEST_BUILTINS_OBJS += test-pkt-line.o
724724
TEST_BUILTINS_OBJS += test-prio-queue.o
725+
TEST_BUILTINS_OBJS += test-proc-receive.o
725726
TEST_BUILTINS_OBJS += test-progress.o
726727
TEST_BUILTINS_OBJS += test-reach.o
727728
TEST_BUILTINS_OBJS += test-read-cache.o

0 commit comments

Comments
 (0)