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>
Jeff King committed
Dec 10, 2011 at 05:31 UTC
d5742425ebfd3060fd181195f3be84cd28c1d06f
3 files changed
+33
credential.c
+4
@@ -65,6 +65,10 @@ static int credential_config_callback(const char *var, const char *value,
65
66
if (!strcmp(key, "helper"))
67
string_list_append(&c->helpers, value);
68
+ else if (!strcmp(key, "username")) {
69
+ if (!c->username)
70
+ c->username = xstrdup(value);
71
+ }
72
73
return 0;
74
}
t/t0300-credentials.sh
+13
@@ -234,4 +234,17 @@ test_expect_success 'do not match configured credential' '
234
EOF
235
'
236
237
+test_expect_success 'pull username from config' '
238
+ test_config credential.https://example.com.username foo &&
239
+ check fill <<-\EOF
240
+ protocol=https
241
+ host=example.com
242
+ --
243
+ username=foo
244
+ password=askpass-password
245
+ --
246
+ askpass: Password for '\''https://foo@example.com'\'':
247
+ EOF
248
+'
249
+
250
test_done
t/t5550-http-fetch.sh
+16
@@ -113,6 +113,22 @@ test_expect_success 'http auth respects credential helper config' '
113
expect_askpass none
114
'
115
116
+test_expect_success 'http auth can get username from config' '
117
+ test_config_global "credential.$HTTPD_URL.username" user@host &&
118
+ >askpass-query &&
119
+ echo user@host >askpass-response &&
120
+ git clone "$HTTPD_URL/auth/repo.git" clone-auth-user &&
121
+ expect_askpass pass user@host
122
+'
123
+
124
+test_expect_success 'configured username does not override URL' '
125
+ test_config_global "credential.$HTTPD_URL.username" wrong &&
126
+ >askpass-query &&
127
+ echo user@host >askpass-response &&
128
+ git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-user2 &&
129
+ expect_askpass pass user@host
130
+'
131
+
132
test_expect_success 'fetch changes via http' '
133
echo content >>file &&
134
git commit -a -m two &&