-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue where diff preview was broken on mac #365
Conversation
bin/git-forgit
Outdated
@@ -137,10 +137,10 @@ _forgit_diff() { | |||
# oldfile\0 | |||
# We have to do a two-step sed -> tr pipe because OSX's sed implementation does | |||
# not support the null-character directly. | |||
get_files="echo {} | sed 's/\\\\s*\\\\[.]\\\\s*//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'" | |||
get_files="echo {} | sed -e 's/^[[:space:]]*\\\\[[A-Z]\\\\][[:space:]]*//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, I changed it to "Remove everything that looks like a capital letter in brackets and a bunch of spaces following it"
Please sanity check if you agree that this makes sense.
I was seeing the pattern
[M] somefile.txt
[M] another[file].txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does the trick for me:
get_files="echo {} | sed -e 's/^[[:space:]]*\\\\[[A-Z0-9]*\\\\][[:space:]]*//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'"
The previous [A-Z]
did not match the R100
for renamed files.
I can confirm that files with normal name, files with spaces in the name and files with brackets in the name all work on this branch. preview_cmd="$get_files | xargs -0 -I% echo '%'" The preview displays a list of the contained files in the change then. For a modified file, it displays just the single filename. For a renamed file, it should display both filenames, the old and the new one. In my case it displays:
So the As I found out, this is the case since #354 already, so it wasn't introduced in this PR. However, I think we should fix it in this PR. |
bin/git-forgit
Outdated
@@ -137,10 +137,10 @@ _forgit_diff() { | |||
# oldfile\0 | |||
# We have to do a two-step sed -> tr pipe because OSX's sed implementation does | |||
# not support the null-character directly. | |||
get_files="echo {} | sed 's/\\\\s*\\\\[.]\\\\s*//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'" | |||
get_files="echo {} | sed -e 's/^[[:space:]]*\\\\[[A-Z]\\\\][[:space:]]*//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does the trick for me:
get_files="echo {} | sed -e 's/^[[:space:]]*\\\\[[A-Z0-9]*\\\\][[:space:]]*//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'"
The previous [A-Z]
did not match the R100
for renamed files.
And I am extremely looking forward to covering these cases in a unit test. :-) |
@carlfriedrich 100% on the unit tests, so many regressions in this area.. Can you send me the exact "steps to repro" for your R100 case? I will run it on my mac and ensure your xargs suggestion works then update this PR |
@cjappl Just call |
@carlfriedrich would you please run through the test cases again. I took your suggestion, plus one extra modification that was necessary (.* around the arrow, matching get_file). |
bin/git-forgit
Outdated
@@ -137,10 +137,10 @@ _forgit_diff() { | |||
# oldfile\0 | |||
# We have to do a two-step sed -> tr pipe because OSX's sed implementation does | |||
# not support the null-character directly. | |||
get_files="echo {} | sed 's/\\\\s*\\\\[.]\\\\s*//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'" | |||
get_files="echo {} | sed -e 's/^[[:space:]]*\\\\[[A-Z0-9]*\\\\][[:space:]]*//' | sed 's/.*-> //' | tr '\\\n' '\\\0'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still does not work for me when diffing renamed files that were added. To reproduce:
- mv LICENSE LICENSE1
- git add .
- gd --staged
The preview will look like LICENSE1 has been added. This can be fixed like this:
get_files="echo {} | sed -e 's/^[[:space:]]*\\\\[[A-Z0-9]*\\\\][[:space:]]*//' | sed 's/.*-> //' | tr '\\\n' '\\\0'" | |
get_files="echo {} | sed -e 's/^[[:space:]]*\\\\[[A-Z0-9]*\\\\][[:space:]]*//' | sed 's/.*-> //' | tr '\\\n' '\\\0'" | |
get_files="echo {} | sed -e 's/^[[:space:]]*\\\\[[A-Z0-9]*\\\\][[:space:]]*//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'" |
The second sed command is what has changed here. I realized that I accidentally modified it with #354. Sorry you for that and another strong yes for unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I see what you're seeing, but your suggestion doesn't work on my mac. In my current code I have on this branch, I get this:
Your suggestion leads to a blank preview (on both ubuntu and mac):
That is using this line:
get_files="echo {} | sed -e 's/^[[:space:]]*\\\\[[A-Z0-9]*\\\\][[:space:]]*//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'"
I realize my "working" version says "file added" at the top, but I'm not sure how it is supposed to look. Can you post a screenshot of what the working version looks like on your machine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without my change it looks like the first one. With the change, it looks like this for me:
That the diff is empty is correct, since the content of the file did not change. Could you check how this behaved before #354 for you? My suggestion simply adds back the code that has been replaced in #354 by accident, so it surprises me that this would break something. What happens when you add a line to the file aswell? Looks like this for me:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I cannot explain it but after going in and copy/pasting from the original pre-#345 version (which is identical to the code you pasted above) I can confirm this works on both Mac and Ubunutu. I pushed to this branch.
Please test the test cases again :) Thanks for the help as always
I also noticed that files with a leading white space fail to get a preview. This seems to have been the case before your changes and even before #354. So we could leave this open for a follow up PR IMO. Other than this and the change I've suggested above, this is working fine for me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for me as expected now. That is, there are still some file names that do not work, but that never actually worked. The ones I've found so far are file names that start with a white space (probably because we remove leading white space in the sed
command) and files that have a backslash in their name (probably because it being interpreted as an escape character).
I think we can only fixes those by implementing a completely new approach, so clearly out of scope for this PR. So approved from my side.
Thanks @cjappl!
Works for me! |
@cjappl Please add a note in the final commit message that this also fixes diff preview for renames, which was broken since forgit-24.03.0. |
@cjappl Didn't read my last comment? That's why I prefer squashing before merging. :-/ |
Sorry I missed it, I had the page loaded before merging and I didn't see it. |
@carlfriedrich I'm going to do a release to get this out to the package managers, do you want me to mention this in the release notes: "fixes diff preview for renames" Currently the "auto generated" release notes are:
Normally I haven't varied from the auto generated, but in this case I could add a line to be:
|
@cjappl Yep, that would be great, thanks a lot! |
@carlfriedrich No problem. Apologies again on missing your comment. I'll do that release now. |
Closes #362
I need one of my favorite linux pals (@sandr01d , @wfxr , @carlfriedrich ) to ensure this still works on your favorite linux distro.
The test cases I would recommend:
my[test]file.txt
)I have checked on my mac and docker image and everything seems happy.
Check list
Description
Type of change
Test environment