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

bug in git-apply

From
Karl Hasselström <kha@treskal.com>
Date
Apr 6, 2008, 23:53 UTC
Message-ID
<20080406235334.GA8483@diana.vm.bytemark.co.uk>

StGit's test suite has started failing, and it's due to a change in git that I'm pretty sure is a bug. I built a small test case using just git for easier testing:

  mkdir foo
  cd foo
  git init
  touch xx
  git add xx
  git commit -m 'first'
  git checkout -b branch
  echo aaa >> xx
  git add xx
  git commit -m 'second'
  git checkout master
  echo bbb >> xx
  git add xx
  git commit -m 'third'
  git diff branch^ branch > p
  git apply < p && echo "this should not succeed!"

Basically, we have a file containing "aaa\n", and a patch that tries to take the file from "" to "bbb\n". A recent enough git-apply will accept this patch without complaining, and put "aaa\nbbb\n" in the file.

I bisected, and the culprit was this commit:
commit dc41976a3eed1d9c93fdc08c448bab969db4e0ec
Author: Junio C Hamano <gitster@pobox.com>
Date:   Sat Jan 19 01:58:34 2008 -0800
    builtin-apply.c: push match-beginning/end logic down
    This moves the logic to force match at the beginning and/or at
    the end of the buffer to the actual function that finds the
    match from its caller.  This is a necessary preparation for the
    next step to allow matching disregarding certain differences,
    such as whitespace changes.
    We probably could optimize this even more by taking advantage of
    the fact that match_beginning and match_end forces the match to
    be at an exact location (anchored at the beginning and/or the
    end), but that's for another commit.
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle
Next: Junio C Hamano
Message 1 of 4 in “bug in git-apply”
  1. Karl HasselströmApr 6, 2008
  2. Junio C HamanoApr 7, 2008
  3. Karl HasselströmApr 7, 2008
  4. Junio C HamanoApr 7, 2008

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.