diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2011-07-05 22:09:58 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2011-07-05 22:09:58 +0200 |
commit | 7dcb07947cd71f47b5e2e5f101d289e263506ca9 (patch) | |
tree | 0919e03e08db0edd1e1698a0249c3e15241f6e7a | |
parent | 1ddf05a78475a194ed1aa082d26b3d27ecc77475 (diff) | |
download | gitpython-7dcb07947cd71f47b5e2e5f101d289e263506ca9.tar.gz |
Implemented GIT_PYTHON_GIT_EXECUTABLE including test and docs
-rw-r--r-- | doc/source/changes.rst | 8 | ||||
-rw-r--r-- | doc/source/tutorial.rst | 14 | ||||
-rw-r--r-- | git/cmd.py | 17 | ||||
m--------- | git/ext/gitdb | 0 | ||||
-rw-r--r-- | git/test/test_git.py | 10 |
5 files changed, 41 insertions, 8 deletions
diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 587e7c0d..c5a7319b 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -7,7 +7,9 @@ Changelog * **git** command wrapper * Added ``version_info`` property which returns a tuple of integers representing the installed git version. - + + * 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. + * **Blob** Type * Added mode constants to ease the manual creation of blobs @@ -21,7 +23,9 @@ Changelog * Configuration file parsing is more robust. It should now be able to handle everything that the git command can parse as well. * The progress parsing was updated to support git 1.7.0.3 and newer. Previously progress was not enabled for the git command or only worked with ssh in case of older git versions. * Parsing of tags was improved. Previously some parts of the name could not be parsed properly. - * The rev-parse pure python implementation now handles branches correctly if they look like hexadecimal sha's. + * The rev-parse pure python implementation now handles branches correctly if they look like hexadecimal sha's. + * 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. 0.3.1 Beta 2 diff --git a/doc/source/tutorial.rst b/doc/source/tutorial.rst index a9a3f81d..c176ed0c 100644 --- a/doc/source/tutorial.rst +++ b/doc/source/tutorial.rst @@ -427,6 +427,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 ... ***************** @@ -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/ext/gitdb b/git/ext/gitdb -Subproject a5ed410aa0d3bed587214c3c017af2916b740da +Subproject 656a2e0b4da7d60ac638d1615751a89efb3a4ee diff --git a/git/test/test_git.py b/git/test/test_git.py index b9a0b617..2d38e0a8 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.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 |