summaryrefslogtreecommitdiff
path: root/git/cmd.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/cmd.py')
-rw-r--r--git/cmd.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/git/cmd.py b/git/cmd.py
index b3274dd8..bd7d5b92 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -74,6 +74,9 @@ class Git(LazyMixin):
self.args = args
def __del__(self):
+ self.proc.stdout.close()
+ self.proc.stderr.close()
+
# did the process finish already so we have a return code ?
if self.proc.poll() is not None:
return
@@ -85,6 +88,8 @@ class Git(LazyMixin):
# try to kill it
try:
os.kill(self.proc.pid, 2) # interrupt signal
+ except OSError:
+ pass # ignore error when process already died
except AttributeError:
# try windows
# for some reason, providing None for stdout/stderr still prints something. This is why
@@ -101,6 +106,8 @@ class Git(LazyMixin):
:raise GitCommandError: if the return status is not 0"""
status = self.proc.wait()
+ self.proc.stdout.close()
+ self.proc.stderr.close()
if status != 0:
raise GitCommandError(self.args, status, self.proc.stderr.read())
# END status handling
@@ -236,7 +243,7 @@ class Git(LazyMixin):
if attr == '_version_info':
# We only use the first 4 numbers, as everthing else could be strings in fact (on windows)
version_numbers = self._call_process('version').split(' ')[2]
- self._version_info = tuple(int(n) for n in version_numbers.split('.')[:4])
+ self._version_info = tuple(int(n) for n in version_numbers.split('.')[:4] if n.isdigit())
else:
super(Git, self)._set_cache_(attr)
#END handle version info
@@ -316,6 +323,9 @@ class Git(LazyMixin):
if ouput_stream is True, the stdout value will be your output stream:
* output_stream if extended_output = False
* tuple(int(status), output_stream, str(stderr)) if extended_output = True
+
+ Note git is executed with LC_MESSAGES="C" to ensure consitent
+ output regardless of system language.
:raise GitCommandError:
@@ -333,6 +343,7 @@ class Git(LazyMixin):
# Start the process
proc = Popen(command,
+ env={"LC_MESSAGES": "C"},
cwd=cwd,
stdin=istream,
stderr=PIPE,
@@ -380,7 +391,10 @@ class Git(LazyMixin):
# END handle debug printing
if with_exceptions and status != 0:
- raise GitCommandError(command, status, stderr_value)
+ if with_extended_output:
+ raise GitCommandError(command, status, stderr_value, stdout_value)
+ else:
+ raise GitCommandError(command, status, stderr_value)
# Allow access to the command's status code
if with_extended_output:
@@ -410,12 +424,16 @@ class Git(LazyMixin):
@classmethod
def __unpack_args(cls, arg_list):
if not isinstance(arg_list, (list,tuple)):
+ if isinstance(arg_list, unicode):
+ return [arg_list.encode('utf-8')]
return [ str(arg_list) ]
outlist = list()
for arg in arg_list:
if isinstance(arg_list, (list, tuple)):
outlist.extend(cls.__unpack_args( arg ))
+ elif isinstance(arg_list, unicode):
+ outlist.append(arg_list.encode('utf-8'))
# END recursion
else:
outlist.append(str(arg))