From: Matthieu Moy <Matthieu.Moy@imag.fr>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Javier.Roucher-Iglesias@ensimag.imag.fr,
Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: [PATCH 2/3] git credential fill: output the whole 'struct credential'
Date: Fri, 22 Jun 2012 18:07:10 +0200 [thread overview]
Message-ID: <1340381231-9522-3-git-send-email-Matthieu.Moy@imag.fr> (raw)
In-Reply-To: <1340381231-9522-1-git-send-email-Matthieu.Moy@imag.fr>
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".
---
Suggested by Jeff, and will be very nice to use from perl in the next
patch.
Documentation/git-credential.txt | 15 +++++++++++----
builtin/credential.c | 5 +----
credential.c | 2 +-
credential.h | 1 +
t/lib-credential.sh | 25 +++++++++++++++++++++++++
t/t0300-credentials.sh | 14 ++++++++++++++
6 files changed, 53 insertions(+), 9 deletions(-)
diff --git a/Documentation/git-credential.txt b/Documentation/git-credential.txt
index b64ac30..67737de 100644
--- a/Documentation/git-credential.txt
+++ b/Documentation/git-credential.txt
@@ -62,11 +62,18 @@ credential description (don't forget the blank line at the end):
2. Ask git-credential to give us a username and password for this
description. This is done by running `git credential fill`,
- feeding the description from step (1) to its stdin. The username
- and password will be produced on stdout, like:
+ feeding the description from step (1) to its stdin. The complete
+ credential description will be produced on stdout, like:
+ protocol=https
+ host=example.com
username=bob
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.
3. Try to use the credential (e.g., by accessing the URL with the
username and password from step (2)).
@@ -76,8 +83,8 @@ credential description (don't forget the blank line at the end):
it can be marked with an "approve" action. If the credential was
rejected during the operation, use the "reject" action. In either
case, `git credential` should be fed with the credential
- description obtained from step (2) together with the ones already
- provided in step (1).
+ description obtained from step (2) (which also contain the ones
+ provided in step (1)).
[[IOFMT]]
INPUT/OUTPUT FORMAT
diff --git a/builtin/credential.c b/builtin/credential.c
index 4147314..b956059 100644
--- a/builtin/credential.c
+++ b/builtin/credential.c
@@ -19,10 +19,7 @@ int cmd_credential (int argc, const char **argv, const char *prefix)
if (!strcmp(op, "fill")) {
credential_fill(&c);
- if (c.username)
- printf("username=%s\n", c.username);
- if (c.password)
- printf("password=%s\n", c.password);
+ credential_write(&c, stdout);
} else if (!strcmp(op, "approve")) {
credential_approve(&c);
} else if (!strcmp(op, "reject")) {
diff --git a/credential.c b/credential.c
index 62d1c56..2c40007 100644
--- a/credential.c
+++ b/credential.c
@@ -191,7 +191,7 @@ static void credential_write_item(FILE *fp, const char *key, const char *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, "host", c->host);
diff --git a/credential.h b/credential.h
index 96ea41b..0c3e85e 100644
--- a/credential.h
+++ b/credential.h
@@ -26,6 +26,7 @@ void credential_approve(struct credential *);
void credential_reject(struct credential *);
int credential_read(struct credential *, FILE *);
+void credential_write(const struct credential *, FILE *);
void credential_from_url(struct credential *, const char *url);
int credential_match(const struct credential *have,
const struct credential *want);
diff --git a/t/lib-credential.sh b/t/lib-credential.sh
index 7c4826e..957ae93 100755
--- a/t/lib-credential.sh
+++ b/t/lib-credential.sh
@@ -62,6 +62,8 @@ helper_test() {
protocol=https
host=example.com
--
+ protocol=https
+ host=example.com
username=askpass-username
password=askpass-password
--
@@ -84,6 +86,8 @@ helper_test() {
protocol=https
host=example.com
--
+ protocol=https
+ host=example.com
username=store-user
password=store-pass
--
@@ -95,6 +99,8 @@ helper_test() {
protocol=http
host=example.com
--
+ protocol=http
+ host=example.com
username=askpass-username
password=askpass-password
--
@@ -108,6 +114,8 @@ helper_test() {
protocol=https
host=other.tld
--
+ protocol=https
+ host=other.tld
username=askpass-username
password=askpass-password
--
@@ -122,6 +130,8 @@ helper_test() {
host=example.com
username=other
--
+ protocol=https
+ host=example.com
username=other
password=askpass-password
--
@@ -143,6 +153,9 @@ helper_test() {
host=path.tld
path=bar.git
--
+ protocol=http
+ host=path.tld
+ path=bar.git
username=askpass-username
password=askpass-password
--
@@ -160,6 +173,8 @@ helper_test() {
protocol=https
host=example.com
--
+ protocol=https
+ host=example.com
username=askpass-username
password=askpass-password
--
@@ -186,6 +201,8 @@ helper_test() {
host=example.com
username=user1
--
+ protocol=https
+ host=example.com
username=user1
password=pass1
EOF
@@ -194,6 +211,8 @@ helper_test() {
host=example.com
username=user2
--
+ protocol=https
+ host=example.com
username=user2
password=pass2
EOF
@@ -210,6 +229,8 @@ helper_test() {
host=example.com
username=user1
--
+ protocol=https
+ host=example.com
username=user1
password=askpass-password
--
@@ -223,6 +244,8 @@ helper_test() {
host=example.com
username=user2
--
+ protocol=https
+ host=example.com
username=user2
password=pass2
EOF
@@ -244,6 +267,8 @@ helper_test_timeout() {
protocol=https
host=timeout.tld
--
+ protocol=https
+ host=timeout.tld
username=askpass-username
password=askpass-password
--
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index 20e28e3..538ea5f 100755
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
@@ -82,6 +82,9 @@ test_expect_success 'credential_fill passes along metadata' '
host=example.com
path=foo.git
--
+ protocol=ftp
+ host=example.com
+ path=foo.git
username=one
password=two
--
@@ -213,6 +216,8 @@ test_expect_success 'match configured credential' '
host=example.com
path=repo.git
--
+ protocol=https
+ host=example.com
username=foo
password=bar
--
@@ -225,6 +230,8 @@ test_expect_success 'do not match configured credential' '
protocol=https
host=bar
--
+ protocol=https
+ host=bar
username=askpass-username
password=askpass-password
--
@@ -239,6 +246,8 @@ test_expect_success 'pull username from config' '
protocol=https
host=example.com
--
+ protocol=https
+ host=example.com
username=foo
password=askpass-password
--
@@ -252,6 +261,8 @@ test_expect_success 'http paths can be part of context' '
host=example.com
path=foo.git
--
+ protocol=https
+ host=example.com
username=foo
password=bar
--
@@ -265,6 +276,9 @@ test_expect_success 'http paths can be part of context' '
host=example.com
path=foo.git
--
+ protocol=https
+ host=example.com
+ path=foo.git
username=foo
password=bar
--
--
1.7.11.5.g0c7e058.dirty
next prev parent reply other threads:[~2012-06-22 16:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-22 16:07 [PATCH 0/3] git credential plumbing command: implementation and use Matthieu Moy
2012-06-22 16:07 ` [PATCH 1/3] add 'git credential' plumbing command Matthieu Moy
2012-06-22 20:24 ` Junio C Hamano
2012-06-24 11:37 ` Matthieu Moy
2012-06-24 11:39 ` Matthieu Moy
2012-06-24 11:40 ` [PATCH 2/3] git credential fill: output the whole 'struct credential' Matthieu Moy
2012-06-24 11:40 ` [PATCH 3/3] git-remote-mediawiki: add credential support Matthieu Moy
2012-06-26 21:58 ` [PATCH 1/3] add 'git credential' plumbing command Junio C Hamano
2012-06-22 16:07 ` Matthieu Moy [this message]
2012-06-22 20:26 ` [PATCH 2/3] git credential fill: output the whole 'struct credential' Junio C Hamano
2012-06-22 16:07 ` [PATCH 3/3] git-remote-mediawiki: add credential support Matthieu Moy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1340381231-9522-3-git-send-email-Matthieu.Moy@imag.fr \
--to=matthieu.moy@imag.fr \
--cc=Javier.Roucher-Iglesias@ensimag.imag.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).