# [PATCH/RFC] git-grep: correct exit code with --quiet and -L

2 messages from 2017-08-18 to 2017-08-18. Participants: Anthony Sottile, Junio C Hamano.
Thread: https://gitlist.dev/t/46619

## Anthony Sottile, 2017-08-18 01:38

Subject: [PATCH/RFC] git-grep: correct exit code with --quiet and -L
Message-ID: <20170818013851.16753-1-asottile@umich.edu>
URL: https://gitlist.dev/e/20170818013851.16753-1-asottile%40umich.edu

```
The handling of `status_only` no longer interferes with the handling of
`unmatch_name_only`.  `--quiet` no longer affects the exit code when using
`-L`/`--files-without-match`.

Signed-off-by: Anthony Sottile <asottile@umich.edu>
---
 grep.c          | 2 +-
 t/t7810-grep.sh | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/grep.c b/grep.c
index 2efec0e..c9e7cc7 100644
--- a/grep.c
+++ b/grep.c
@@ -1821,7 +1821,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
 		return 0;
 
 	if (opt->status_only)
-		return 0;
+		return opt->unmatch_name_only;
 	if (opt->unmatch_name_only) {
 		/* We did not see any hit, so we want to show this */
 		show_name(opt, gs->name);
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index f106387..2a6679c 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -374,6 +374,11 @@ test_expect_success 'grep -L -C' '
 	test_cmp expected actual
 '
 
+test_expect_success 'grep --files-without-match --quiet' '
+	git grep --files-without-match --quiet nonexistent_string >actual &&
+	test_cmp /dev/null actual
+'
+
 cat >expected <<EOF
 file:foo mmap bar_mmap
 EOF
-- 
2.7.4


```

## Junio C Hamano, 2017-08-18 02:22

Subject: Re: [PATCH/RFC] git-grep: correct exit code with --quiet and -L
Message-ID: <xmqq4lt5ehtc.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq4lt5ehtc.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20170818013851.16753-1-asottile@umich.edu>

```
Anthony Sottile <asottile@umich.edu> writes:

> The handling of `status_only` no longer interferes with the handling of
> `unmatch_name_only`.  `--quiet` no longer affects the exit code when using
> `-L`/`--files-without-match`.
>
> Signed-off-by: Anthony Sottile <asottile@umich.edu>
> ---

Thanks, Will queue.

>  grep.c          | 2 +-
>  t/t7810-grep.sh | 5 +++++
>  2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/grep.c b/grep.c
> index 2efec0e..c9e7cc7 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -1821,7 +1821,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
>  		return 0;
>  
>  	if (opt->status_only)
> -		return 0;
> +		return opt->unmatch_name_only;
>  	if (opt->unmatch_name_only) {
>  		/* We did not see any hit, so we want to show this */
>  		show_name(opt, gs->name);
> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
> index f106387..2a6679c 100755
> --- a/t/t7810-grep.sh
> +++ b/t/t7810-grep.sh
> @@ -374,6 +374,11 @@ test_expect_success 'grep -L -C' '
>  	test_cmp expected actual
>  '
>  
> +test_expect_success 'grep --files-without-match --quiet' '
> +	git grep --files-without-match --quiet nonexistent_string >actual &&
> +	test_cmp /dev/null actual
> +'
> +
>  cat >expected <<EOF
>  file:foo mmap bar_mmap
>  EOF

```
