summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2011-07-05 22:09:58 +0200
committerSebastian Thiel <byronimo@gmail.com>2011-07-05 22:27:01 +0200
commitf1a2a4c611bc1f27bd1b63c26847ea74e18caddc (patch)
treed8ea4c9c347a029fd1318ef2599c29c9e227a0a8
parent6507e4e14337a929d4f3986a90efd8674d963a3f (diff)
downloadgitpython-f1a2a4c611bc1f27bd1b63c26847ea74e18caddc.tar.gz
Implemented GIT_PYTHON_GIT_EXECUTABLE including test and docs
-rw-r--r--doc/source/changes.rst3
-rw-r--r--doc/source/tutorial.rst14
-rw-r--r--git/cmd.py17
-rw-r--r--git/test/test_cmd.py10
4 files changed, 38 insertions, 6 deletions
diff --git a/doc/source/changes.rst b/doc/source/changes.rst
index 5564cfd7..ad0f2530 100644
--- a/doc/source/changes.rst
+++ b/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 ###
diff --git a/doc/source/tutorial.rst b/doc/source/tutorial.rst
index 5530cedd..4dcfad4a 100644
--- a/doc/source/tutorial.rst
+++ b/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 ...
*****************
diff --git a/git/cmd.py b/git/cmd.py
index b3ca0f48..63a7134e 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -17,9 +17,6 @@ from subprocess import (
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 @@ __all__ = ('Git', )
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 @@ class Git(LazyMixin):
: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 @@ class Git(LazyMixin):
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 @@ class Git(LazyMixin):
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)
diff --git a/git/test/test_cmd.py b/git/test/test_cmd.py
index b9a0b617..2d38e0a8 100644
--- a/git/test/test_cmd.py
+++ b/git/test/test_cmd.py
@@ -98,3 +98,13 @@ class TestGit(TestBase):
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