Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--credential.c9
-rw-r--r--credential.h3
-rwxr-xr-xt/t0300-credentials.sh2
3 files changed, 11 insertions, 3 deletions
diff --git a/credential.c b/credential.c
index 62be651b03..5701e32792 100644
--- a/credential.c
+++ b/credential.c
@@ -71,8 +71,10 @@ static int credential_config_callback(const char *var, const char *value,
else
string_list_clear(&c->helpers, 0);
} else if (!strcmp(key, "username")) {
- if (!c->username)
+ if (!c->username_from_proto) {
+ free(c->username);
c->username = xstrdup(value);
+ }
}
else if (!strcmp(key, "usehttppath"))
c->use_http_path = git_config_bool(var, value);
@@ -163,6 +165,7 @@ int credential_read(struct credential *c, FILE *fp)
if (!strcmp(key, "username")) {
free(c->username);
c->username = xstrdup(value);
+ c->username_from_proto = 1;
} else if (!strcmp(key, "password")) {
free(c->password);
c->password = xstrdup(value);
@@ -349,10 +352,14 @@ void credential_from_url(struct credential *c, const char *url)
else if (!colon || at <= colon) {
/* Case (2) */
c->username = url_decode_mem(cp, at - cp);
+ if (c->username && *c->username)
+ c->username_from_proto = 1;
host = at + 1;
} else {
/* Case (3) */
c->username = url_decode_mem(cp, colon - cp);
+ if (c->username && *c->username)
+ c->username_from_proto = 1;
c->password = url_decode_mem(colon + 1, at - (colon + 1));
host = at + 1;
}
diff --git a/credential.h b/credential.h
index 5772d50577..fffed4d934 100644
--- a/credential.h
+++ b/credential.h
@@ -208,7 +208,8 @@ struct credential {
unsigned approved:1,
configured:1,
quit:1,
- use_http_path:1;
+ use_http_path:1,
+ username_from_proto:1;
char *username;
char *password;
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index 4593a0cd3d..8f87599056 100755
--- a/t/t0300-credentials.sh
+++ b/t/t0300-credentials.sh
@@ -344,7 +344,7 @@ test_expect_success 'honors username from URL over helper (components)' '
EOF
'
-test_expect_failure 'last matching username wins' '
+test_expect_success 'last matching username wins' '
test_config credential.https://example.com/path.git.username bob &&
test_config credential.https://example.com.username alice &&
test_config credential.https://example.com.helper "verbatim \"\" bar" &&