Gitpython: Using gitpython on windows outside git bash raises an exception

Created on 5 Jul 2011  路  5Comments  路  Source: gitpython-developers/GitPython

Because "git.cmd" is in PATH and not "git"
I wrote an email to mailing list about it.

The exception:

import git
git.Git().help()

WindowsError Traceback (most recent call last)

C:Program FilesSupport Tools in ()

C:pythonlibsite-packagesgitpython-0.3.1-py2.6.egggitcmd.pyc in (_args, *_kwargs)
217 if name[:1] == '_':
218 raise AttributeError(name)
--> 219 return lambda _args, *_kwargs: self._call_process(name, _args, *_kwargs)
220
221 @property

C:pythonlibsite-packagesgitpython-0.3.1-py2.6.egggitcmd.pyc in _call_process(self, method, _args, _kwargs)
428 call.extend(args)
429
--> 430 return self.execute(call, *
_kwargs)
431
432 def _parse_object_header(self, header_line):

C:pythonlibsite-packagesgitpython-0.3.1-py2.6.egggitcmd.pyc in execute(self, command, istream, with_keep_cwd, with_extended_output, with_exceptions, as_process, output_stream, *_subprocess_kwargs)
307 stdout=PIPE,
308 close_fds=(os.name=='posix'),# unsupported on linux
--> 309 *_subprocess_kwargs
310 )
311 if as_process:

C:pythonpython26.zipsubprocess.py in init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
593 p2cread, p2cwrite,
594 c2pread, c2pwrite,
--> 595 errread, errwrite)
596
597 if mswindows:

C:pythonpython26.zipsubprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
802 env,
803 cwd,
--> 804 startupinfo)
805 except pywintypes.error, e:
806 # Translate pywintypes.error to WindowsError, which is

Fix

Changing line 427 in cmd.py from "git" to "git.cmd" solved this locally.
Need a better solution, e.g.

  • try: except WindowError:
  • check if platform.system() == "Windows"
  • search for git or git.cmd in PATH
  • etc.

Most helpful comment

You can now use a GIT_PYTHON_GIT_EXECUTABLE environment variable to specify which executable to use. Doing anything windows specific is not the right way, in the end git-python expects git to be in the path. If this is not the case though, the user may now specify where to find git specifically.

This is the excerpt from the docs

  • GIT_PYTHON_TRACE

    • If set to non-0, all executed git commands will be printed to stdout.

    • if set to _full_, the executed git command will be printed along with its output.

  • GIT_PYTHON_GIT_EXECUTABLE

    • If set, it should contain the full path to the git executable, e.g. _c:Program Files (x86)Gitbingit.exe_ on windows or _/usr/bin/git_ on linux.

All 5 comments

You can now use a GIT_PYTHON_GIT_EXECUTABLE environment variable to specify which executable to use. Doing anything windows specific is not the right way, in the end git-python expects git to be in the path. If this is not the case though, the user may now specify where to find git specifically.

This is the excerpt from the docs

  • GIT_PYTHON_TRACE

    • If set to non-0, all executed git commands will be printed to stdout.

    • if set to _full_, the executed git command will be printed along with its output.

  • GIT_PYTHON_GIT_EXECUTABLE

    • If set, it should contain the full path to the git executable, e.g. _c:Program Files (x86)Gitbingit.exe_ on windows or _/usr/bin/git_ on linux.

That's nice, but I still think that it's a reasonable request for gitpython to work with the way git works in default windows installation.

What I would need to know is why git.cmd, that is the ./cmd directory, is in your PATH, but not ./bin itself.
In my default installation, ./bin is in the PATH.
Or in other words, can you explain why the case you are talking about is indeed common, so that gitpython should support it ?
Currently your issue seems like a special case to me, which is why I am hesitant to do something about it, at least in the way you proposed.

Well, I downloaded git for windows from http://git-scm.com/download, and installed it on several windows servers.

In all of them, when choosing you want "git" to work from commandline as well (which I think is the default but am not sure), when I go to cmd immediately after installation and run:

echo %PATH%

I only get the c:Program FilesGitcmd directory.

This makes sense, because git.exe won't work from cmd without prior preparations, what git.cmd - the batch file - does.

So for instance, if I have a build script running from a Jenkins slave on my windows hosts, unless I perform some tweaks, it's going to have cmd in PATH, but not bin.

AFAIK these are the default settings so I don't think I'm a special case here.

However, if you find the ways I suggested to support this 'ugly', I will understand your being hesitant about them...
I admit the GIT_PYTHON_GIT_EXECUTABLE env var is not such a bad way to go.
What I would recommend - is to at least add this information in the message of the raised exception (instead of a cryptic WindowsError).

Thanks for the detailed description. I now see that in fact, I am the special case :).
Even though I have ./bin in my PATH, I also seem to have ./cmd in the PATH on system level. I don't know who put it there, but I assume it was the installer because I told it to put _all_ linux programs into the system path.

Apparently the default option just leaves you with the git.cmd though.

I will have to test whether starting git through a shell (which is cmd.exe in this case) will properly redirect stdin, stdout and stderr to git-python, as it is the case with git.exe.

If this works, I will be glad to put your something like your proposed solution into the cmd implementation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

niso120b picture niso120b  路  4Comments

sp-ricard-valverde picture sp-ricard-valverde  路  3Comments

aaronlelevier picture aaronlelevier  路  5Comments

pared picture pared  路  4Comments

malford picture malford  路  3Comments