credential: load default config

Make `git credential fill` honour the core.askPass variable. Signed-off-by: Thomas Koutcher <thomas.koutcher@online.fr> [jk: added test] Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Koutcher committed Oct 15, 2020 at 21:59 UTC 567ad2c0f90fe63d1fde2c0269be8df17675148c
2 files changed +29
builtin/credential.c
+3
@@ -1,6 +1,7 @@
1 #include "git-compat-util.h"
2 #include "credential.h"
3 #include "builtin.h"
4 +#include "config.h"
5
6 static const char usage_msg[] =
7 "git credential [fill|approve|reject]";
@@ -10,6 +11,8 @@ int cmd_credential(int argc, const char **argv, const char *prefix)
11 const char *op;
12 struct credential c = CREDENTIAL_INIT;
13
14 + git_config(git_default_config, NULL);
15 +
16 if (argc != 2 || !strcmp(argv[1], "-h"))
17 usage(usage_msg);
18 op = argv[1];
t/t0300-credentials.sh
+26
@@ -265,6 +265,32 @@ test_expect_success 'internal getpass does not ask for known username' '
265 EOF
266 '
267
268 +test_expect_success 'git-credential respects core.askPass' '
269 + write_script alternate-askpass <<-\EOF &&
270 + echo >&2 "alternate askpass invoked"
271 + echo alternate-value
272 + EOF
273 + test_config core.askpass "$PWD/alternate-askpass" &&
274 + (
275 + # unset GIT_ASKPASS set by lib-credential.sh which would
276 + # override our config, but do so in a subshell so that we do
277 + # not interfere with other tests
278 + sane_unset GIT_ASKPASS &&
279 + check fill <<-\EOF
280 + protocol=http
281 + host=example.com
282 + --
283 + protocol=http
284 + host=example.com
285 + username=alternate-value
286 + password=alternate-value
287 + --
288 + alternate askpass invoked
289 + alternate askpass invoked
290 + EOF
291 + )
292 +'
293 +
294 HELPER="!f() {
295 cat >/dev/null
296 echo username=foo