jesseduffield / lazygit

simple terminal UI for git commands
MIT License
47.94k stars 1.72k forks source link

Custom patch fails with "error: new file XXX depends on old contents" #3679

Closed sedmicha closed 1 week ago

sedmicha commented 1 week ago

Hello,

I often use the "Custom patch options" to split one commit into multiple, but I have run into a problem with commits that create a new file. In this case, when I try to split such commit into two, the custom patch fails to apply with "error: new file XXX depends on old contents". Am I doing something wrong or is this functionality that's missing or a bug?

To demonstrate: This does not work, and I'd expect it to: https://asciinema.org/a/qbyHwDITTdbd0Wa3V7UnWO6E6 This does work as expected: https://asciinema.org/a/lc4ZiQDb7XaxgR8yt65RKrcMO

Thanks

stefanhaller commented 1 week ago

You are definitely not doing anything wrong, I'd also expect this to work. This also happens when trying to drop a few lines from a newly added file using a custom patch.

I'll see if I can find a way to work around it.

stefanhaller commented 1 week ago

Here's a PR that fixes this: #3684. It needs thorough testing, as it is mucking with git internals even more than the custom patch mechanism already does. For example, I almost broke the feature of moving parts of an added file to an earlier commit.

@sedmicha If you can build from source, it would be great if you could test it.