Skip to content

Commit 2432137

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 56f37fd commit 2432137

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

Documentation/config.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,8 +1113,9 @@ commit.template::
11131113
credential.helper::
11141114
Specify an external helper to be called when a username or
11151115
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.
11181119

11191120
credential.useHttpPath::
11201121
When acquiring credentials, consider the "path" component of an http

Documentation/gitcredentials.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ variable, each helper will be tried in turn, and may provide a username,
106106
password, or nothing. Once Git has acquired both a username and a
107107
password, no more helpers will be tried.
108108

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+
109114

110115
CREDENTIAL CONTEXTS
111116
-------------------

credential.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ static int credential_config_callback(const char *var, const char *value,
6363
key = dot + 1;
6464
}
6565

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")) {
6972
if (!c->username)
7073
c->username = xstrdup(value);
7174
}

t/t0300-credentials.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,15 @@ test_expect_success 'helpers can abort the process' '
298298
test_cmp expect stdout
299299
'
300300

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+
301312
test_done

0 commit comments

Comments
 (0)