NeogitOrg / neogit

An interactive and powerful Git interface for Neovim, inspired by Magit
MIT License
3.83k stars 228 forks source link

Fix status when files have conflicts #1216

Closed kjughx closed 5 months ago

kjughx commented 5 months ago

The bug was that in a repo which has both a conflict and a renamed file git status -z --porcelain=2 -b will report:

# branch.oid dbb8571c4f873daff059c04443077b43a703338a
# branch.head (detached)
2 R. N... 100644 100644 100644 cd4e4e1ada23361e9ad886a5723bda3aa9419ea8 cd4e4e1ada23361e9ad886a5723bda3aa9419ea8 R100 c.txt
a.txt
u UU N... 100644 100644 100644 100644 15b4f7fdbd22faf05ee23ec5c3a98c775657fe18 7513f79749fe4a5c1942b1f89de63c128a0fedcd d5a2e9b772aa39468c69670ad9bd319bbf197a86 b.txt

and that does not match the pattern in: if line:match("^[12u]%s[MTADRCU%s%.%?!][MTDRCU%s%.%?!]%s") or line:match("^[%?!#]%s") then so it falls through to the else which appends the unmatched line to the previous line.

The else statement is there to handle renamed files which end up on separate lines so I changed the for loop from a simple one-by-one loop to a loop that can look at the previous line. If the previous line is a "this file was renamed", i.e. matches: ^2 R., then append the current line, which contains the old file, to the previous line and move on.

This fixes #1176

CKolkey commented 5 months ago

Thanks for tackling this ;)