Skip to content

Commit

Permalink
stripspace: allow -s/-c outside git repository
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jonathan Nieder <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
jrn authored and gitster committed Dec 26, 2018
1 parent 0d0ac38 commit 957da75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion builtin/stripspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
{
struct strbuf buf = STRBUF_INIT;
enum stripspace_mode mode = STRIP_DEFAULT;
int nongit;

const struct option options[] = {
OPT_CMDMODE('s', "strip-comments", &mode,
Expand All @@ -46,7 +47,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
usage_with_options(stripspace_usage, options);

if (mode == STRIP_COMMENTS || mode == COMMENT_LINES) {
setup_git_directory_gently(NULL);
setup_git_directory_gently(&nongit);
git_config(git_default_config, NULL);
}

Expand Down
12 changes: 9 additions & 3 deletions t/t0030-stripspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,15 @@ test_expect_success '-c with changed comment char' '
test_expect_success '-c with comment char defined in .git/config' '
test_config core.commentchar = &&
printf "= foo\n" >expect &&
printf "foo" | (
mkdir sub && cd sub && git stripspace -c
) >actual &&
rm -fr sub &&
mkdir sub &&
printf "foo" | git -C sub stripspace -c >actual &&
test_cmp expect actual
'

test_expect_success '-c outside git repository' '
printf "# foo\n" >expect &&
printf "foo" | nongit git stripspace -c >actual &&
test_cmp expect actual
'

Expand Down

0 comments on commit 957da75

Please sign in to comment.