gornostal/Modific

Stray CR character after replace_modified_part command

Closed this issue · 24 comments

Unmodified file:
1

Deleting a line and saving the file:
2

Invoking the command replace_modified_part:
3

Note the spurious CR appearing at the end of the reverted line.

I am using Git for Windows 2.5. Changing "default_line_ending" has no effect.

Git settings, but seems to also have no effect:
core.autocrlf = true

@markusgritsch, can you create a gist with a file (or a part of it), where you see the issue?
Also, please provide your git version.

Thanks.

I already mentioned that I use Git for Windows 2.5. However, I also had the same behaviour with previous versions of Git.

I think the crucial thing to reproduce the bug is to have a file which is in the repository with Unix (LF) line endings which gets checked out on Windows with Windows (CR LF) line endigs. For example this file
https://github.com/nodemcu/nodemcu-firmware/blob/master/Makefile
has LF line endings in the repo (https://github.com/nodemcu/nodemcu-firmware/raw/master/Makefile) but my local clone of this file has CR LF line endings.

So here is an example with exactly that file:
1

Now, if I delete line 3
2

And then press CTRL+ALT+R
3

the spurious CR appears.

Thanks for looking into this.

Hehe, I was wondering what is Window 2.5.
I think I know how to fix it. I'll create a fix, then you verify it, because I don't have access to Windows machine right now.

Great, looking forward to it.

I just pushed commit to master.

No, this does not change anything. Note, even if I change join_lines() to return "", a spurious CR appears (of course without any text from the original line):

3

Made another fix. Hope that helps.

Unfortunately, still the same.

I just made another fix. And I'm pretty sure it will work.

Still no change. If it helps, when doing
git diff Makefile > tmp.diff
the file tmp.diff has Unix (LF) line endings.

OK. I'll get back to this when I get access to a Windows machine.

All right.

Hi gornostal, any chance you will take another look into this issue?

Sorry for the delay.
I'll try to find time for this today or tomorrow.

Thanks for the reminder!

Could not reproduce the bug today.

Here is what I did:

  1. downloaded and installed Git-2.6.3-64.bit.exe on Windows 7
  2. downloaded and installed ST 3
  3. git config --global core.autocrlf true
  4. git checkout https://github.com/nodemcu/nodemcu-firmware
  5. modified a few lines in Makefile
  6. pressed Ctrl+Alt+R
  7. Modific reverted lines just fine, no CR symbols in the end of the line

Did you delete some lines in the Makefile so that they were added back when pressing Ctrl+Alt+R?

Reverting works fine with modified lines and added lines. The problem appears only when deleting lines from the original file.

Oh.. I missed that in your description. Will try again today.

Have you been able to reproduce it?

Not yet. Got distracted at work that day.
Downloading virtual box...

I reproduced it and here is what I found out:

CR appears only if I use \r\n to join the lines.
When I change it to \n, it joins them just fine.

Can you find the line with "\r\n" in Modific.py and change that to \n, then let me know if it works for you?

If it does I will simply add a new config option to manually change line endings, because as it turns out, we cannot use windows line endings on windows in some cases like yours.

Checked in changes to issue-96 branch.
Will merge when @markusgritsch confirms it's working.

Yes, this seems to solve the issue, thanks!

But why add a "line_ending" configuration option? Who would need to set this to something else than \n?

It's good to hear it works.

I thought I could break the functionality for someone who needs \r\n, but maybe you are right. I'll use \n.

P.S. Thanks for being insistent :)

You are welcome ;) I like Modific a lot, and this was the only outstanding issue I had with it. Great that it's fixed now.

Concerning the config option: I think, it is unnecessary. Mind you: The problem with the stray \r characters appeard on a file, which had Windows (\r\n) line endings, and even there the config option has to be set to \n.

Besides: If it would be different from file to file, it would not be practicat to have to change the config option every time.