From: Junio C Hamano <gitster@pobox.com>
To: Simon Ser <contact@emersion.fr>
Cc: git@vger.kernel.org, me@ttaylorr.com,
Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH v2] grep: add configuration variables for --heading
Date: Wed, 27 May 2020 09:45:13 -0700 [thread overview]
Message-ID: <xmqqeer5mina.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <C5PlGbi78_QpceNrgFm_-Wt6BooqbntaL8OdH7XjxjXCtyIfsisyeOQMslLOwNY68Dg7iUxGIvzLPAvUEWyMIC0GdpTgeWwgwD5sWlsyrSM=@emersion.fr> (Simon Ser's message of "Wed, 27 May 2020 15:45:46 +0000")
Simon Ser <contact@emersion.fr> writes:
> There are already configuration variables for -n and --column. Add one
> for --heading, allowing users to customize the default behaviour.
>
> Signed-off-by: Simon Ser <contact@emersion.fr>
> ---
>
> v2: add a test
>
> Documentation/git-grep.txt | 3 +++
> grep.c | 5 +++++
> t/t7810-grep.sh | 5 +++++
> 3 files changed, 13 insertions(+)
>
> diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
> index a7f9bc99eaf1..ed4f05d885a2 100644
> --- a/Documentation/git-grep.txt
> +++ b/Documentation/git-grep.txt
> @@ -47,6 +47,9 @@ grep.lineNumber::
> grep.column::
> If set to true, enable the `--column` option by default.
>
> +grep.heading::
> + If set to true, enable the `--heading` option by default.
> +
OK.
Naturally it follows that a command-line option
$ git config grep.heading yes
$ git grep --no-heading -e pattern
is a way to countermand the configured default per invocation
basis.
> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
> index 991d5bd9c03f..1acc6fe89c51 100755
> --- a/t/t7810-grep.sh
> +++ b/t/t7810-grep.sh
> @@ -1556,6 +1556,11 @@ test_expect_success 'grep --heading' '
> test_cmp expected actual
> '
>
> +test_expect_success 'grep with grep.heading=true' '
> + git -c grep.heading=true grep -e char -e lo_w hello.c hello_world >actual &&
> + test_cmp expected actual
> +'
> +
When writing new tests, we often get too excited and stop at showing
off how well the shiny new feature works, but we should make sure
that we test the "negative" case, too, i.e. that the "feature" can
be disabled when the user does not want to trigger it, and that the
"feature" notices incorrect invocations and fails appropriately.
E.g.
git -c grep.heading=yes grep --no-heading ...
should not leave the opt->heading true, and
git -c grep.heading=nonsense grep ...
should fail, saying "grep.heading must be a bool" (or something
along that line).
Thanks.
> cat >expected <<EOF
> <BOLD;GREEN>hello.c<RESET>
> 4:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
next prev parent reply other threads:[~2020-05-27 16:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-26 8:37 [PATCH] grep: add configuration variables for --heading Simon Ser
2020-05-26 13:40 ` Eric Sunshine
2020-05-27 15:45 ` [PATCH v2] " Simon Ser
2020-05-27 16:45 ` Junio C Hamano [this message]
2020-06-08 10:22 ` Simon Ser
2020-06-08 14:02 ` Phillip Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqeer5mina.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=contact@emersion.fr \
--cc=git@vger.kernel.org \
--cc=me@ttaylorr.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).