git credential fill: output the whole 'struct credential'

Instead of outputing only the username and password, print all the
attributes, even those that already appeared in the input.

This is closer to what the C API does, and allows one to take the exact
output of "git credential fill" as input to "git credential approve" or
"git credential reject".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Matthieu Moy 2012-06-24 13:40:00 +02:00 коммит произвёл Junio C Hamano
Родитель e30b2feb1b
Коммит 2d6dc182b8
6 изменённых файлов: 54 добавлений и 9 удалений

Просмотреть файл

@ -64,12 +64,20 @@ infomation it has):
2. Ask git-credential to give us a username and password for this 2. Ask git-credential to give us a username and password for this
description. This is done by running `git credential fill`, description. This is done by running `git credential fill`,
feeding the description from step (1) to its standard input. The feeding the description from step (1) to its standard input. The complete
credential will be produced on standard output, like: credential description (including the credential per se, i.e. the
login and password) will be produced on standard output, like:
protocol=https
host=example.com
username=bob username=bob
password=secr3t password=secr3t
+ +
In most cases, this means the attributes given in the input will be
repeated in the output, but git may also modify the credential
description, for example by removing the `path` attribute when the
protocol is HTTP(s) and `credential.useHttpPath` is false.
+
If the `git credential` knew about the password, this step may If the `git credential` knew about the password, this step may
not have involved the user actually typing this password (the not have involved the user actually typing this password (the
user may have typed a password to unlock the keychain instead, user may have typed a password to unlock the keychain instead,
@ -86,8 +94,8 @@ unlocked) before it returned `password=secr3t`.
was rejected during the operation, use the "reject" action so was rejected during the operation, use the "reject" action so
that `git credential` will ask for a new password in its next that `git credential` will ask for a new password in its next
invocation. In either case, `git credential` should be fed with invocation. In either case, `git credential` should be fed with
the credential description obtained from step (2) together with the credential description obtained from step (2) (which also
the ones already provided in step (1). contain the ones provided in step (1)).
[[IOFMT]] [[IOFMT]]
INPUT/OUTPUT FORMAT INPUT/OUTPUT FORMAT

Просмотреть файл

@ -19,10 +19,7 @@ int cmd_credential(int argc, const char **argv, const char *prefix)
if (!strcmp(op, "fill")) { if (!strcmp(op, "fill")) {
credential_fill(&c); credential_fill(&c);
if (c.username) credential_write(&c, stdout);
printf("username=%s\n", c.username);
if (c.password)
printf("password=%s\n", c.password);
} else if (!strcmp(op, "approve")) { } else if (!strcmp(op, "approve")) {
credential_approve(&c); credential_approve(&c);
} else if (!strcmp(op, "reject")) { } else if (!strcmp(op, "reject")) {

Просмотреть файл

@ -191,7 +191,7 @@ static void credential_write_item(FILE *fp, const char *key, const char *value)
fprintf(fp, "%s=%s\n", key, value); fprintf(fp, "%s=%s\n", key, value);
} }
static void credential_write(const struct credential *c, FILE *fp) void credential_write(const struct credential *c, FILE *fp)
{ {
credential_write_item(fp, "protocol", c->protocol); credential_write_item(fp, "protocol", c->protocol);
credential_write_item(fp, "host", c->host); credential_write_item(fp, "host", c->host);

Просмотреть файл

@ -26,6 +26,7 @@ void credential_approve(struct credential *);
void credential_reject(struct credential *); void credential_reject(struct credential *);
int credential_read(struct credential *, FILE *); int credential_read(struct credential *, FILE *);
void credential_write(const struct credential *, FILE *);
void credential_from_url(struct credential *, const char *url); void credential_from_url(struct credential *, const char *url);
int credential_match(const struct credential *have, int credential_match(const struct credential *have,
const struct credential *want); const struct credential *want);

Просмотреть файл

@ -62,6 +62,8 @@ helper_test() {
protocol=https protocol=https
host=example.com host=example.com
-- --
protocol=https
host=example.com
username=askpass-username username=askpass-username
password=askpass-password password=askpass-password
-- --
@ -84,6 +86,8 @@ helper_test() {
protocol=https protocol=https
host=example.com host=example.com
-- --
protocol=https
host=example.com
username=store-user username=store-user
password=store-pass password=store-pass
-- --
@ -95,6 +99,8 @@ helper_test() {
protocol=http protocol=http
host=example.com host=example.com
-- --
protocol=http
host=example.com
username=askpass-username username=askpass-username
password=askpass-password password=askpass-password
-- --
@ -108,6 +114,8 @@ helper_test() {
protocol=https protocol=https
host=other.tld host=other.tld
-- --
protocol=https
host=other.tld
username=askpass-username username=askpass-username
password=askpass-password password=askpass-password
-- --
@ -122,6 +130,8 @@ helper_test() {
host=example.com host=example.com
username=other username=other
-- --
protocol=https
host=example.com
username=other username=other
password=askpass-password password=askpass-password
-- --
@ -143,6 +153,9 @@ helper_test() {
host=path.tld host=path.tld
path=bar.git path=bar.git
-- --
protocol=http
host=path.tld
path=bar.git
username=askpass-username username=askpass-username
password=askpass-password password=askpass-password
-- --
@ -160,6 +173,8 @@ helper_test() {
protocol=https protocol=https
host=example.com host=example.com
-- --
protocol=https
host=example.com
username=askpass-username username=askpass-username
password=askpass-password password=askpass-password
-- --
@ -186,6 +201,8 @@ helper_test() {
host=example.com host=example.com
username=user1 username=user1
-- --
protocol=https
host=example.com
username=user1 username=user1
password=pass1 password=pass1
EOF EOF
@ -194,6 +211,8 @@ helper_test() {
host=example.com host=example.com
username=user2 username=user2
-- --
protocol=https
host=example.com
username=user2 username=user2
password=pass2 password=pass2
EOF EOF
@ -210,6 +229,8 @@ helper_test() {
host=example.com host=example.com
username=user1 username=user1
-- --
protocol=https
host=example.com
username=user1 username=user1
password=askpass-password password=askpass-password
-- --
@ -223,6 +244,8 @@ helper_test() {
host=example.com host=example.com
username=user2 username=user2
-- --
protocol=https
host=example.com
username=user2 username=user2
password=pass2 password=pass2
EOF EOF
@ -244,6 +267,8 @@ helper_test_timeout() {
protocol=https protocol=https
host=timeout.tld host=timeout.tld
-- --
protocol=https
host=timeout.tld
username=askpass-username username=askpass-username
password=askpass-password password=askpass-password
-- --

Просмотреть файл

@ -82,6 +82,9 @@ test_expect_success 'credential_fill passes along metadata' '
host=example.com host=example.com
path=foo.git path=foo.git
-- --
protocol=ftp
host=example.com
path=foo.git
username=one username=one
password=two password=two
-- --
@ -213,6 +216,8 @@ test_expect_success 'match configured credential' '
host=example.com host=example.com
path=repo.git path=repo.git
-- --
protocol=https
host=example.com
username=foo username=foo
password=bar password=bar
-- --
@ -225,6 +230,8 @@ test_expect_success 'do not match configured credential' '
protocol=https protocol=https
host=bar host=bar
-- --
protocol=https
host=bar
username=askpass-username username=askpass-username
password=askpass-password password=askpass-password
-- --
@ -239,6 +246,8 @@ test_expect_success 'pull username from config' '
protocol=https protocol=https
host=example.com host=example.com
-- --
protocol=https
host=example.com
username=foo username=foo
password=askpass-password password=askpass-password
-- --
@ -252,6 +261,8 @@ test_expect_success 'http paths can be part of context' '
host=example.com host=example.com
path=foo.git path=foo.git
-- --
protocol=https
host=example.com
username=foo username=foo
password=bar password=bar
-- --
@ -265,6 +276,9 @@ test_expect_success 'http paths can be part of context' '
host=example.com host=example.com
path=foo.git path=foo.git
-- --
protocol=https
host=example.com
path=foo.git
username=foo username=foo
password=bar password=bar
-- --