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.

Community
  • 1
  • 1
cardiff space man
  • 1,442
  • 14
  • 31

1 Answers1

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
David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
  • 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. – cardiff space man Aug 09 '14 at 10:26
  • 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. – David Ferenczy Rogožan Aug 10 '14 at 01:37
  • 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. – cardiff space man Aug 10 '14 at 09:56
  • 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. – David Ferenczy Rogožan Aug 10 '14 at 12:02
  • Please let me know, if it works for you, so I can correct my answer in a case there is some issue. – David Ferenczy Rogožan Aug 12 '14 at 22:46
  • Thank-you Mr. Ferenczy, this solution worked. I had a commit to try it out on and addp-hunk-edit.diff came up in notepad2, and Git recognized the changes I made through notepad2. – cardiff space man Aug 14 '14 at 09:25
  • Great, I'm pleased to hear that. Thanks for the info. BTW do you have to close the whole Notepad2 or is't enough to close just one tab opened by Git? (in case you have Notepad2 still running with opened files) I'm afraid Git waits until editor process is closed. – David Ferenczy Rogožan Aug 14 '14 at 09:31
  • Notepad2 is not tabbed. (Opinion/experiment: Are tabs really all that? why don't we have the window manager or OS do its job?) Each notepad2 window is its own process, enabling things like this to work in the obvious way. – cardiff space man Aug 14 '14 at 09:43
  • I see. I thought, Notepad2 is something very similar to Notepad++. So it's pointless in this case. – David Ferenczy Rogožan Aug 14 '14 at 12:00
  • And about tabs vs. windows: for me, tabs are definitely better, because for example now I have about 20 opened files in Notepad++. If I need to edit particular (already opened) file, I just move to Notepad++ window (`WIN + N`), press `CTRL + SHIFT + O`, write few characters from the filename I want to edit and press `ENTER`. Done. I have no idea how to easily do that in case of 20 different windows. I'm always trying to have as few windows as possible. – David Ferenczy Rogožan Aug 14 '14 at 12:07