diff options
author | Guido Günther <agx@sigxcpu.org> | 2012-07-03 11:48:21 +0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2012-07-28 16:27:40 +0200 |
commit | cd829c9437d42f3223fbf51e22b795d2fcc33d00 (patch) | |
tree | 34c6deac49a9c06b8c01fb10c5fbcc21ce31c7e2 /gbp | |
parent | 6e4138faae673bd3398b1c85829a41e348e40caf (diff) |
GitRepository: raise GitRepositoryError on git errors
Raise GitRepositoryError in cases where CommandExecFailed (from
GitCommand) was previously silently passed forward.
Heavily based on a patch by Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp')
-rw-r--r-- | gbp/git/repository.py | 23 | ||||
-rwxr-xr-x | gbp/scripts/buildpackage.py | 4 | ||||
-rwxr-xr-x | gbp/scripts/clone.py | 6 | ||||
-rw-r--r-- | gbp/scripts/common/pq.py | 5 | ||||
-rw-r--r-- | gbp/scripts/create_remote_repo.py | 2 | ||||
-rw-r--r-- | gbp/scripts/import_dsc.py | 2 | ||||
-rw-r--r-- | gbp/scripts/import_dscs.py | 2 | ||||
-rw-r--r-- | gbp/scripts/import_orig.py | 4 | ||||
-rwxr-xr-x | gbp/scripts/pq.py | 6 | ||||
-rwxr-xr-x | gbp/scripts/pull.py | 2 |
10 files changed, 35 insertions, 21 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index c9f3610..d581094 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -44,6 +44,8 @@ class GitRepository(object): @type _path: C{str} @ivar _bare: Whether this is a bare repository @type _bare: C{bool} + @raises GitRepositoryError: on git errors GitRepositoryError is raised by + all methods. """ def _check_bare(self): @@ -156,7 +158,11 @@ class GitRepository(object): @param extra_env: extra environment variables to set when running command @type extra_env: C{dict} """ - GitCommand(command, args, extra_env=extra_env, cwd=self.path)() + try: + GitCommand(command, args, extra_env=extra_env, cwd=self.path)() + except CommandExecFailed as excobj: + raise GitRepositoryError("Error running git %s: %s" % + (command, excobj)) @property def path(self): @@ -542,7 +548,7 @@ class GitRepository(object): try: self._git_command('tag', args.args) - except CommandExecFailed: + except GitRepositoryError: return False return True @@ -1418,7 +1424,11 @@ class GitRepository(object): try: if not os.path.exists(abspath): os.makedirs(abspath) - GitCommand("init", args.args, cwd=abspath)() + try: + GitCommand("init", args.args, cwd=abspath)() + except CommandExecFailed as excobj: + raise GitRepositoryError("Error running git init: %s" % excobj) + if description: with file(os.path.join(abspath, git_dir, "description"), 'w') as f: description += '\n' if description[-1] != '\n' else '' @@ -1470,7 +1480,12 @@ class GitRepository(object): if not os.path.exists(abspath): os.makedirs(abspath) - GitCommand("clone", args.args, cwd=abspath)() + try: + GitCommand("clone", args.args, cwd=abspath)() + except CommandExecFailed as excobj: + raise GitRepositoryError("Error running git clone: %s" % + excobj) + if not name: name = remote.rstrip('/').rsplit('/',1)[1] if (mirror or bare): diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index daa791c..53428b0 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -60,7 +60,7 @@ def git_archive(repo, cp, output_dir, treeish, comp_type, comp_level, with_submo else: git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts) - except CommandExecFailed: + except (GitRepositoryError, CommandExecFailed): gbp.log.err("Error generating submodules' archives") return False except OSError as err: @@ -564,7 +564,7 @@ def main(argv): 'GBP_SHA1': sha})() except CommandExecFailed: retval = 1 - except GbpError as err: + except (GbpError, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) retval = 1 diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py index f893344..65dbc20 100755 --- a/gbp/scripts/clone.py +++ b/gbp/scripts/clone.py @@ -24,7 +24,6 @@ import os, os.path from gbp.config import (GbpOptionParser, GbpOptionGroup) from gbp.deb.git import DebianGitRepository from gbp.git import (GitRepository, GitRepositoryError) -from gbp.command_wrappers import (Command, CommandExecFailed) from gbp.errors import GbpError import gbp.log @@ -100,8 +99,9 @@ def main(argv): repo.set_branch(options.debian_branch) - except CommandExecFailed: - retval = 1 + except GitRepositoryError as err: + gbp.log.err("Git command failed: %s" % err) + ret = 1 except GbpError as err: if len(err.__str__()): gbp.log.err(err) diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py index 0e0b75b..8a6a06c 100644 --- a/gbp/scripts/common/pq.py +++ b/gbp/scripts/common/pq.py @@ -23,8 +23,7 @@ import os import shutil import subprocess from gbp.git import (GitRepositoryError, GitRepository) -from gbp.command_wrappers import (Command, GitCommand, RunAtCommand, - CommandExecFailed) +from gbp.command_wrappers import (Command, GitCommand, RunAtCommand) from gbp.errors import GbpError import gbp.log from gbp.patch_series import (PatchSeries, Patch) @@ -138,7 +137,7 @@ def switch_to_pq_branch(repo, branch): if not repo.has_branch(pq_branch): try: repo.create_branch(pq_branch) - except CommandExecFailed: + except GitRepositoryError: raise GbpError("Cannot create patch-queue branch '%s'. Try 'rebase' instead." % pq_branch) diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py index 1e6b3f8..1ac30b5 100644 --- a/gbp/scripts/create_remote_repo.py +++ b/gbp/scripts/create_remote_repo.py @@ -358,7 +358,7 @@ def main(argv): except CommandExecFailed: retval = 1 - except GbpError as err: + except (GbpError, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) retval = 1 diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py index 15fa7ea..9fe345c 100644 --- a/gbp/scripts/import_dsc.py +++ b/gbp/scripts/import_dsc.py @@ -139,7 +139,7 @@ def apply_debian_patch(repo, unpack_dir, src, options, parents): commit=commit, sign=options.sign_tags, keyid=options.keyid) - except gbpc.CommandExecFailed: + except (gbpc.CommandExecFailed, GitRepositoryError): gbp.log.err("Failed to import Debian package") raise GbpError finally: diff --git a/gbp/scripts/import_dscs.py b/gbp/scripts/import_dscs.py index 3256534..cbd6b7a 100644 --- a/gbp/scripts/import_dscs.py +++ b/gbp/scripts/import_dscs.py @@ -149,7 +149,7 @@ def main(argv): for dsc in dscs[1:]: importer.importdsc(dsc) - except (GbpError, gbpc.CommandExecFailed) as err: + except (GbpError, gbpc.CommandExecFailed, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) ret = 1 diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index c7e2b18..7bb3a51 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -325,7 +325,7 @@ def main(argv): repo.set_branch(options.debian_branch) try: repo.merge(tag) - except gbpc.CommandExecFailed: + except GitRepositoryError: raise GbpError("Merge failed, please resolve.") if options.postimport: epoch = '' @@ -339,7 +339,7 @@ def main(argv): info = { 'version': "%s%s-1" % (epoch, version) } env = { 'GBP_BRANCH': options.debian_branch } gbpc.Command(options.postimport % info, extra_env=env, shell=True)() - except gbpc.CommandExecFailed: + except (gbpc.CommandExecFailed, GitRepositoryError): raise GbpError("Import of %s failed" % source.path) except GbpNothingImported as err: gbp.log.err(err) diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 44b8819..ed95e0f 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -136,7 +136,7 @@ def import_quilt_patches(repo, branch, series, tries, force): try: gbp.log.info("Trying to apply patches at '%s'" % commit) repo.create_branch(pq_branch, commit) - except CommandExecFailed: + except GitRepositoryError: raise GbpError("Cannot create patch-queue branch '%s'." % pq_branch) repo.set_branch(pq_branch) @@ -144,7 +144,7 @@ def import_quilt_patches(repo, branch, series, tries, force): gbp.log.debug("Applying %s" % patch.path) try: apply_and_commit_patch(repo, patch, patch.topic) - except (GbpError, GitRepositoryError, CommandExecFailed): + except (GbpError, GitRepositoryError): repo.set_branch(branch) repo.delete_branch(pq_branch) break @@ -251,7 +251,7 @@ def main(argv): switch_pq(repo, current) except CommandExecFailed: retval = 1 - except GbpError as err: + except (GbpError, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) retval = 1 diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py index adfe2bc..3f51749 100755 --- a/gbp/scripts/pull.py +++ b/gbp/scripts/pull.py @@ -127,7 +127,7 @@ def main(argv): repo.set_branch(current) except CommandExecFailed: retval = 1 - except GbpError as err: + except (GbpError, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) retval = 1 |