Merge branch 'jn/stripspace-wo-repository'

"git stripspace" should be usable outside a git repository, but
under the "-s" or "-c" mode, it didn't.

* jn/stripspace-wo-repository:
  stripspace: allow -s/-c outside git repository
This commit is contained in:
Junio C Hamano 2019-01-18 13:49:53 -08:00
commit ec27a94013
2 changed files with 11 additions and 4 deletions

View file

@ -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,
@ -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);
}

View file

@ -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
'