aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-12-10 05:31:30 -0500
committerJunio C Hamano <gitster@pobox.com>2011-12-11 23:16:24 -0800
commitd5742425ebfd3060fd181195f3be84cd28c1d06f (patch)
treeed7860e560e9ad0690f73d7375b4b067a13556f4
parent118250728e1aa46c19d4d258950b2ba15cb6d5d2 (diff)
downloadgit-d5742425ebfd3060fd181195f3be84cd28c1d06f.tar.gz
git-d5742425ebfd3060fd181195f3be84cd28c1d06f.tar.xz
credential: add credential.*.username
Credential helpers can help users avoid having to type their username and password over and over. However, some users may not want a helper for their password, or they may be running a helper which caches for a short time. In this case, it is convenient to provide the non-secret username portion of their credential via config. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--credential.c4
-rwxr-xr-xt/t0300-credentials.sh13
-rwxr-xr-xt/t5550-http-fetch.sh16
3 files changed, 33 insertions, 0 deletions
diff --git a/credential.c b/credential.c
index 96be1c22d..3c17ea197 100644
--- a/credential.c
+++ b/credential.c
@@ -65,6 +65,10 @@ static int credential_config_callback(const char *var, const char *value,
if (!strcmp(key, "helper"))
string_list_append(&c->helpers, value);
+ else if (!strcmp(key, "username")) {
+ if (!c->username)
+ c->username = xstrdup(value);
+ }
return 0;
}
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index 42d0f5b70..53e94bc03 100755
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
@@ -234,4 +234,17 @@ test_expect_success 'do not match configured credential' '
EOF
'
+test_expect_success 'pull username from config' '
+ test_config credential.https://example.com.username foo &&
+ check fill <<-\EOF
+ protocol=https
+ host=example.com
+ --
+ username=foo
+ password=askpass-password
+ --
+ askpass: Password for '\''https://foo@example.com'\'':
+ EOF
+'
+
test_done
diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh
index c59908fe7..3262f903e 100755
--- a/t/t5550-http-fetch.sh
+++ b/t/t5550-http-fetch.sh
@@ -113,6 +113,22 @@ test_expect_success 'http auth respects credential helper config' '
expect_askpass none
'
+test_expect_success 'http auth can get username from config' '
+ test_config_global "credential.$HTTPD_URL.username" user@host &&
+ >askpass-query &&
+ echo user@host >askpass-response &&
+ git clone "$HTTPD_URL/auth/repo.git" clone-auth-user &&
+ expect_askpass pass user@host
+'
+
+test_expect_success 'configured username does not override URL' '
+ test_config_global "credential.$HTTPD_URL.username" wrong &&
+ >askpass-query &&
+ echo user@host >askpass-response &&
+ git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-user2 &&
+ expect_askpass pass user@host
+'
+
test_expect_success 'fetch changes via http' '
echo content >>file &&
git commit -a -m two &&