views:

139

answers:

2

I am using:

I have an environment variable looking like an absolute path (/path/to/dir) but I'm using it to construct a git URL. At some point, it's getting translated to C:/Program Files/Git/path/to/dir. It seems like Python is at fault:

In a git bash shell:

$ export VAR=/path/to/dir
$ echo $VAR
/path/to/dir
$ python
>>> import os
>>> os.environ['VAR']
'C:/Program Files/Git/path/to/dir'

git bash is not translating the path, but Python is?

In a Windows Command Prompt, Python gets it right:

C:\>set VAR=/path/to/dir
C:\>echo %VAR%
/path/to/dir

C:\>python
>>> import os
>>> os.environ['VAR']
'/path/to/dir'

Can anyone explain what's going on here? And how can I prevent the translation in a bash shell?

EDIT: I should add that my python script runs on OS X and Windows, so if anyone does have a solution it would be good if worked on both platforms.

+1  A: 

My guess would be that this is not python at fault, but the git bash shell.
Maybe the git bash shell is lying to you when you look at the variable.
Or, try to not put the first / and add it again later (if translation does not occurs).

If I try with cygwin, it works:

$ export test="/bin"
$ python
>>> import os
>>> os.environ["test"]
'/bin'
slurdge
Interesting... it doesn't translate with 2 leading slashes either. This might be better for me anyway. Since I can compose a git repo URL using `ssh://host//path/to/repo.git` instead of `host://path/to/repo.git`. Quite rightly, git complains that it doesn't know about protocol 'host' with the second form. How bizarre!
Steve Folly
+1  A: 

The console you get from msysgit is probably modified for git user's needs, from my POV, it is only useful for simple tasks and to access git command line not to develop and run python scripts (you are using a Python installation for Windows in a shell installed for a specific application, that doesn't sound good).

You should install Cygwin and his python package (and even git package if you want) to get a correct POSIX environment with binaries and libraries prepared for it.

KurzedMetal