views:

880

answers:

3

When I try to commit the first revision to my git repository (git commit) from Cygwin, I'm getting an error in gvim which says "Unable to open swap file for "foo\.git\COMMIT_EDITMSG" [New Directory]. I think it might be some sort of permission problem, but I've tried removing the read-only flag from the folder, as well as recursively adjusting the owner (using the windows property tab, not chown under Cygwin) to be the account I'm running under, without any luck. If I change the default editor to notepad, I get "The system cannot find the file specified", even though the file (COMMIT_EDITMSG) does exist and even contains:

# Please enter the commit message for your changes.
# (Comment lines starting with '#' will not be included)
# etc...

How can I troubleshoot this problem further?

+1  A: 

Unable to open swap file for "foo\.git\COMMIT_EDITMSG" [New Directory].

Looks like the git commit is passing the file path as a Windows path, not a POSIX path. note the \ in the message.

gvim is going to try to open `foo.gitCOMMIT_EDITMSG", which doesn't exist.

I don't use git, but I imagine it uses an environment var similar to SVN_EDITOR. You may need to wrap the editing session with a small script that uses cygpath to change the file path from Windows to Posix separators.

#!/bin/bash
gvim "$(cygpath --unix "${1}")"

Caveat Emptor, untested.

Ken Gentle
A: 

Trying Ken G's script does not help me. I can see the value in a script like this, however simply manually typing

gvim /cygdrive/d/Projects/foo/.git/COMMIT_EDITMSG

yields the same result from gvim. One other peculiarity I have now noticed is that gvim's titlebar says

COMMIT_EDITMSG (d:\cygdrive\d\Projects\foo\.git)

which is clearly an invalid path (there's no actual "cygdrive" folder on my D drive. I get a similar result when using the vim program built into cygwin, so I don't think its a gvim problem, but rather some issue with cygwin itself.

Terence Lewis
cygdrive is a cygwin artifact to allow for the access of "letter" drives without having to mount them.I don't think that is the problem.
Ken Gentle
After reading through the options for "cygpath", I changed your script to say gvim "$(cygpath --windows "${1}")", which seems better but still not 100%, because I now get: "Unable to open swap file for "D:\Projects\foo\.git\COMMIT_EDITMSG^M" [New File]". Why is the "^M" appearing on the end?
Terence Lewis
On the '^M', I'd guess that the file was edited with Windows line endings (cr/lf) instead of unix line endings (lf)Are you using the cygwin distribution of gvim or an independently installed version?
Ken Gentle
Are you using the git commit '-template=<file>' option or the `commit.template` configuration variable?
Ken Gentle
I'm using an independently installed version of gvim. My commit command is "git commit", so I assume it's using commit.template. Also, I did not create COMMIT_EDITMSG manually - I think it was created when I called "git add ."
Terence Lewis
My bridging script does not have any line ending on that line - it's only a 2 line script and that's the last line in the file. I went back and checked the line ending on the first line using cygwin's vim - still no luck.
Terence Lewis
A: 

I faced the same issue first time but I found out that this is normal. Only I don't remember how to deal with Vim. I found solution in that link: http://vim.runpaint.org/basics/quitting-vim/. I used the vim command :x that resulted in saving my comment & committing modifcation. You may read about this integration between Git & Vim through this link: http://vim.runpaint.org/extending/integrating-vim-with-git/.

Waheed Sayed