Skip to content

Commit aa28171

Browse files
committed
Merge branch 'cb/credential-doc-fixes'
Minor in-code comments and documentation updates around credential API. * cb/credential-doc-fixes: credential: document protocol updates credential: update gitcredentials documentation credential: correct order of parameters for credential_match credential: update description for credential_from_url_gently
2 parents 69ae8ff + 1aed817 commit aa28171

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

Documentation/git-credential.txt

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,20 @@ INPUT/OUTPUT FORMAT
103103
`git credential` reads and/or writes (depending on the action used)
104104
credential information in its standard input/output. This information
105105
can correspond either to keys for which `git credential` will obtain
106-
the login/password information (e.g. host, protocol, path), or to the
107-
actual credential data to be obtained (login/password).
106+
the login information (e.g. host, protocol, path), or to the actual
107+
credential data to be obtained (username/password).
108108

109109
The credential is split into a set of named attributes, with one
110-
attribute per line. Each attribute is
111-
specified by a key-value pair, separated by an `=` (equals) sign,
112-
followed by a newline. The key may contain any bytes except `=`,
113-
newline, or NUL. The value may contain any bytes except newline or NUL.
110+
attribute per line. Each attribute is specified by a key-value pair,
111+
separated by an `=` (equals) sign, followed by a newline.
112+
113+
The key may contain any bytes except `=`, newline, or NUL. The value may
114+
contain any bytes except newline or NUL.
115+
114116
In both cases, all bytes are treated as-is (i.e., there is no quoting,
115117
and one cannot transmit a value with newline or NUL in it). The list of
116118
attributes is terminated by a blank line or end-of-file.
119+
117120
Git understands the following attributes:
118121

119122
`protocol`::
@@ -123,7 +126,8 @@ Git understands the following attributes:
123126

124127
`host`::
125128

126-
The remote hostname for a network credential.
129+
The remote hostname for a network credential. This includes
130+
the port number if one was specified (e.g., "example.com:8088").
127131

128132
`path`::
129133

@@ -134,7 +138,7 @@ Git understands the following attributes:
134138
`username`::
135139

136140
The credential's username, if we already have one (e.g., from a
137-
URL, from the user, or from a previously run helper).
141+
URL, the configuration, the user, or from a previously run helper).
138142

139143
`password`::
140144

@@ -146,8 +150,12 @@ Git understands the following attributes:
146150
value is parsed as a URL and treated as if its constituent parts
147151
were read (e.g., `url=https://example.com` would behave as if
148152
`protocol=https` and `host=example.com` had been provided). This
149-
can help callers avoid parsing URLs themselves. Note that any
150-
components which are missing from the URL (e.g., there is no
151-
username in the example above) will be set to empty; if you want
152-
to provide a URL and override some attributes, provide the URL
153-
attribute first, followed by any overrides.
153+
can help callers avoid parsing URLs themselves.
154+
155+
Note that specifying a protocol is mandatory and if the URL
156+
doesn't specify a hostname (e.g., "cert:///path/to/file") the
157+
credential will contain a hostname attribute whose value is an
158+
empty string.
159+
160+
Components which are missing from the URL (e.g., there is no
161+
username in the example above) will be left unset.

Documentation/gitcredentials.txt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,26 @@ For a `get` operation, the helper should produce a list of attributes on
268268
stdout in the same format (see linkgit:git-credential[1] for common
269269
attributes). A helper is free to produce a subset, or even no values at
270270
all if it has nothing useful to provide. Any provided attributes will
271-
overwrite those already known about by Git. If a helper outputs a
272-
`quit` attribute with a value of `true` or `1`, no further helpers will
273-
be consulted, nor will the user be prompted (if no credential has been
274-
provided, the operation will then fail).
271+
overwrite those already known about by Git's credential subsystem.
272+
273+
While it is possible to override all attributes, well behaving helpers
274+
should refrain from doing so for any attribute other than username and
275+
password.
276+
277+
If a helper outputs a `quit` attribute with a value of `true` or `1`,
278+
no further helpers will be consulted, nor will the user be prompted
279+
(if no credential has been provided, the operation will then fail).
280+
281+
Similarly, no more helpers will be consulted once both username and
282+
password had been provided.
275283

276284
For a `store` or `erase` operation, the helper's output is ignored.
277-
If it fails to perform the requested operation, it may complain to
278-
stderr to inform the user. If it does not support the requested
279-
operation (e.g., a read-only store), it should silently ignore the
280-
request.
285+
286+
If a helper fails to perform the requested operation or needs to notify
287+
the user of a potential issue, it may write to stderr.
288+
289+
If it does not support the requested operation (e.g., a read-only store),
290+
it should silently ignore the request.
281291

282292
If a helper receives any other operation, it should silently ignore the
283293
request. This leaves room for future operations to be added (older

credential.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ void credential_write(const struct credential *, FILE *);
177177
* Parse a url into a credential struct, replacing any existing contents.
178178
*
179179
* If the url can't be parsed (e.g., a missing "proto://" component), the
180-
* resulting credential will be empty but we'll still return success from the
181-
* "gently" form.
180+
* resulting credential will be empty and the function will return an
181+
* error (even in the "gently" form).
182182
*
183183
* If we encounter a component which cannot be represented as a credential
184184
* value (e.g., because it contains a newline), the "gently" form will return
@@ -189,7 +189,7 @@ void credential_write(const struct credential *, FILE *);
189189
void credential_from_url(struct credential *, const char *url);
190190
int credential_from_url_gently(struct credential *, const char *url, int quiet);
191191

192-
int credential_match(const struct credential *have,
193-
const struct credential *want);
192+
int credential_match(const struct credential *want,
193+
const struct credential *have);
194194

195195
#endif /* CREDENTIAL_H */

0 commit comments

Comments
 (0)