git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] diff: diff.context configuration gives default to -U

From
Jeff King <peff@peff.net>
Date
Sep 27, 2012, 18:43 UTC
Message-ID
<20120927184309.GC2519@sigill.intra.peff.net>
In-Reply-To
<7vr4pnqs8l.fsf@alter.siamese.dyndns.org>
On Thu, Sep 27, 2012 at 10:40:26AM -0700, Junio C Hamano wrote:
Show 21 quoted lines
> > +test_expect_success 'diff.context affects log' '
> > +	git log -1 -p | grep -q -v firstline
> > +	git config diff.context 8 &&
> > +	git log -1 -p | grep -q firstline
> > +'
> 
> Three points:
> 
>  - Please avoid "grep -q", which does not help people who ran tests
>    (the output is hidden by default) and hurts people who want to
>    debug tests.
> 
>  - Your test will ignore breakage from the first "log 1" output and
>    goes on running "git config".  Make sure you got your && cascades
>    right.
> 
>  - Because an error from the command on the upstream side of the
>    pipe is ignored, we tend to prefer writing things like this:
> 
> 	git log -n 1 -p >output &&
>         grep -v firstline output &&

I agree with all of that. But also, is "grep -v" the right thing? I think the intent of the test is "firstline does not appear". But that is not what "grep -v" will tell you. It will tell you whether any line that did not have "firstline" in it was shown (which it would be, since there are a bunch of other lines shown).

I think "! grep firstline" is what is needed here. Or even just explicitly matching the diff that we expect via test_cmp. I like the latter much better anyway, as a failure will show exactly what is wrong. Whereas if the grep ends up not matching, there is no helpful output for somebody reading the test.

We already produce nice messages from things like test_must_fail. Maybe it would be nice to have:

  test_contains () {
          if ! grep "$1" "$2"; then
	          echo >&2 "File '$2' does not contain a line with '$1'"
		  return 1
	  fi
  }

and likewise a "test_not_contains" or something to negate it. That makes both the tests and their failure output readable.

-Peff
Previous: Junio C HamanoNext: Jeff Muizelaar
Message 5 of 8 in “Add diff.context option to specify default context”
  1. Add diff.context option to specify default contextJeff Muizelaar, Sep 14, 2012
  2. Junio C HamanoSep 14, 2012
  3. diff: diff.context configuration gives default to -UJeff Muizelaar, Sep 27, 2012
  4. Junio C HamanoSep 27, 2012
  5. Jeff KingSep 27, 2012
  6. diff: diff.context configuration gives default to -UJeff Muizelaar, Sep 27, 2012
  7. Junio C HamanoSep 27, 2012
  8. diff: diff.context configuration gives default to -UJeff Muizelaar, Oct 19, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.