summaryrefslogtreecommitdiff
path: root/credential.c
diff options
context:
space:
mode:
authorbrian m. carlson <bk2204@github.com>2020-02-20 02:24:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-02-20 21:05:43 (GMT)
commit82eb249853868582d8ba65e3afc5a7dcaeb620ea (patch)
treef7810f74a0f26aa183be36239edadbad5cf7b3ab /credential.c
parent588c70e10f3511f85110512da97b188f3c581e53 (diff)
downloadgit-82eb249853868582d8ba65e3afc5a7dcaeb620ea.zip
git-82eb249853868582d8ba65e3afc5a7dcaeb620ea.tar.gz
git-82eb249853868582d8ba65e3afc5a7dcaeb620ea.tar.bz2
credential: use the last matching username in the config
Everywhere else in the codebase, we use the rule that the last matching configuration option is the one that takes effect. This is helpful because it allows more specific configuration settings (e.g., per-repo configuration) to override less specific settings (e.g., per-user configuration). However, in the credential code, we didn't honor this setting, and instead picked the first setting we had, and stuck with it. This was likely to ensure we picked the value from the URL, which we want to honor over the configuration. It's possible to do both, though, so let's check if the value is the one we've gotten over our protocol connection, which if present will have come from the URL, and keep it if so. Otherwise, let's overwrite the value with the latest version we've got from the configuration, so we keep the last configuration value. Signed-off-by: brian m. carlson <bk2204@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'credential.c')
-rw-r--r--credential.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/credential.c b/credential.c
index 62be651..5701e32 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;
}