Skip to content
Browse files

Implemented GIT_PYTHON_GIT_EXECUTABLE including test and docs

  • Loading branch information...
1 parent 6507e4e commit f1a2a4c611bc1f27bd1b63c26847ea74e18caddc @Byron Byron committed Jul 5, 2011
Showing with 38 additions and 6 deletions.
  1. +3 −0 doc/source/changes.rst
  2. +14 −0 doc/source/tutorial.rst
  3. +11 −6 git/cmd.py
  4. +10 −0 git/test/test_cmd.py
View
3 doc/source/changes.rst
@@ -27,6 +27,9 @@ NEXT
* ### Git Cmd ###
* Added ``version_info`` property to git command, returning a tuple of version numbers.
+ * Added GIT_PYTHON_GIT_EXECUTABLE environment variable, which can be used to set the desired git executable to be used. despite of what would be found in the path.
+ * GIT_PYTHON_TRACE is now set on class level of the Git type, previously it was a module level global variable.
+ * GIT_PYTHON_GIT_EXECUTABLE is a class level variable as well.
* ### Exceptions ###
View
14 doc/source/tutorial.rst
@@ -412,6 +412,20 @@ The special notion ``git.command(flag=True)`` will create a flag without value l
If ``None`` is found in the arguments, it will be dropped silently. Lists and tuples passed as arguments will be unpacked recursively to individual arguments. Objects are converted to strings using the str(...) function.
+Git Command Debugging and Customization
+***************************************
+
+Using environment variables, you can further adjust the behaviour of the git command.
+
+* **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)\\Git\\bin\\git.exe* on windows or */usr/bin/git* on linux.
+
And even more ...
*****************
View
17 git/cmd.py
@@ -17,9 +17,6 @@
PIPE
)
-# Enables debugging of GitPython's git commands
-GIT_PYTHON_TRACE = os.environ.get("GIT_PYTHON_TRACE", False)
-
execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output',
'with_exceptions', 'as_process',
'output_stream' )
@@ -29,6 +26,7 @@
def dashify(string):
return string.replace('_', '-')
+
class Git(LazyMixin):
"""
The Git class manages communication with the Git binary.
@@ -50,6 +48,13 @@ class Git(LazyMixin):
# The size in bytes read from stdout when copying git's output to another stream
max_chunk_size = 1024*64
+ # Enables debugging of GitPython's git commands
+ GIT_PYTHON_TRACE = os.environ.get("GIT_PYTHON_TRACE", False)
+
+ # Provide the full path to the git executable. Otherwise it assumes git is in the path
+ GIT_PYTHON_GIT_EXECUTABLE = os.environ.get("GIT_PYTHON_GIT_EXECUTABLE", 'git')
+
+
class AutoInterrupt(object):
"""Kill/Interrupt the stored process instance once this instance goes out of scope. It is
used to prevent processes piling up in case iterators stop reading.
@@ -311,7 +316,7 @@ def execute(self, command,
:note:
If you add additional keyword arguments to the signature of this method,
you must update the execute_kwargs tuple housed in this module."""
- if GIT_PYTHON_TRACE and not GIT_PYTHON_TRACE == 'full':
+ if self.GIT_PYTHON_TRACE and not self.GIT_PYTHON_TRACE == 'full':
print ' '.join(command)
# Allow the user to have the command executed in their working dir.
@@ -358,7 +363,7 @@ def execute(self, command,
proc.stdout.close()
proc.stderr.close()
- if GIT_PYTHON_TRACE == 'full':
+ if self.GIT_PYTHON_TRACE == 'full':
cmdstr = " ".join(command)
if stderr_value:
print "%s -> %d; stdout: '%s'; stderr: '%s'" % (cmdstr, status, stdout_value, stderr_value)
@@ -445,7 +450,7 @@ def _call_process(self, method, *args, **kwargs):
ext_args = self.__unpack_args([a for a in args if a is not None])
args = opt_args + ext_args
- call = ["git", dashify(method)]
+ call = [self.GIT_PYTHON_GIT_EXECUTABLE, dashify(method)]
call.extend(args)
return self.execute(call, **_kwargs)
View
10 git/test/test_cmd.py
@@ -98,3 +98,13 @@ def test_version(self):
for n in v:
assert isinstance(n, int)
#END verify number types
+
+ def test_cmd_override(self):
+ prev_cmd = self.git.GIT_PYTHON_GIT_EXECUTABLE
+ try:
+ # set it to something that doens't exist, assure it raises
+ type(self.git).GIT_PYTHON_GIT_EXECUTABLE = os.path.join("some", "path", "which", "doesn't", "exist", "gitbinary")
+ self.failUnlessRaises(OSError, self.git.version)
+ finally:
+ type(self.git).GIT_PYTHON_GIT_EXECUTABLE = prev_cmd
+ #END undo adjustment

0 comments on commit f1a2a4c

Please sign in to comment.
Something went wrong with that request. Please try again.