From b38020ae17ed9f83af75ce176e96267dcce6ecbd Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Fri, 13 Jun 2008 19:40:14 +0200 Subject: Improved the GIT_PYTHON_TRACE=full output format It now also shows stderr if there was any on it, and only shows stdout if there was any output. Also added a '->' between the command and the return value as a visual clue. --- lib/git/cmd.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/git/cmd.py') diff --git a/lib/git/cmd.py b/lib/git/cmd.py index cf0f066d..1eed1f84 100644 --- a/lib/git/cmd.py +++ b/lib/git/cmd.py @@ -107,6 +107,10 @@ class Git(MethodMissingMixin): status = proc.wait() proc.stdout.close() + if proc.stderr: + stderr_value = proc.stderr.read() + proc.stderr.close() + # Strip off trailing whitespace by default if not with_raw_output: stdout_value = stdout_value.rstrip() @@ -118,7 +122,12 @@ class Git(MethodMissingMixin): % (str(command), status)) if GIT_PYTHON_TRACE == 'full': - print "%s %d: '%s'" % (command, status, stdout_value) + if stderr_value: + print "%s -> %d: '%s' !! '%s'" % (command, status, stdout_value, stderr_value) + elif stdout_value: + print "%s -> %d: '%s'" % (command, status, stdout_value) + else: + print "%s -> %d" % (command, status) # Allow access to the command's status code if with_status: -- cgit v1.2.1 From 0aa1ce356c7c3d53d6ee035b4c7bcf425e108cdc Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Fri, 13 Jun 2008 20:10:01 +0200 Subject: Added a with_keep_cwd option When executing commands, if the with_keep_cwd option is specified, the current working directory will be set to os.getcwd() instead of the directory containing the .git directory. --- lib/git/cmd.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lib/git/cmd.py') diff --git a/lib/git/cmd.py b/lib/git/cmd.py index 1eed1f84..8a3de181 100644 --- a/lib/git/cmd.py +++ b/lib/git/cmd.py @@ -56,6 +56,7 @@ class Git(MethodMissingMixin): with_stderr=False, with_exceptions=False, with_raw_output=False, + with_keep_cwd=False, ): """ Handles executing the command on the shell and consumes and returns @@ -79,6 +80,9 @@ class Git(MethodMissingMixin): ``with_raw_output`` Whether to avoid stripping off trailing whitespace. + ``with_keep_cwd`` + Whether to use the current working directory from os.getcwd(). + Returns str(output) # with_status = False (Default) tuple(int(status), str(output)) # with_status = True @@ -94,9 +98,15 @@ class Git(MethodMissingMixin): else: stderr = subprocess.PIPE + # Allow the user to have the command executed in their working dir. + if with_keep_cwd: + cwd = os.getcwd() + else: + cwd=self.git_dir + # Start the process proc = subprocess.Popen(command, - cwd=self.git_dir, + cwd=cwd, stdin=istream, stderr=stderr, stdout=subprocess.PIPE @@ -183,6 +193,7 @@ class Git(MethodMissingMixin): with_stderr = kwargs.pop("with_stderr", None) with_exceptions = kwargs.pop("with_exceptions", None) with_raw_output = kwargs.pop("with_raw_output", None) + with_keep_cwd = kwargs.pop("with_keep_cwd", None) # Prepare the argument list opt_args = self.transform_kwargs(**kwargs) @@ -198,4 +209,5 @@ class Git(MethodMissingMixin): with_stderr = with_stderr, with_exceptions = with_exceptions, with_raw_output = with_raw_output, + with_keep_cwd = with_keep_cwd, ) -- cgit v1.2.1