0

I need to split a hunk while doing git add -p. But the e option during the interaction doesn't work. I will explain why it doesn't work and inquire what I could do to make it work.

So my hunk might look like the code below. From other research I have learned that I should use the e option, and then my editor will come up with the hunk's lines, and I can delete the ones I don't want.

+ virtual bool fat() const {
+    return true;
+ }
+ virtual bool lazy() const {
+    return true;
+ }

Clearly I would want to commit just the fat method and leave the lazy method for another commit.

The problem is that I'm running Git from Cygwin and I have editor set as follows:

export EDITOR=/cygdrive/c/csm/notepad2/Notepad2.exe

By the way when I do commit messages this starts the editor perfectly.

When I inspect the editor's commandline it looks like

c:\csm\notepad2\Notepad2.exe /home/csm/path/to/my/code/.git/addp-hunk-edit.diff

Clearly this is one of those times when Windows and Cygwin are mixing like two non-mixy things, but I would like a solution that does bridge this gap, rather than having to use some Cygwin-based editor.

I believe the question cygwin and windows git - path confusion is opposite to mine because I use the Git that comes with Cygwin and I want to use a Windows helper tool with it, while that question seeks to integrate a Git that is native to Windows with a Cygwin shell environment.

1 Answer 1

1

I would recommend to set Git's editor instead of global system's editor, but it should work for both:

git config --global core.editor ~/bin/git-editor.sh

and create ~/bin/git-editor.sh containing something like:

/cygdrive/c/csm/notepad2/Notepad2.exe "`cygpath -w -a \"$*\"`"

cygpath converts paths between Windows and Unix format.

  • -w - convert from Unix to Windows format
  • -a - output absolute path
Sign up to request clarification or add additional context in comments.

10 Comments

So far this looks good. I found that the helper script shouldn't have a CRLF at the end. An LF is okay. I have only tested this by setting VISUAL and typing $VISUAL testfile.c as I don't have any Git activity to try it with. When I have had success I will accept the answer.
Well, any bash script shouldn't contain Windows' line endings (CRLF). Or better don't use Windows line endings with Cygwin at all. It causes issues on many places. Even .bashrc will fail with them. Use LF only.
AND: Your text didn't include any line ending so the fact that I ended up with CRLF certainly isn't your fault. I just found out that my Eclipse configuration is apparently defaulting to CRLF. Eclipse/CDT seems to punt many of these little pain points on Windows. Notepad2 at least makes the line ending highly visible and easily changed.
This is also about choosing a right tool to accomplish task. Eclipse is complex IDE, so it isn't the right tool to create one small shell script. Line endings depends on project setting there, I guess, and you didn't create new project for just one small shell script. Programmer's text editor (Notepad2 in your case) is the best tool to do that. That doesn't mean, that you can't create small shell script in Eclipse, of course.
Please let me know, if it works for you, so I can correct my answer in a case there is some issue.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.