gitui icon indicating copy to clipboard operation
gitui copied to clipboard

Wrong patch when staged line by line, compared to other alternatives

Open kulkalkul opened this issue 3 years ago • 8 comments

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:

  1. Create a empty repo
  2. Stage & commit this on a file:
struct Earth;

impl Earth {
	fn new() -> Self {
		Self
	}
}

struct Mars;

impl Mars {
	fn new() -> Self {
		Self
	}
}
  1. 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
	}
}
  1. Use gitui to just stage into_mars and its body
  2. 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.

kulkalkul avatar Oct 31 '22 01:10 kulkalkul

It also duplicates some of the lines if you stage removal of \ No newline at end of file: image

I believe both issues could be related.

kulkalkul avatar Oct 31 '22 02:10 kulkalkul

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,

alexmaco avatar Nov 04 '22 13:11 alexmaco

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

extrawurst avatar Nov 05 '22 08:11 extrawurst

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

kulkalkul avatar Nov 05 '22 13:11 kulkalkul

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

extrawurst avatar Nov 05 '22 14:11 extrawurst

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.

stale[bot] avatar May 21 '23 11:05 stale[bot]

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

kulkalkul avatar Sep 02 '23 04:09 kulkalkul