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

Bug: conflict in the last file line results in wrong combined diff

From
Danil Pristupov <danil@danil.cz>
Date
Aug 18, 2022, 13:54 UTC
Message-ID
<CAKdzDnnE3cOsfdQ+HFY76kNB1W2sSm-5EyY7JDe=MsvH4dBZpw@mail.gmail.com>

I found another bug in the combined diff. It is slightly related to the one I reported some time ago (combined diff always misses 'NoEolAtEof' pragma), but it's different.

Description: A simple conflict in the last line in a file with no EOL at EOF results in a wrong -cc diff with a weird (invalid?) formatting.

Steps to reproduce:

``` git init

echo -n "1\n2" > m.txt git add m.txt git commit -m "initial commit"

echo -n "1m\n2m" > m.txt git commit -am "master change"

git checkout -b branch1 HEAD^ echo -n "1b\n2b" > m.txt git commit -am "branch1 change"

git merge master

git log --all --graph --oneline git diff m.txt ```

Actual diff:

``` diff --cc m.txt index d53cefe,cf67f83..0000000

--- a/m.txt
+++ b/m.txt
@@@ -1,2 -1,2 +1,7 @@@
++<<<<<<< HEAD
 +1b
- 2b      <- wrong! there was no '2b' in the initial commit
++2b      <- wrong! '++' ('both added') doesn't make sense inside a
conflict block
++=======
+ 1m
 -2m      <- wrong! there was no '2m' in the initial commit
++2m      <- wrong! '++' ('both added') doesn't make sense inside a
conflict block
++>>>>>>> master
```

Expected diff (I intentionally missed `\ No newline at end of file`
pragmas to simplify the idea):
```
$ git diff m.txt
diff --cc m.txt
index 7d8e479,73a8b45..0000000
--- a/m.txt
+++ b/m.txt
@@@ -1,2 -1,2 +1,7 @@@
++<<<<<<< HEAD
 +1b
 +2b
++=======
+ 1m
+ 2m
++>>>>>>> master
```

It looks like `\ No newline at end of file` handling is involved
because removing `-n` from the `echo` command in the steps to
reproduce makes diff to produce the correct output.
Message 1 of 1 in “Bug: conflict in the last file line results in wrong combined diff”
  1. Danil PristupovAug 18, 2022

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.