Windows: git doesn't use .gitconfig in home directory
Closed this issue · 4 comments
On Windows 7, in my home directory I have a .gitconfig with:
[alias]
lg = log --graph --pretty=...
Inside the gitsome shell:
$ git lg
git: 'lg' is not a git command. See 'git --help'.Did you mean this?
log
and
$ git config --global -l
fatal: unable to read config file 'C://.gitconfig': No such file or directory
So git (inside gitsome) is looking for the config file in c:/ instead of my home directory.
I've tracked the problem down to xonsh. In it's environ.py there is this function:
def windows_env_fixes(ctx):
"""Environment fixes for Windows. Operates in-place."""
# Windows default prompt doesn't work.
ctx['PROMPT'] = DEFAULT_PROMPT
# remove these bash variables which only cause problems.
for ev in ['HOME', 'OLDPWD']:
if ev in ctx:
del ctx[ev]
# Override path-related bash variables; on Windows bash uses
# /c/Windows/System32 syntax instead of C:\\Windows\\System32
# which messes up these environment variables for xonsh.
for ev in ['PATH', 'TEMP', 'TMP']:
if ev in os.environ:
ctx[ev] = os.environ[ev]
elif ev in ctx:
del ctx[ev]
ctx['PWD'] = _get_cwd()
So it's deleting the HOME environment variable, which then causes git to not be able to find .gitconfig.I've changed it locally on my machine to:
def windows_env_fixes(ctx):
"""Environment fixes for Windows. Operates in-place."""
# Windows default prompt doesn't work.
ctx['PROMPT'] = DEFAULT_PROMPT
# remove these bash variables which only cause problems.
for ev in ['HOME', 'OLDPWD']:
if ev in ctx:
path = subprocess.check_output(('cygpath', '-w', ctx[ev]))
ctx[ev] = path.decode().strip()
# Override path-related bash variables; on Windows bash uses
# /c/Windows/System32 syntax instead of C:\\Windows\\System32
# which messes up these environment variables for xonsh.
for ev in ['PATH', 'TEMP', 'TMP']:
if ev in os.environ:
ctx[ev] = os.environ[ev]
elif ev in ctx:
del ctx[ev]
ctx['PWD'] = _get_cwd()
which fixes it for me, but requires cygpath to be available (so not a generic fix). Reimplementing cygpath is apparently non-trivial (http://stackoverflow.com/questions/10884268/convert-posix-win-path-in-cygwin-python-w-o-calling-cygpath/10887350#10887350), but that is a problem for xonsh.
An alternative workaround is to create a .xonshrc in the home directory with this line:
$HOME = $USERPROFILE