{"thread":{"id":"58320","subject":"Bug: conflict in the last file line results in wrong combined diff","startedAt":"2022-08-18T13:56:14Z","lastAt":"2022-08-18T13:56:14Z","messageCount":1,"participants":["Danil Pristupov"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"461421","messageId":"CAKdzDnnE3cOsfdQ+HFY76kNB1W2sSm-5EyY7JDe=MsvH4dBZpw@mail.gmail.com","threadId":"58320","inReplyTo":null,"subject":"Bug: conflict in the last file line results in wrong combined diff","fromName":"Danil Pristupov","fromEmail":"danil@danil.cz","sentAt":"2022-08-18T13:54:38Z","receivedAt":"2022-08-18T13:56:14Z","isPatch":false,"sender":{"key":"danil@danil.cz","avatar":"https://gravatar.com/avatar/0c17c2eda2eaabbcc09a02149bedaff23bc8894c7be16e6b25d6602abfc34243?d=mp&s=160"},"body":"I found another bug in the combined diff. It is slightly related to\nthe one I reported some time ago (combined diff always misses\n'NoEolAtEof' pragma), but it's different.\n\nDescription:\nA simple conflict in the last line in a file with no EOL at EOF\nresults in a wrong -cc diff with a weird (invalid?) formatting.\n\nSteps to reproduce:\n\n```\ngit init\n\necho -n \"1\\n2\" > m.txt\ngit add m.txt\ngit commit -m \"initial commit\"\n\necho -n \"1m\\n2m\" > m.txt\ngit commit -am \"master change\"\n\ngit checkout -b branch1 HEAD^\necho -n \"1b\\n2b\" > m.txt\ngit commit -am \"branch1 change\"\n\ngit merge master\n\ngit log --all --graph --oneline\ngit diff m.txt\n```\n\nActual diff:\n\n```\ndiff --cc m.txt\nindex d53cefe,cf67f83..0000000\n--- a/m.txt\n+++ b/m.txt\n@@@ -1,2 -1,2 +1,7 @@@\n++<<<<<<< HEAD\n +1b\n- 2b      <- wrong! there was no '2b' in the initial commit\n++2b      <- wrong! '++' ('both added') doesn't make sense inside a\nconflict block\n++=======\n+ 1m\n -2m      <- wrong! there was no '2m' in the initial commit\n++2m      <- wrong! '++' ('both added') doesn't make sense inside a\nconflict block\n++>>>>>>> master\n```\n\nExpected diff (I intentionally missed `\\ No newline at end of file`\npragmas to simplify the idea):\n```\n$ git diff m.txt\ndiff --cc m.txt\nindex 7d8e479,73a8b45..0000000\n--- a/m.txt\n+++ b/m.txt\n@@@ -1,2 -1,2 +1,7 @@@\n++<<<<<<< HEAD\n +1b\n +2b\n++=======\n+ 1m\n+ 2m\n++>>>>>>> master\n```\n\nIt looks like `\\ No newline at end of file` handling is involved\nbecause removing `-n` from the `echo` command in the steps to\nreproduce makes diff to produce the correct output.\n"}]}