]> git.ipfire.org Git - thirdparty/git.git/commitdiff
credential: let empty credential specs reset helper list
authorJeff King <peff@peff.net>
Fri, 26 Feb 2016 10:51:35 +0000 (05:51 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 26 Feb 2016 18:58:14 +0000 (10:58 -0800)
Sine the credential.helper key is a multi-valued config
list, there's no way to "unset" a helper once it's been set.
So if your system /etc/gitconfig sets one, you can never
avoid running it, but only add your own helpers on top.

Since an empty value for credential.helper is nonsensical
(it would just try to run "git-credential-"), we can assume
nobody is using it. Let's define it to reset the helper
list, letting you override lower-priority instances which
have come before.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
Documentation/gitcredentials.txt
credential.c
t/t0300-credentials.sh

index 2cd6bdd7d2bc2816c1a9aed1c6a26bbd3285777c..4b85095fc2c2875e5289f9f52264c22ef6111bfe 100644 (file)
@@ -1113,8 +1113,9 @@ commit.template::
 credential.helper::
        Specify an external helper to be called when a username or
        password credential is needed; the helper may consult external
-       storage to avoid prompting the user for the credentials. See
-       linkgit:gitcredentials[7] for details.
+       storage to avoid prompting the user for the credentials. Note
+       that multiple helpers may be defined. See linkgit:gitcredentials[7]
+       for details.
 
 credential.useHttpPath::
        When acquiring credentials, consider the "path" component of an http
index 1c75be080368a5975b609cd8b902d224eabc9bd8..f3a75d1ce1c5a2709b452faca76f5f6f1cdb7de0 100644 (file)
@@ -106,6 +106,11 @@ variable, each helper will be tried in turn, and may provide a username,
 password, or nothing. Once Git has acquired both a username and a
 password, no more helpers will be tried.
 
+If `credential.helper` is configured to the empty string, this resets
+the helper list to empty (so you may override a helper set by a
+lower-priority config file by configuring the empty-string helper,
+followed by whatever set of helpers you would like).
+
 
 CREDENTIAL CONTEXTS
 -------------------
index 7d6501d190a529933d501e7f7006a70c4897282b..aa996669fc40021e0c8cb01fa8021da7064e2781 100644 (file)
@@ -63,9 +63,12 @@ static int credential_config_callback(const char *var, const char *value,
                key = dot + 1;
        }
 
-       if (!strcmp(key, "helper"))
-               string_list_append(&c->helpers, value);
-       else if (!strcmp(key, "username")) {
+       if (!strcmp(key, "helper")) {
+               if (*value)
+                       string_list_append(&c->helpers, value);
+               else
+                       string_list_clear(&c->helpers, 0);
+       } else if (!strcmp(key, "username")) {
                if (!c->username)
                        c->username = xstrdup(value);
        }
index d7ef44b4a261a588874df3b8359d809655286a43..03bd31e9f22a1964551cb07d76c45ce90a3cd17e 100755 (executable)
@@ -298,4 +298,15 @@ test_expect_success 'helpers can abort the process' '
        test_cmp expect stdout
 '
 
+test_expect_success 'empty helper spec resets helper list' '
+       test_config credential.helper "verbatim file file" &&
+       check fill "" "verbatim cmdline cmdline" <<-\EOF
+       --
+       username=cmdline
+       password=cmdline
+       --
+       verbatim: get
+       EOF
+'
+
 test_done