builtin-config: Fix crash when using "-f <relative path>" from non-root dir
When your current directory is not at the root of the working tree, and you use the "-f" option with a relative path, the current code tries to read from a wrong file, since argv[2] is now beyond the end of the rearranged argument list. This patch replaces the incorrect argv[2] with the variable holding the given config file name. The bug was introduced by d64ec16 (git config: reorganize to use parseopt). [jc: added test] Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Jan 26, 2010 at 16:02 UTC
65807ee697a28cb30b8ad38ebb8b84cebd3f255d
2 files changed
+12
-1
builtin-config.c
+1
-1
@@ -339,7 +339,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
339
if (!is_absolute_path(given_config_file) && prefix)
340
config_exclusive_filename = prefix_filename(prefix,
341
strlen(prefix),
342
- argv[2]);
342
+ given_config_file);
343
else
344
config_exclusive_filename = given_config_file;
345
}
t/t1300-repo-config.sh
+11
@@ -398,6 +398,17 @@ test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
398
test_expect_success 'alternative GIT_CONFIG (--file)' \
399
'git config --file other-config -l > output && cmp output expect'
400
401
+test_expect_success 'refer config from subdirectory' '
402
+ mkdir x &&
403
+ (
404
+ cd x &&
405
+ echo strasse >expect
406
+ git config --get --file ../other-config ein.bahn >actual &&
407
+ test_cmp expect actual
408
+ )
409
+
410
+'
411
+
412
GIT_CONFIG=other-config git config anwohner.park ausweis
413
414
cat > expect << EOF