summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1182507)
raw | patch | inline | side by side (parent: 1182507)
author | Jeff King <peff@peff.net> | |
Sat, 10 Dec 2011 10:31:30 +0000 (05:31 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 12 Dec 2011 07:16:24 +0000 (23:16 -0800) |
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>
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>
credential.c | patch | blob | history | |
t/t0300-credentials.sh | patch | blob | history | |
t/t5550-http-fetch.sh | patch | blob | history |
diff --git a/credential.c b/credential.c
index 96be1c22dd4b6188aef9c89de51ffe6ac08a0331..3c17ea19732c01dbd2a32bd3f3c97483ef2f5556 100644 (file)
--- a/credential.c
+++ b/credential.c
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 42d0f5b7078ab405f70d71a9eeb7acb45b400ac6..53e94bc0382f7d2fc0fc99935269f3d630995ddf 100755 (executable)
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
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 c59908fe77fdf1af3357a801e8ad86e3b0355508..3262f903e14499a1d0823150713a5f81072577f9 100755 (executable)
--- a/t/t5550-http-fetch.sh
+++ b/t/t5550-http-fetch.sh
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 &&