7

I'm new to GIT. I downloaded GIT for Windows from a GitHub link a few days ago. I'm using the command line tool MinGW32. I'm not comfortable with the default editor so I've been trying to set up my favourite editor.

I followed the instructions here to use EditPad Pro as my editor. But I keep getting the following message:

Aborting commit due to empty commit message.

EditPad Pro opens a new instance. MinGW32 is waiting because I don't get the abort message until after I close EditPad Pro. When the editor opens, it opens with a blank file called COMMIT_EDITMSG. When I close the editor, the file saves to the main directory for the repo.

I found a clue in this answer, specifically this phrase:

[Vim] saves the file to .git/COMMIT_EDITMSG by default

If I do a Save As to save the file to the .git directory before closing the editor, then it works. However, there are two problems with that:

  1. I have to remember to Save As
  2. I don't get the helpful comments that Git adds by default to COMMIT_EDITMSG

The current config setting for core.editor is:

"'D:\Program Files\JGsoft\EditPadPro5\EditPad Pro.exe' //newinstance"

I'm not sure what the $* mentioned in the instructions is for, but I tried it with and without that and also assorted variations with and without single/double quotes. I tried setting the value in a shell script as well. At worst, it doesn't work at all (e.g. won't even open the editor) and at best it opens a blank file.

How do I get my editor to open with the file that Git created in the .git directory?

EDIT: I get the exact same results whether I use $* or not, and this answer says it's not needed. This Git Pro page makes mention of it when explaining how to set up external merge and diff tools, but makes no mention of it when explaining the core.editor config setting. Note: I also tried %*.

If the $* variable was needed (and missing), I would think that EditPad Pro would open with a blank Untitled file rather than a blank COMMIT_EDITMSG file in the current directory. The problem seems to be the path.

EDIT: I've done more experimenting. I have spaces in my file path and I thought that might be causing a problem. I cloned my repo into a new directory with no spaces in the name and fixed my config variables. It didn't solve the problem. But I noticed another problem. In some of my tests, the blank file that was loaded into the editor was named $@.

Community
  • 1
  • 1
toxalot
  • 9,829
  • 5
  • 33
  • 56
  • For the record, `/newinstance` is the [command line parameter](http://www.editpadpro.com/manual/commandline.html) that EditPad Pro uses *to start a new EditPad instance that the application can wait for*. Different editors have different ways to specify this. In other words, this parameter is specific to the editor not Git. – toxalot Dec 30 '12 at 08:06
  • Also note: The double slash (//newinstance) is needed in this context. Without it, EditPad Pro opens a blank file named *newinstance* in an existing instance. – toxalot Dec 30 '12 at 08:12

5 Answers5

6

There are several issues that can be causing confusion and problems.

  1. The Shell Special Variable

    If core.editor is set to the editor path and filename, then the $* variable is redundant and not needed. However, if the core.editor is set to a shell script, then the $* variable must be passed along to the editor.

    This is valid:

    $ git config --global core.editor "'D:/Path To/EditPadPro.exe' //newinstance"
    

    This is also valid:

    $ git config --global core.editor "'E:/Path To/editor.sh'"
    

    when editor.sh contains:

    #!/bin/sh
    "D:/Path To/EditPadPro.exe" //newinstance "$*"
    
  2. Spaces in File Names

    Filenames with spaces can be a pain. If the path/filename is quoted, then it isn't usually a problem. But when setting the value of core.editor you have to either

    escape the spaces like this:

    "E:/Path\ To/editor.sh"
    

    or quote it twice like this:

    "'E:/Path To/editor.sh'"
    

    Without the extra quotes (or backslash escapes), you will have no problem setting the value, but it will fail when it's used because the outer quotes are not part of the value.

    EDIT: Latter method (quoting twice) seems safer. See the edit at the bottom for more explanation.

  3. Windows Path Separator

    The filename that is being passed to the editor can be a relative path (i.e. .git/COMMIT_EDITMSG) or absolute path (i.e. e:/path to/.git/rebase-merge/git-rebase-todo), but in both cases it is using forward slashes as a path separator. Windows can usually accept forward slashes as a path separator, especially if the path is quoted. Perhaps the older version of EditPad Pro is unable to accept the forward slashes in combination with the hidden directory. A little bit of preprocessing can fix this.

    Note: Hardcoded paths with forward slashes and no hidden directory seem to work fine. Hardcoded paths with hidden directories and backslashes seem to work fine.

Final Solution

I'm not very experienced with shell scripting, but the following is now working for me.

The editor.sh file contains:

#!/bin/sh
fullpath=`echo "$*" | tr '/' '\\\'`
"D:/Program Files/JGsoft/EditPadPro5/EditPadPro.exe" //newinstance "$fullpath"

and the config is set like this:

$ git config --global core.editor "'E:/Path To/editor.sh'"

My copy of EditPad Pro 5.3.2 is now opening with the correct files already loaded, regardless of what git command launches the editor.

EDIT: I had to change the value of core.editor. I had used backslashes to escape spaces in the path and this opened the editor properly. However, when a GIt command passed a fielname with a relative path (beginning with a dot) to my shell script, the value of $* was $@ rather than the filename, which caused the editor to open with a blank file named $@. I thought I tested that combination, but apparently not. Using the quote twice method works.

toxalot
  • 9,829
  • 5
  • 33
  • 56
  • Excellent feedback, much more complete than my answer. +1 – VonC Dec 30 '12 at 08:39
  • Thanks. I put a lot of time and effort into figuring it out and writing it up. Figuring it out on my own was satisfying, but it feels good to be validated. More importantly, your vote earned me a hat. :) – toxalot Dec 30 '12 at 18:25
  • The "Git R done" hat... As a Git specialist, I can only appreciate: that hat fits you and this question. My hat off to you, sir. – VonC Dec 30 '12 at 20:20
2

$* is for "all other parameters": see "what does $* mean in a shell script"

If you forget $* in:

 "C:/Program Files/JGsoft/EditPadPro6/EditPadPro.exe" //newinstance "$*"

, you won't open your editor with the final parameter which is .git/COMMIT_EDITMSG.
that means you won't save by dfault your commit message where it should be saved (for git to use it).

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
1

I'm not sure whether the problem lies with EditPad Pro or MinGW32, but I found a workaround. If I pass in the path and file name, it works.

For example:

$ git config --global core.editor "'D:/Program Files/JGsoft/EditPadPro5/EditPadPro.exe' //newinstance '.git\COMMIT_EDITMSG'"

EditPad Pro will open with two files: a blank COMMIT_EDITMSG in the current directory and the COMMIT_EDITMSG from the .git directory. I can edit the .git one and save it. When I close the editor, the .git one is used as the commit message. The blank one is not saved anywhere and is completely ignored.

The backslash and single quotes in '.git\COMMIT_EDITMSG' are important. It won't work any other way. At first I thought maybe my old version of EditPad Pro didn't like the forward slashes, but I can pass in other file names using forward slashes in the path (with or without the quotes) and it works for them. I can only surmise that any other variation of COMMIT_EDITMSG is conflicting with what MinGW32 is already passing in.

Since the path is relative to the current directory, it should work no matter which repo I am committing.

EDIT: The above solution will only work for commits.

It doesn't help when the editor is used for other purposes such as an interactive rebase. See my other answer for the final solution.

Community
  • 1
  • 1
toxalot
  • 9,829
  • 5
  • 33
  • 56
0

The following works for me so far for commits:

$ git config --global core.editor "'C:/Program Files/Just Great Software/EditPad Pro 7/EditPadPro7.exe' '//wait'" --replace-all

This opens a new tab pointing to the correct file and waits for that tab to close before continuing. The --replace-all was added to clear stuff I had stuck in there from previous attempts to set it.

Tad Guski
  • 541
  • 5
  • 5
0

The solution in the chosen answer was very helpful.

I want to share a one-liner version based on it:

git config --global core.editor "callEditor(){ filepath=\`echo \"\$*\" | tr '/' '\\' 2> /dev/null\`; '**PathToYourEditorHere**' \"\$filepath\"; }; callEditor"
Marcs
  • 3,393
  • 4
  • 29
  • 39