Abby Fichtner
Abby Fichtner

Reputation: 2648

Cygwin git passing wrong path to my editor for commit messages

I'm using git under cygwin but it's not passing the correct path to my editor for commit messages.

I'm working in a test repository located on my drive at:

d:\X\git\myproject

in the cygwin terminal it shows this path as:

/cygdrive/d/X/git/myproject

When I commit without the -m flag (so that it opens up my editor for me to enter a message), my editor tries to write a file to the wrong path:

d:\cygdrive\d\x\git\myproject\.git\commit_editmsg

note the addition of "\cygdrive\d"

How can I make git pass the windows path (rather than the cygwin/unix path) to my editor?

Upvotes: 9

Views: 1361

Answers (3)

Felipe C.
Felipe C.

Reputation: 181

I had the same problem. Cygwin git would not pass the correct path to sublime 3 (It would not include the cygwin64 folder) I created the git-editor.sh folder, this is what I put in it:

#!/bin/sh
 /cygdrive/c/Program\ Files/Sublime\ Text\ 3/subl.exe $(cygpath --windows "${1}") -w

Then made this .sh file my core.editor

Upvotes: 1

Zombo
Zombo

Reputation: 1

#!/bin/dash -e
if [ "$1" ]
then k=$(cygpath -w "$1")
elif [ "$#" != 0 ]
then k=
fi
Notepad2 ${k+"$k"}
  1. If no path, pass no path

  2. If path is empty, pass empty path

  3. If path is not empty, convert to Windows format.

Then I set these variables:

export EDITOR=notepad2.sh
export GIT_EDITOR='dash /usr/local/bin/notepad2.sh'
  1. EDITOR allows script to work with Git

  2. GIT_EDITOR allows script to work with Hub commands

Source

Upvotes: 2

itchimus
itchimus

Reputation: 96

cygwin has a utility called cygpath which can be used to convert between cygwin and native Windows file paths. For instance:

$ cygpath --windows /cygdrive/d/X/git/myproject
D:\X\git\myproject

We're going to create a script which uses this utility to convert the path before passing it to your editor. We'll use emacs as an example, assuming it is installed at C:\emacs. Create a file called ~/bin/git-editor.sh:

#!/bin/sh
/cygdrive/c/emacs/bin/emacsclientw.exe $(cygpath --windows "${1}")

(since this is Windows, we don't need to set the executable flag on this file)

Now, set your git editor to point to this script:

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

Upvotes: 8

Related Questions