Documentation/remote-helpers: document common use-case for private ref
[git.git] / Documentation / gitremote-helpers.txt
blob9ae36da7aa418c24a96defc41a4c29afe57faf8e
1 gitremote-helpers(1)
2 ====================
4 NAME
5 ----
6 gitremote-helpers - Helper programs to interact with remote repositories
8 SYNOPSIS
9 --------
10 [verse]
11 'git remote-<transport>' <repository> [<URL>]
13 DESCRIPTION
14 -----------
16 Remote helper programs are normally not used directly by end users,
17 but they are invoked by Git when it needs to interact with remote
18 repositories Git does not support natively.  A given helper will
19 implement a subset of the capabilities documented here. When Git
20 needs to interact with a repository using a remote helper, it spawns
21 the helper as an independent process, sends commands to the helper's
22 standard input, and expects results from the helper's standard
23 output. Because a remote helper runs as an independent process from
24 Git, there is no need to re-link Git to add a new helper, nor any
25 need to link the helper with the implementation of Git.
27 Every helper must support the "capabilities" command, which Git
28 uses to determine what other commands the helper will accept.  Those
29 other commands can be used to discover and update remote refs,
30 transport objects between the object database and the remote repository,
31 and update the local object store.
33 Git comes with a "curl" family of remote helpers, that handle various
34 transport protocols, such as 'git-remote-http', 'git-remote-https',
35 'git-remote-ftp' and 'git-remote-ftps'. They implement the capabilities
36 'fetch', 'option', and 'push'.
38 INVOCATION
39 ----------
41 Remote helper programs are invoked with one or (optionally) two
42 arguments. The first argument specifies a remote repository as in Git;
43 it is either the name of a configured remote or a URL. The second
44 argument specifies a URL; it is usually of the form
45 '<transport>://<address>', but any arbitrary string is possible.
46 The 'GIT_DIR' environment variable is set up for the remote helper
47 and can be used to determine where to store additional data or from
48 which directory to invoke auxiliary Git commands.
50 When Git encounters a URL of the form '<transport>://<address>', where
51 '<transport>' is a protocol that it cannot handle natively, it
52 automatically invokes 'git remote-<transport>' with the full URL as
53 the second argument. If such a URL is encountered directly on the
54 command line, the first argument is the same as the second, and if it
55 is encountered in a configured remote, the first argument is the name
56 of that remote.
58 A URL of the form '<transport>::<address>' explicitly instructs Git to
59 invoke 'git remote-<transport>' with '<address>' as the second
60 argument. If such a URL is encountered directly on the command line,
61 the first argument is '<address>', and if it is encountered in a
62 configured remote, the first argument is the name of that remote.
64 Additionally, when a configured remote has 'remote.<name>.vcs' set to
65 '<transport>', Git explicitly invokes 'git remote-<transport>' with
66 '<name>' as the first argument. If set, the second argument is
67 'remote.<name>.url'; otherwise, the second argument is omitted.
69 INPUT FORMAT
70 ------------
72 Git sends the remote helper a list of commands on standard input, one
73 per line.  The first command is always the 'capabilities' command, in
74 response to which the remote helper must print a list of the
75 capabilities it supports (see below) followed by a blank line.  The
76 response to the capabilities command determines what commands Git uses
77 in the remainder of the command stream.
79 The command stream is terminated by a blank line.  In some cases
80 (indicated in the documentation of the relevant commands), this blank
81 line is followed by a payload in some other protocol (e.g., the pack
82 protocol), while in others it indicates the end of input.
84 Capabilities
85 ~~~~~~~~~~~~
87 Each remote helper is expected to support only a subset of commands.
88 The operations a helper supports are declared to Git in the response
89 to the `capabilities` command (see COMMANDS, below).
91 In the following, we list all defined capabilities and for
92 each we list which commands a helper with that capability
93 must provide.
95 Capabilities for Pushing
96 ^^^^^^^^^^^^^^^^^^^^^^^^
97 'connect'::
98         Can attempt to connect to 'git receive-pack' (for pushing),
99         'git upload-pack', etc for communication using
100         git's native packfile protocol. This
101         requires a bidirectional, full-duplex connection.
103 Supported commands: 'connect'.
105 'push'::
106         Can discover remote refs and push local commits and the
107         history leading up to them to new or existing remote refs.
109 Supported commands: 'list for-push', 'push'.
111 'export'::
112         Can discover remote refs and push specified objects from a
113         fast-import stream to remote refs.
115 Supported commands: 'list for-push', 'export'.
117 If a helper advertises 'connect', Git will use it if possible and
118 fall back to another capability if the helper requests so when
119 connecting (see the 'connect' command under COMMANDS).
120 When choosing between 'push' and 'export', Git prefers 'push'.
121 Other frontends may have some other order of preference.
124 Capabilities for Fetching
125 ^^^^^^^^^^^^^^^^^^^^^^^^^
126 'connect'::
127         Can try to connect to 'git upload-pack' (for fetching),
128         'git receive-pack', etc for communication using the
129         Git's native packfile protocol. This
130         requires a bidirectional, full-duplex connection.
132 Supported commands: 'connect'.
134 'fetch'::
135         Can discover remote refs and transfer objects reachable from
136         them to the local object store.
138 Supported commands: 'list', 'fetch'.
140 'import'::
141         Can discover remote refs and output objects reachable from
142         them as a stream in fast-import format.
144 Supported commands: 'list', 'import'.
146 If a helper advertises 'connect', Git will use it if possible and
147 fall back to another capability if the helper requests so when
148 connecting (see the 'connect' command under COMMANDS).
149 When choosing between 'fetch' and 'import', Git prefers 'fetch'.
150 Other frontends may have some other order of preference.
152 Miscellaneous capabilities
153 ^^^^^^^^^^^^^^^^^^^^^^^^^^
155 'option'::
156         For specifying settings like `verbosity` (how much output to
157         write to stderr) and `depth` (how much history is wanted in the
158         case of a shallow clone) that affect how other commands are
159         carried out.
161 'refspec' <refspec>::
162         For remote helpers that implement 'import' or 'export', this capability
163         allows the refs to be constrained to a private namespace, instead of
164         writing to refs/heads or refs/remotes directly.
165         It is recommended that all importers providing the 'import'
166         capability use this. It's mandatory for 'export'.
168 A helper advertising the capability
169 `refspec refs/heads/*:refs/svn/origin/branches/*`
170 is saying that, when it is asked to `import refs/heads/topic`, the
171 stream it outputs will update the `refs/svn/origin/branches/topic`
172 ref.
174 This capability can be advertised multiple times.  The first
175 applicable refspec takes precedence.  The left-hand of refspecs
176 advertised with this capability must cover all refs reported by
177 the list command.  If no 'refspec' capability is advertised,
178 there is an implied `refspec *:*`.
180 When writing remote-helpers for decentralized version control
181 systems, it is advised to keep a local copy of the repository to
182 interact with, and to let the private namespace refs point to this
183 local repository, while the refs/remotes namespace is used to track
184 the remote repository.
186 'bidi-import'::
187         This modifies the 'import' capability.
188         The fast-import commands 'cat-blob' and 'ls' can be used by remote-helpers
189         to retrieve information about blobs and trees that already exist in
190         fast-import's memory. This requires a channel from fast-import to the
191         remote-helper.
192         If it is advertised in addition to "import", Git establishes a pipe from
193         fast-import to the remote-helper's stdin.
194         It follows that Git and fast-import are both connected to the
195         remote-helper's stdin. Because Git can send multiple commands to
196         the remote-helper it is required that helpers that use 'bidi-import'
197         buffer all 'import' commands of a batch before sending data to fast-import.
198         This is to prevent mixing commands and fast-import responses on the
199         helper's stdin.
201 'export-marks' <file>::
202         This modifies the 'export' capability, instructing Git to dump the
203         internal marks table to <file> when complete. For details,
204         read up on '--export-marks=<file>' in linkgit:git-fast-export[1].
206 'import-marks' <file>::
207         This modifies the 'export' capability, instructing Git to load the
208         marks specified in <file> before processing any input. For details,
209         read up on '--import-marks=<file>' in linkgit:git-fast-export[1].
211 'signed-tags'::
212         This modifies the 'export' capability, instructing Git to pass
213         '--signed-tags=verbatim' to linkgit:git-fast-export[1].  In the
214         absence of this capability, Git will use '--signed-tags=warn-strip'.
218 COMMANDS
219 --------
221 Commands are given by the caller on the helper's standard input, one per line.
223 'capabilities'::
224         Lists the capabilities of the helper, one per line, ending
225         with a blank line. Each capability may be preceded with '*',
226         which marks them mandatory for Git versions using the remote
227         helper to understand. Any unknown mandatory capability is a
228         fatal error.
230 Support for this command is mandatory.
232 'list'::
233         Lists the refs, one per line, in the format "<value> <name>
234         [<attr> ...]". The value may be a hex sha1 hash, "@<dest>" for
235         a symref, or "?" to indicate that the helper could not get the
236         value of the ref. A space-separated list of attributes follows
237         the name; unrecognized attributes are ignored. The list ends
238         with a blank line.
240 See REF LIST ATTRIBUTES for a list of currently defined attributes.
242 Supported if the helper has the "fetch" or "import" capability.
244 'list for-push'::
245         Similar to 'list', except that it is used if and only if
246         the caller wants to the resulting ref list to prepare
247         push commands.
248         A helper supporting both push and fetch can use this
249         to distinguish for which operation the output of 'list'
250         is going to be used, possibly reducing the amount
251         of work that needs to be performed.
253 Supported if the helper has the "push" or "export" capability.
255 'option' <name> <value>::
256         Sets the transport helper option <name> to <value>.  Outputs a
257         single line containing one of 'ok' (option successfully set),
258         'unsupported' (option not recognized) or 'error <msg>'
259         (option <name> is supported but <value> is not valid
260         for it).  Options should be set before other commands,
261         and may influence the behavior of those commands.
263 See OPTIONS for a list of currently defined options.
265 Supported if the helper has the "option" capability.
267 'fetch' <sha1> <name>::
268         Fetches the given object, writing the necessary objects
269         to the database.  Fetch commands are sent in a batch, one
270         per line, terminated with a blank line.
271         Outputs a single blank line when all fetch commands in the
272         same batch are complete. Only objects which were reported
273         in the output of 'list' with a sha1 may be fetched this way.
275 Optionally may output a 'lock <file>' line indicating a file under
276 GIT_DIR/objects/pack which is keeping a pack until refs can be
277 suitably updated.
279 Supported if the helper has the "fetch" capability.
281 'push' +<src>:<dst>::
282         Pushes the given local <src> commit or branch to the
283         remote branch described by <dst>.  A batch sequence of
284         one or more 'push' commands is terminated with a blank line
285         (if there is only one reference to push, a single 'push' command
286         is followed by a blank line). For example, the following would
287         be two batches of 'push', the first asking the remote-helper
288         to push the local ref 'master' to the remote ref 'master' and
289         the local 'HEAD' to the remote 'branch', and the second
290         asking to push ref 'foo' to ref 'bar' (forced update requested
291         by the '+').
293 ------------
294 push refs/heads/master:refs/heads/master
295 push HEAD:refs/heads/branch
297 push +refs/heads/foo:refs/heads/bar
299 ------------
301 Zero or more protocol options may be entered after the last 'push'
302 command, before the batch's terminating blank line.
304 When the push is complete, outputs one or more 'ok <dst>' or
305 'error <dst> <why>?' lines to indicate success or failure of
306 each pushed ref.  The status report output is terminated by
307 a blank line.  The option field <why> may be quoted in a C
308 style string if it contains an LF.
310 Supported if the helper has the "push" capability.
312 'import' <name>::
313         Produces a fast-import stream which imports the current value
314         of the named ref. It may additionally import other refs as
315         needed to construct the history efficiently. The script writes
316         to a helper-specific private namespace. The value of the named
317         ref should be written to a location in this namespace derived
318         by applying the refspecs from the "refspec" capability to the
319         name of the ref.
321 Especially useful for interoperability with a foreign versioning
322 system.
324 Just like 'push', a batch sequence of one or more 'import' is
325 terminated with a blank line. For each batch of 'import', the remote
326 helper should produce a fast-import stream terminated by a 'done'
327 command.
329 Note that if the 'bidi-import' capability is used the complete batch
330 sequence has to be buffered before starting to send data to fast-import
331 to prevent mixing of commands and fast-import responses on the helper's
332 stdin.
334 Supported if the helper has the "import" capability.
336 'export'::
337         Instructs the remote helper that any subsequent input is
338         part of a fast-import stream (generated by 'git fast-export')
339         containing objects which should be pushed to the remote.
341 Especially useful for interoperability with a foreign versioning
342 system.
344 The 'export-marks' and 'import-marks' capabilities, if specified,
345 affect this command in so far as they are passed on to 'git
346 fast-export', which then will load/store a table of marks for
347 local objects. This can be used to implement for incremental
348 operations.
350 Supported if the helper has the "export" capability.
352 'connect' <service>::
353         Connects to given service. Standard input and standard output
354         of helper are connected to specified service (git prefix is
355         included in service name so e.g. fetching uses 'git-upload-pack'
356         as service) on remote side. Valid replies to this command are
357         empty line (connection established), 'fallback' (no smart
358         transport support, fall back to dumb transports) and just
359         exiting with error message printed (can't connect, don't
360         bother trying to fall back). After line feed terminating the
361         positive (empty) response, the output of service starts. After
362         the connection ends, the remote helper exits.
364 Supported if the helper has the "connect" capability.
366 If a fatal error occurs, the program writes the error message to
367 stderr and exits. The caller should expect that a suitable error
368 message has been printed if the child closes the connection without
369 completing a valid response for the current command.
371 Additional commands may be supported, as may be determined from
372 capabilities reported by the helper.
374 REF LIST ATTRIBUTES
375 -------------------
377 The 'list' command produces a list of refs in which each ref
378 may be followed by a list of attributes. The following ref list
379 attributes are defined.
381 'unchanged'::
382         This ref is unchanged since the last import or fetch, although
383         the helper cannot necessarily determine what value that produced.
385 OPTIONS
386 -------
388 The following options are defined and (under suitable circumstances)
389 set by Git if the remote helper has the 'option' capability.
391 'option verbosity' <n>::
392         Changes the verbosity of messages displayed by the helper.
393         A value of 0 for <n> means that processes operate
394         quietly, and the helper produces only error output.
395         1 is the default level of verbosity, and higher values
396         of <n> correspond to the number of -v flags passed on the
397         command line.
399 'option progress' \{'true'|'false'\}::
400         Enables (or disables) progress messages displayed by the
401         transport helper during a command.
403 'option depth' <depth>::
404         Deepens the history of a shallow repository.
406 'option followtags' \{'true'|'false'\}::
407         If enabled the helper should automatically fetch annotated
408         tag objects if the object the tag points at was transferred
409         during the fetch command.  If the tag is not fetched by
410         the helper a second fetch command will usually be sent to
411         ask for the tag specifically.  Some helpers may be able to
412         use this option to avoid a second network connection.
414 'option dry-run' \{'true'|'false'\}:
415         If true, pretend the operation completed successfully,
416         but don't actually change any repository data.  For most
417         helpers this only applies to the 'push', if supported.
419 'option servpath <c-style-quoted-path>'::
420         Sets service path (--upload-pack, --receive-pack etc.) for
421         next connect. Remote helper may support this option, but
422         must not rely on this option being set before
423         connect request occurs.
425 SEE ALSO
426 --------
427 linkgit:git-remote[1]
429 linkgit:git-remote-testgit[1]
433 Part of the linkgit:git[1] suite