updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-receive-pack.xml
blobb9728f199234d065ad14ab5374be278be91d2294
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <article lang="en" id="git-receive-pack(1)">\r
5 <articleinfo>\r
6     <title>git-receive-pack(1)</title>\r
7 <indexterm>\r
8 <primary>git-receive-pack(1)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-receive-pack - Receive what is pushed into the repository</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git-receive-pack</emphasis> &lt;directory&gt;</literallayout>\r
19 </blockquote>\r
20 </simplesect>\r
21 <simplesect id="_description">\r
22 <title>DESCRIPTION</title>\r
23 <simpara>Invoked by <emphasis>git send-pack</emphasis> and updates the repository with the\r
24 information fed from the remote end.</simpara>\r
25 <simpara>This command is usually not invoked directly by the end user.\r
26 The UI for the protocol is on the <emphasis>git send-pack</emphasis> side, and the\r
27 program pair is meant to be used to push updates to remote\r
28 repository.  For pull operations, see <xref linkend="git-fetch-pack(1)" />.</simpara>\r
29 <simpara>The command allows for creation and fast-forwarding of sha1 refs\r
30 (heads/tags) on the remote end (strictly speaking, it is the\r
31 local end <emphasis>git-receive-pack</emphasis> runs, but to the user who is sitting at\r
32 the send-pack end, it is updating the remote.  Confused?)</simpara>\r
33 <simpara>There are other real-world examples of using update and\r
34 post-update hooks found in the Documentation/howto directory.</simpara>\r
35 <simpara><emphasis>git-receive-pack</emphasis> honours the receive.denyNonFastForwards config\r
36 option, which tells it if updates to a ref should be denied if they\r
37 are not fast-forwards.</simpara>\r
38 </simplesect>\r
39 <simplesect id="_options">\r
40 <title>OPTIONS</title>\r
41 <variablelist>\r
42 <varlistentry>\r
43 <term>\r
44 &lt;directory&gt;\r
45 </term>\r
46 <listitem>\r
47 <simpara>\r
48         The repository to sync into.\r
49 </simpara>\r
50 </listitem>\r
51 </varlistentry>\r
52 </variablelist>\r
53 </simplesect>\r
54 <simplesect id="_pre_receive_hook">\r
55 <title>pre-receive Hook</title>\r
56 <simpara>Before any ref is updated, if $GIT_DIR/hooks/pre-receive file exists\r
57 and is executable, it will be invoked once with no parameters.  The\r
58 standard input of the hook will be one line per ref to be updated:</simpara>\r
59 <literallayout class="monospaced">sha1-old SP sha1-new SP refname LF</literallayout>\r
60 <simpara>The refname value is relative to $GIT_DIR; e.g. for the master\r
61 head this is "refs/heads/master".  The two sha1 values before\r
62 each refname are the object names for the refname before and after\r
63 the update.  Refs to be created will have sha1-old equal to 0{40},\r
64 while refs to be deleted will have sha1-new equal to 0{40}, otherwise\r
65 sha1-old and sha1-new should be valid objects in the repository.</simpara>\r
66 <simpara>This hook is called before any refname is updated and before any\r
67 fast-forward checks are performed.</simpara>\r
68 <simpara>If the pre-receive hook exits with a non-zero exit status no updates\r
69 will be performed, and the update, post-receive and post-update\r
70 hooks will not be invoked either.  This can be useful to quickly\r
71 bail out if the update is not to be supported.</simpara>\r
72 </simplesect>\r
73 <simplesect id="_update_hook">\r
74 <title>update Hook</title>\r
75 <simpara>Before each ref is updated, if $GIT_DIR/hooks/update file exists\r
76 and is executable, it is invoked once per ref, with three parameters:</simpara>\r
77 <literallayout class="monospaced">$GIT_DIR/hooks/update refname sha1-old sha1-new</literallayout>\r
78 <simpara>The refname parameter is relative to $GIT_DIR; e.g. for the master\r
79 head this is "refs/heads/master".  The two sha1 arguments are\r
80 the object names for the refname before and after the update.\r
81 Note that the hook is called before the refname is updated,\r
82 so either sha1-old is 0{40} (meaning there is no such ref yet),\r
83 or it should match what is recorded in refname.</simpara>\r
84 <simpara>The hook should exit with non-zero status if it wants to disallow\r
85 updating the named ref.  Otherwise it should exit with zero.</simpara>\r
86 <simpara>Successful execution (a zero exit status) of this hook does not\r
87 ensure the ref will actually be updated, it is only a prerequisite.\r
88 As such it is not a good idea to send notices (e.g. email) from\r
89 this hook.  Consider using the post-receive hook instead.</simpara>\r
90 </simplesect>\r
91 <simplesect id="_post_receive_hook">\r
92 <title>post-receive Hook</title>\r
93 <simpara>After all refs were updated (or attempted to be updated), if any\r
94 ref update was successful, and if $GIT_DIR/hooks/post-receive\r
95 file exists and is executable, it will be invoked once with no\r
96 parameters.  The standard input of the hook will be one line\r
97 for each successfully updated ref:</simpara>\r
98 <literallayout class="monospaced">sha1-old SP sha1-new SP refname LF</literallayout>\r
99 <simpara>The refname value is relative to $GIT_DIR; e.g. for the master\r
100 head this is "refs/heads/master".  The two sha1 values before\r
101 each refname are the object names for the refname before and after\r
102 the update.  Refs that were created will have sha1-old equal to\r
103 0{40}, while refs that were deleted will have sha1-new equal to\r
104 0{40}, otherwise sha1-old and sha1-new should be valid objects in\r
105 the repository.</simpara>\r
106 <simpara>Using this hook, it is easy to generate mails describing the updates\r
107 to the repository.  This example script sends one mail message per\r
108 ref listing the commits pushed to the repository:</simpara>\r
109 <literallayout class="monospaced">#!/bin/sh\r
110 # mail out commit update information.\r
111 while read oval nval ref\r
112 do\r
113         if expr "$oval" : '0*$' &gt;/dev/null\r
114         then\r
115                 echo "Created a new ref, with the following commits:"\r
116                 git rev-list --pretty "$nval"\r
117         else\r
118                 echo "New commits:"\r
119                 git rev-list --pretty "$nval" "^$oval"\r
120         fi |\r
121         mail -s "Changes to ref $ref" commit-list@mydomain\r
122 done\r
123 exit 0</literallayout>\r
124 <simpara>The exit code from this hook invocation is ignored, however a\r
125 non-zero exit code will generate an error message.</simpara>\r
126 <simpara>Note that it is possible for refname to not have sha1-new when this\r
127 hook runs.  This can easily occur if another user modifies the ref\r
128 after it was updated by <emphasis>git-receive-pack</emphasis>, but before the hook was able\r
129 to evaluate it.  It is recommended that hooks rely on sha1-new\r
130 rather than the current value of refname.</simpara>\r
131 </simplesect>\r
132 <simplesect id="_post_update_hook">\r
133 <title>post-update Hook</title>\r
134 <simpara>After all other processing, if at least one ref was updated, and\r
135 if $GIT_DIR/hooks/post-update file exists and is executable, then\r
136 post-update will be called with the list of refs that have been updated.\r
137 This can be used to implement any repository wide cleanup tasks.</simpara>\r
138 <simpara>The exit code from this hook invocation is ignored; the only thing\r
139 left for <emphasis>git-receive-pack</emphasis> to do at that point is to exit itself\r
140 anyway.</simpara>\r
141 <simpara>This hook can be used, for example, to run <emphasis>git update-server-info</emphasis>\r
142 if the repository is packed and is served via a dumb transport.</simpara>\r
143 <literallayout class="monospaced">#!/bin/sh\r
144 exec git update-server-info</literallayout>\r
145 </simplesect>\r
146 <simplesect id="_see_also">\r
147 <title>SEE ALSO</title>\r
148 <simpara><xref linkend="git-send-pack(1)" />, <xref linkend="gitnamespaces(7)" /></simpara>\r
149 </simplesect>\r
150 <simplesect id="_git">\r
151 <title>GIT</title>\r
152 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
153 </simplesect>\r
154 </article>\r