Skip to content

Commit

Permalink
Merge branch 'jk/credential-clear-config'
Browse files Browse the repository at this point in the history
The credential.helper configuration variable is cumulative and
there is no good way to override it from the command line.  As
a special case, giving an empty string as its value now serves
as the signal to clear the values specified in various files.

* jk/credential-clear-config:
  credential: let empty credential specs reset helper list
  • Loading branch information
Junio C Hamano committed Apr 3, 2016
2 parents e13de0b + 2432137 commit 1b68962
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Documentation/gitcredentials.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------
Expand Down
9 changes: 6 additions & 3 deletions credential.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 11 additions & 0 deletions t/t0300-credentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1b68962

Please sign in to comment.