git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Danil Pristupov <danil@danil.cz>
To: git@vger.kernel.org
Subject: Bug: conflict in the last file line results in wrong combined diff
Date: Thu, 18 Aug 2022 15:54:38 +0200	[thread overview]
Message-ID: <CAKdzDnnE3cOsfdQ+HFY76kNB1W2sSm-5EyY7JDe=MsvH4dBZpw@mail.gmail.com> (raw)

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.

                 reply	other threads:[~2022-08-18 13:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='CAKdzDnnE3cOsfdQ+HFY76kNB1W2sSm-5EyY7JDe=MsvH4dBZpw@mail.gmail.com' \
    --to=danil@danil.cz \
    --cc=git@vger.kernel.org \
    /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).