Wrong patch when staged line by line, compared to other alternatives
Describe the bug
Wrong patch when line by line staging compared to using hunks or lazygit or git add -e.
To Reproduce Steps to reproduce the behavior:
- Create a empty repo
- Stage & commit this on a file:
struct Earth;
impl Earth {
fn new() -> Self {
Self
}
}
struct Mars;
impl Mars {
fn new() -> Self {
Self
}
}
- Update the file with this:
struct Earth;
impl Earth {
fn new() -> Self {
Self
}
fn into_mars(self) -> Mars {
Mars
}
}
struct Mars;
impl Mars {
fn new() -> Self {
Self
}
fn into_earth(self) -> Earth {
Earth
}
}
- Use gitui to just stage
into_marsand its body - Check the resulted patch with
git diff --staged
Expected behavior I expect it to match other commands and tools.
Screenshots (source code is different from the example above as I recorded these before creating the issue) Using gitui: https://asciinema.org/a/dL8rEfpOHRQskpa7wmfVTJDQF Using lazygit: https://asciinema.org/a/z0iSujDQzZO24wr7qXjKNwTf2
Context (please complete the following information):
- OS/Distro + Version: Windows 10 22H2
- GitUI Version: 0.21.0
- Rust version: 1.66.0-nightly
Additional context I don't know if this is actually an issue because I don't know much about git patches; but it looks like it corrupts(?) the patch.
It also duplicates some of the lines if you stage removal of \ No newline at end of file:

I believe both issues could be related.
I think this might also be related to the issue of not being able to stage chunks.
Chunks are identified by a struct HunkHeader and its hash, but, in different contexts the diff returned by things like fn get_diff_raw seems to be different, off by 1 or 2 lines. This results in loading one diff, displaying it, but then when trying to stage, not being able to identify which hunk is selected.
I haven't yet found the cause of this discrepancy,
The line staging and hunk staging use different methods and eventually the manual one for linestaging should be used for the hunk staging.
The line staging is based off code from nodegit
The line staging and hunk staging use different methods and eventually the manual one for linestaging should be used for the hunk staging.
The line staging is based off code from nodegit
Though line staging seems to be having the buggy behaviour here
like @alexmaco said hung staging has issues too, what I am saying is: rather than fixing hunk staging based on a weak duck-taped solution we should rather migrate it to the line based staging and make sure it is more solid
This issue has been automatically marked as stale because it has not had any activity half a year. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
If no one is actively working on this I can try coming up with a solution; but I have no prior experience with anything related.
Also, this seems related: #1804