Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get COMMIT_EDITMSG to open from the correct location?

Tags:

git

mingw32

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 $@.

like image 344
toxalot Avatar asked Dec 28 '12 10:12

toxalot


2 Answers

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.

like image 144
toxalot Avatar answered Oct 21 '22 09:10

toxalot


$* 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).

like image 29
VonC Avatar answered Oct 21 '22 10:10

VonC