| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a5db3d3 commit cf2335a
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,7 +62,8 @@ def safe_decode(s): | |||
| 62 | 62 | return s | |
| 63 | 63 | elif isinstance(s, bytes): | |
| 64 | 64 | return s.decode(defenc, 'replace') | |
| 65 | - raise TypeError('Expected bytes or text, but got %r' % (s,)) | ||
| 65 | + elif s is not None: | ||
| 66 | + raise TypeError('Expected bytes or text, but got %r' % (s,)) | ||
| 66 | 67 | ||
| 67 | 68 | ||
| 68 | 69 | def with_metaclass(meta, *bases): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,13 +37,9 @@ def __init__(self, command, status, stderr=None, stdout=None): | |||
| 37 | 37 | self.command = command | |
| 38 | 38 | ||
| 39 | 39 | def __unicode__(self): | |
| 40 | - ret = u"'%s' returned with exit code %s" % \ | ||
| 41 | - (u' '.join(safe_decode(i) for i in self.command), self.status) | ||
| 42 | - if self.stderr: | ||
| 43 | - ret += u"\nstderr: '%s'" % safe_decode(self.stderr) | ||
| 44 | - if self.stdout: | ||
| 45 | - ret += u"\nstdout: '%s'" % safe_decode(self.stdout) | ||
| 46 | - return ret | ||
| 40 | + cmdline = u' '.join(safe_decode(i) for i in self.command) | ||
| 41 | + return (u"'%s' returned with exit code %s\n stdout: '%s'\n stderr: '%s'" | ||
| 42 | + % (cmdline, self.status, safe_decode(self.stdout), safe_decode(self.stderr))) | ||
| 47 | 43 | ||
| 48 | 44 | ||
| 49 | 45 | class CheckoutError(Exception): | |
@@ -80,19 +76,20 @@ class UnmergedEntriesError(CacheError): | |||
| 80 | 76 | entries in the cache""" | |
| 81 | 77 | ||
| 82 | 78 | ||
| 83 | - class HookExecutionError(Exception): | ||
| 79 | + class HookExecutionError(UnicodeMixin, Exception): | ||
| 84 | 80 | """Thrown if a hook exits with a non-zero exit code. It provides access to the exit code and the string returned | |
| 85 | 81 | via standard output""" | |
| 86 | 82 | ||
| 87 | - def __init__(self, command, status, stdout, stderr): | ||
| 83 | + def __init__(self, command, status, stdout=None, stderr=None): | ||
| 88 | 84 | self.command = command | |
| 89 | 85 | self.status = status | |
| 90 | 86 | self.stdout = stdout | |
| 91 | 87 | self.stderr = stderr | |
| 92 | 88 | ||
| 93 | - def __str__(self): | ||
| 94 | - return ("'%s' hook returned with exit code %i\nstdout: '%s'\nstderr: '%s'" | ||
| 95 | - % (self.command, self.status, self.stdout, self.stderr)) | ||
| 89 | + def __unicode__(self): | ||
| 90 | + cmdline = u' '.join(safe_decode(i) for i in self.command) | ||
| 91 | + return (u"'%s' hook failed with %r\n stdout: '%s'\n stderr: '%s'" | ||
| 92 | + % (cmdline, self.status, safe_decode(self.stdout), safe_decode(self.stderr))) | ||
| 96 | 93 | ||
| 97 | 94 | ||
| 98 | 95 | class RepositoryDirtyError(Exception): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,8 +14,8 @@ | |||
| 14 | 14 | import os | |
| 15 | 15 | import subprocess | |
| 16 | 16 | ||
| 17 | - from git.util import IndexFileSHA1Writer | ||
| 18 | - from git.cmd import PROC_CREATIONFLAGS | ||
| 17 | + from git.util import IndexFileSHA1Writer, finalize_process | ||
| 18 | + from git.cmd import PROC_CREATIONFLAGS, handle_process_output | ||
| 19 | 19 | from git.exc import ( | |
| 20 | 20 | UnmergedEntriesError, | |
| 21 | 21 | HookExecutionError | |
@@ -71,21 +71,26 @@ def run_commit_hook(name, index): | |||
| 71 | 71 | env = os.environ.copy() | |
| 72 | 72 | env['GIT_INDEX_FILE'] = index.path | |
| 73 | 73 | env['GIT_EDITOR'] = ':' | |
| 74 | - cmd = subprocess.Popen(hp, | ||
| 75 | - env=env, | ||
| 76 | - stdout=subprocess.PIPE, | ||
| 77 | - stderr=subprocess.PIPE, | ||
| 78 | - cwd=index.repo.working_dir, | ||
| 79 | - close_fds=is_posix, | ||
| 80 | - creationflags=PROC_CREATIONFLAGS,) | ||
| 81 | - stdout, stderr = cmd.communicate() | ||
| 82 | - cmd.stdout.close() | ||
| 83 | - cmd.stderr.close() | ||
| 84 | - | ||
| 85 | - if cmd.returncode != 0: | ||
| 86 | - stdout = force_text(stdout, defenc) | ||
| 87 | - stderr = force_text(stderr, defenc) | ||
| 88 | - raise HookExecutionError(hp, cmd.returncode, stdout, stderr) | ||
| 74 | + try: | ||
| 75 | + cmd = subprocess.Popen(hp, | ||
| 76 | + env=env, | ||
| 77 | + stdout=subprocess.PIPE, | ||
| 78 | + stderr=subprocess.PIPE, | ||
| 79 | + cwd=index.repo.working_dir, | ||
| 80 | + close_fds=is_posix, | ||
| 81 | + creationflags=PROC_CREATIONFLAGS,) | ||
| 82 | + except Exception as ex: | ||
| 83 | + raise HookExecutionError(hp, ex) | ||
| 84 | + else: | ||
| 85 | + stdout = [] | ||
| 86 | + stderr = [] | ||
| 87 | + handle_process_output(cmd, stdout.append, stderr.append, finalize_process) | ||
| 88 | + stdout = ''.join(stdout) | ||
| 89 | + stderr = ''.join(stderr) | ||
| 90 | + if cmd.returncode != 0: | ||
| 91 | + stdout = force_text(stdout, defenc) | ||
| 92 | + stderr = force_text(stderr, defenc) | ||
| 93 | + raise HookExecutionError(hp, cmd.returncode, stdout, stderr) | ||
| 89 | 94 | # end handle return code | |
| 90 | 95 | ||
| 91 | 96 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments