JetpackDuba / Gitnuro

A FOSS Git multiplatform client for newbies and pros
https://gitnuro.com/
GNU General Public License v3.0
872 stars 44 forks source link

can't stage hunks containing slashes #121

Closed adam-ce closed 1 year ago

adam-ce commented 1 year ago

Describe the bug if a hunk contains changes to lines with slashes, staging that hunk works only partly. after staging, the diff view stops working. i can recover using git cola.

To Reproduce Steps to reproduce the behaviour:

  1. create a new local repository.
  2. add a file, e.g. named CMakeLists.txt
  3. type "/" into that file (yes, only a slash)
  4. stage the file
  5. change the "/" to a "//"
  6. stage the changed hunk, or manually stage both lines (staging the whole file on the right view doesn't trigger the bug)
  7. now the diff view breaks (it shows "old 01, new", indicating a binary file?)

Expected behavior the hunk or the lines are staged correctly, the diff view continues working

Screenshots image

Desktop (please complete the following information):

JetpackDuba commented 1 year ago

Unfortunately I've not been able to reproduce it.

I've done the following steps:

  1. Create and open a new repo.
  2. echo / > CMakeLists.txt
  3. Stage CMakeLists.txt
  4. echo // > CMakeLists.txt
  5. Stage changed hunk CMakeLists.txt (Also tried staging lines individually)
  6. Diff shows as expected.

Am I missing something? It shouldn't show an "old-new" comperison because it's a new file, weird.

adam-ce commented 1 year ago

weird. at work i hit the problem repeatedly, at home not. i'll test again at work.

JetpackDuba commented 1 year ago

Hello!

Have you been able to test it?

adam-ce commented 1 year ago

ye, just now. thanks for the ping.

i can't reproduce it any more at work either. so i guess it was a glitch in the matrix. i'll reopen if it comes up again.

adam-ce commented 1 year ago

CMakeLists.zip

so this file fails to diff for me in gitnuro. i guess, that there is some sort of special character, but i was unable to isolate it.

(that is, unzip and add it to a repo)

adam-ce commented 1 year ago

image formatting also fails in git cola. but at least the file is there.

JetpackDuba commented 1 year ago

It's because of this imagen

For context: raw = file content

For some reason, there is a \r without being part of a line jump, which is extremly weird (in the image there are 2 \r in a row). JGit detects it as something that should not be in a text file and therefore a binary file.

Removing the new lines between lines 41 & 45 and adding them with using Gedit has worked fine.

adam-ce commented 1 year ago

right.

i have no idea how that landed there. might have been some copy pasting from the web. i could understand if you say, that there are too many other things to fix. and a good fix would be probably some sort of binary diff or a diff showing all special characters (\n\r, tabs etc). both of which would be a lot of work.

JetpackDuba commented 1 year ago

It would be quite an overkill as it would be something very specific and it would require changing the internals of JGit (and even then, JGit behavior is intentional).

Unless it affects a lot of people, I'd mark it the issue as a "won't fix" and reopen it in case more users ask for it.