credential: let empty credential specs reset helper list

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>

Jeff King committed Feb 26, 2016 at 05:51 UTC 24321375cda79f141be72d1a842e930df6f41725
4 files changed +25 -5
Documentation/config.txt
+3 -2
@@ -1113,8 +1113,9 @@ commit.template::
1113 credential.helper::
1114 Specify an external helper to be called when a username or
1115 password credential is needed; the helper may consult external
1116 - storage to avoid prompting the user for the credentials. See
1117 - linkgit:gitcredentials[7] for details.
1116 + storage to avoid prompting the user for the credentials. Note
1117 + that multiple helpers may be defined. See linkgit:gitcredentials[7]
1118 + for details.
1119
1120 credential.useHttpPath::
1121 When acquiring credentials, consider the "path" component of an http
Documentation/gitcredentials.txt
+5
@@ -106,6 +106,11 @@ variable, each helper will be tried in turn, and may provide a username,
106 password, or nothing. Once Git has acquired both a username and a
107 password, no more helpers will be tried.
108
109 +If `credential.helper` is configured to the empty string, this resets
110 +the helper list to empty (so you may override a helper set by a
111 +lower-priority config file by configuring the empty-string helper,
112 +followed by whatever set of helpers you would like).
113 +
114
115 CREDENTIAL CONTEXTS
116 -------------------
credential.c
+6 -3
@@ -63,9 +63,12 @@ static int credential_config_callback(const char *var, const char *value,
63 key = dot + 1;
64 }
65
66 - if (!strcmp(key, "helper"))
67 - string_list_append(&c->helpers, value);
68 - else if (!strcmp(key, "username")) {
66 + if (!strcmp(key, "helper")) {
67 + if (*value)
68 + string_list_append(&c->helpers, value);
69 + else
70 + string_list_clear(&c->helpers, 0);
71 + } else if (!strcmp(key, "username")) {
72 if (!c->username)
73 c->username = xstrdup(value);
74 }
t/t0300-credentials.sh
+11
@@ -298,4 +298,15 @@ test_expect_success 'helpers can abort the process' '
298 test_cmp expect stdout
299 '
300
301 +test_expect_success 'empty helper spec resets helper list' '
302 + test_config credential.helper "verbatim file file" &&
303 + check fill "" "verbatim cmdline cmdline" <<-\EOF
304 + --
305 + username=cmdline
306 + password=cmdline
307 + --
308 + verbatim: get
309 + EOF
310 +'
311 +
312 test_done