stripspace: allow -s/-c outside git repository
v2.11.0-rc3~3^2~1 (stripspace: respect repository config, 2016-11-21) improved stripspace --strip-comments / --comentlines by teaching them to read repository config, but it went a little too far: when running stripspace outside any repository, the result is $ git stripspace --strip-comments <test-input fatal: not a git repository (or any parent up to mount point /tmp) That makes experimenting with the stripspace command unnecessarily fussy. Fix it by discovering the git directory gently, as intended all along. Reported-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Dec 17, 2018 at 08:59 UTC
957da7580255f30ce8f1224531e795a9bace3d52
2 files changed
+11
-4
builtin/stripspace.c
+2
-1
@@ -30,6 +30,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
30
{
31
struct strbuf buf = STRBUF_INIT;
32
enum stripspace_mode mode = STRIP_DEFAULT;
33
+ int nongit;
34
35
const struct option options[] = {
36
OPT_CMDMODE('s', "strip-comments", &mode,
@@ -46,7 +47,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
47
usage_with_options(stripspace_usage, options);
48
49
if (mode == STRIP_COMMENTS || mode == COMMENT_LINES) {
49
- setup_git_directory_gently(NULL);
50
+ setup_git_directory_gently(&nongit);
51
git_config(git_default_config, NULL);
52
}
53
t/t0030-stripspace.sh
+9
-3
@@ -430,9 +430,15 @@ test_expect_success '-c with changed comment char' '
430
test_expect_success '-c with comment char defined in .git/config' '
431
test_config core.commentchar = &&
432
printf "= foo\n" >expect &&
433
- printf "foo" | (
434
- mkdir sub && cd sub && git stripspace -c
435
- ) >actual &&
433
+ rm -fr sub &&
434
+ mkdir sub &&
435
+ printf "foo" | git -C sub stripspace -c >actual &&
436
+ test_cmp expect actual
437
+'
438
+
439
+test_expect_success '-c outside git repository' '
440
+ printf "# foo\n" >expect &&
441
+ printf "foo" | nongit git stripspace -c >actual &&
442
test_cmp expect actual
443
'
444