Skip to content

Commit

Permalink
credential: add credential.*.username
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Dec 12, 2011
1 parent 1182507 commit d574242
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions credential.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 13 additions & 0 deletions t/t0300-credentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions t/t5550-http-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit d574242

Please sign in to comment.