blob: b1f7dc643a0e9b6b232e1c75b39d7f784ab21b4a [file] [log] [blame]
Junio C Hamano2a245012005-07-14 00:10:05 -07001git-receive-pack(1)
2===================
Junio C Hamano2a245012005-07-14 00:10:05 -07003
4NAME
5----
Junio C Hamanoc3f0baa2007-01-18 15:53:37 -08006git-receive-pack - Receive what is pushed into the repository
Junio C Hamano2a245012005-07-14 00:10:05 -07007
8
9SYNOPSIS
10--------
Martin von Zweigbergk7791a1d2011-07-01 22:38:26 -040011[verse]
Junio C Hamano5a277f32011-09-06 11:06:32 -070012'git-receive-pack' <directory>
Junio C Hamano2a245012005-07-14 00:10:05 -070013
14DESCRIPTION
15-----------
Thomas Rast0b444cd2010-01-10 00:33:00 +010016Invoked by 'git send-pack' and updates the repository with the
Junio C Hamano2a245012005-07-14 00:10:05 -070017information fed from the remote end.
18
19This command is usually not invoked directly by the end user.
Thomas Rast0b444cd2010-01-10 00:33:00 +010020The UI for the protocol is on the 'git send-pack' side, and the
Junio C Hamano2a245012005-07-14 00:10:05 -070021program pair is meant to be used to push updates to remote
Jonathan Nieder483bc4f2008-06-30 13:56:34 -050022repository. For pull operations, see linkgit:git-fetch-pack[1].
Junio C Hamano2a245012005-07-14 00:10:05 -070023
Felipe Contrerasa75d7b52009-10-24 11:31:32 +030024The command allows for creation and fast-forwarding of sha1 refs
Josef Weidendorferb1bf95b2005-07-31 21:17:43 +020025(heads/tags) on the remote end (strictly speaking, it is the
Jonathan Niederba020ef2008-07-03 00:41:41 -050026local end 'git-receive-pack' runs, but to the user who is sitting at
Josef Weidendorferb1bf95b2005-07-31 21:17:43 +020027the send-pack end, it is updating the remote. Confused?)
28
Junio C Hamanoeb0362a2005-12-05 00:32:01 -080029There are other real-world examples of using update and
30post-update hooks found in the Documentation/howto directory.
31
Jonathan Niederba020ef2008-07-03 00:41:41 -050032'git-receive-pack' honours the receive.denyNonFastForwards config
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050033option, which tells it if updates to a ref should be denied if they
34are not fast-forwards.
Junio C Hamanoeb0362a2005-12-05 00:32:01 -080035
Junio C Hamano2a245012005-07-14 00:10:05 -070036OPTIONS
37-------
38<directory>::
39 The repository to sync into.
40
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050041pre-receive Hook
42----------------
43Before any ref is updated, if $GIT_DIR/hooks/pre-receive file exists
Shawn O. Pearcef43cd492007-03-10 03:28:16 -050044and is executable, it will be invoked once with no parameters. The
45standard input of the hook will be one line per ref to be updated:
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050046
Shawn O. Pearcef43cd492007-03-10 03:28:16 -050047 sha1-old SP sha1-new SP refname LF
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050048
Shawn O. Pearcef43cd492007-03-10 03:28:16 -050049The refname value is relative to $GIT_DIR; e.g. for the master
50head this is "refs/heads/master". The two sha1 values before
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050051each refname are the object names for the refname before and after
Jeff King967506b2007-07-02 01:24:59 -040052the update. Refs to be created will have sha1-old equal to 0\{40},
53while refs to be deleted will have sha1-new equal to 0\{40}, otherwise
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050054sha1-old and sha1-new should be valid objects in the repository.
55
56This hook is called before any refname is updated and before any
57fast-forward checks are performed.
58
59If the pre-receive hook exits with a non-zero exit status no updates
60will be performed, and the update, post-receive and post-update
61hooks will not be invoked either. This can be useful to quickly
62bail out if the update is not to be supported.
63
64update Hook
65-----------
66Before each ref is updated, if $GIT_DIR/hooks/update file exists
67and is executable, it is invoked once per ref, with three parameters:
68
69 $GIT_DIR/hooks/update refname sha1-old sha1-new
70
71The refname parameter is relative to $GIT_DIR; e.g. for the master
72head this is "refs/heads/master". The two sha1 arguments are
73the object names for the refname before and after the update.
74Note that the hook is called before the refname is updated,
Jeff King967506b2007-07-02 01:24:59 -040075so either sha1-old is 0\{40} (meaning there is no such ref yet),
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050076or it should match what is recorded in refname.
77
78The hook should exit with non-zero status if it wants to disallow
79updating the named ref. Otherwise it should exit with zero.
80
81Successful execution (a zero exit status) of this hook does not
Brian Hetro02783072007-08-23 20:44:13 -040082ensure the ref will actually be updated, it is only a prerequisite.
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050083As such it is not a good idea to send notices (e.g. email) from
84this hook. Consider using the post-receive hook instead.
85
86post-receive Hook
87-----------------
88After all refs were updated (or attempted to be updated), if any
89ref update was successful, and if $GIT_DIR/hooks/post-receive
Markus Heidelberg04c8ce92008-12-19 13:14:18 +010090file exists and is executable, it will be invoked once with no
Shawn O. Pearcef43cd492007-03-10 03:28:16 -050091parameters. The standard input of the hook will be one line
92for each successfully updated ref:
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050093
Shawn O. Pearcef43cd492007-03-10 03:28:16 -050094 sha1-old SP sha1-new SP refname LF
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050095
Shawn O. Pearcef43cd492007-03-10 03:28:16 -050096The refname value is relative to $GIT_DIR; e.g. for the master
97head this is "refs/heads/master". The two sha1 values before
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -050098each refname are the object names for the refname before and after
99the update. Refs that were created will have sha1-old equal to
Jeff King967506b2007-07-02 01:24:59 -04001000\{40}, while refs that were deleted will have sha1-new equal to
1010\{40}, otherwise sha1-old and sha1-new should be valid objects in
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500102the repository.
103
104Using this hook, it is easy to generate mails describing the updates
105to the repository. This example script sends one mail message per
106ref listing the commits pushed to the repository:
107
108 #!/bin/sh
109 # mail out commit update information.
Shawn O. Pearcef43cd492007-03-10 03:28:16 -0500110 while read oval nval ref
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500111 do
Shawn O. Pearcef43cd492007-03-10 03:28:16 -0500112 if expr "$oval" : '0*$' >/dev/null
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500113 then
114 echo "Created a new ref, with the following commits:"
Jonathan Niederb1889c32008-06-30 01:09:04 -0500115 git rev-list --pretty "$nval"
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500116 else
117 echo "New commits:"
Jonathan Niederb1889c32008-06-30 01:09:04 -0500118 git rev-list --pretty "$nval" "^$oval"
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500119 fi |
Shawn O. Pearcef43cd492007-03-10 03:28:16 -0500120 mail -s "Changes to ref $ref" commit-list@mydomain
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500121 done
122 exit 0
123
124The exit code from this hook invocation is ignored, however a
125non-zero exit code will generate an error message.
126
127Note that it is possible for refname to not have sha1-new when this
128hook runs. This can easily occur if another user modifies the ref
Jonathan Niederba020ef2008-07-03 00:41:41 -0500129after it was updated by 'git-receive-pack', but before the hook was able
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500130to evaluate it. It is recommended that hooks rely on sha1-new
131rather than the current value of refname.
132
133post-update Hook
134----------------
135After all other processing, if at least one ref was updated, and
136if $GIT_DIR/hooks/post-update file exists and is executable, then
Markus Heidelberg04c8ce92008-12-19 13:14:18 +0100137post-update will be called with the list of refs that have been updated.
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500138This can be used to implement any repository wide cleanup tasks.
139
140The exit code from this hook invocation is ignored; the only thing
Jonathan Niederba020ef2008-07-03 00:41:41 -0500141left for 'git-receive-pack' to do at that point is to exit itself
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500142anyway.
143
Jonathan Nieder483bc4f2008-06-30 13:56:34 -0500144This hook can be used, for example, to run `git update-server-info`
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500145if the repository is packed and is served via a dumb transport.
146
147 #!/bin/sh
Jonathan Niederb1889c32008-06-30 01:09:04 -0500148 exec git update-server-info
Shawn O. Pearce05ef58e2007-03-07 16:52:05 -0500149
Junio C Hamano6d35cc72005-09-02 21:19:26 -0700150
151SEE ALSO
152--------
Josh Triplettd49483f2011-07-08 16:14:10 -0700153linkgit:git-send-pack[1], linkgit:gitnamespaces[7]
Junio C Hamano6d35cc72005-09-02 21:19:26 -0700154
Junio C Hamano2a245012005-07-14 00:10:05 -0700155GIT
156---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200157Part of the linkgit:git[1] suite