diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-08-26 13:59:43 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-08-26 14:14:36 +0200 |
commit | 99e770304ffb0b8df5088d2e94c09ab59cd3f27c (patch) | |
tree | d554727e085b1c7d48ffa90dc3ea07ef63d59203 | |
parent | bf46e26ff985802277fa500a8ecc515acc5da093 (diff) |
import_orig: Properly abort merge on rollbacks
If merging fails we need to call "git merge --abort"
-rw-r--r-- | gbp/git/repository.py | 6 | ||||
-rw-r--r-- | gbp/scripts/import_orig.py | 22 |
2 files changed, 26 insertions, 2 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 60656652..08e29d2c 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -453,6 +453,12 @@ class GitRepository(object): args.add(commit) self._git_command("merge", args.args) + def abort_merge(self): + """ + Abort a merge + """ + self._git_command("merge", ["--abort"]) + def is_fast_forward(self, from_branch, to_branch): """ Check if an update I{from from_branch} to I{to_branch} would be a fast diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index cbe5986d..8c51a5f8 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -86,6 +86,8 @@ class ImportOrigDebianGitRepository(DebianGitRepository): gbp.log.warning("Failed to rev-parse %s: %s" % (refname, err)) elif action == 'delete': pass + elif action == 'abortmerge': + pass else: raise GbpError("Unknown action %s for %s %s" % (action, reftype, refname)) self.rollbacks.append((refname, reftype, action, sha)) @@ -102,6 +104,9 @@ class ImportOrigDebianGitRepository(DebianGitRepository): def rrr_tag(self, tagname, action='delete'): return self.rrr(tagname, action, 'tag') + def rrr_merge(self, commit, action='abortmerge'): + return self.rrr(commit, action, 'commit') + def rollback(self): """ Perform a complete rollback @@ -121,6 +126,9 @@ class ImportOrigDebianGitRepository(DebianGitRepository): elif action == 'reset' and reftype == 'branch': gbp.log.info('Rolling back branch %s by resetting it to %s' % (name, sha)) self.update_ref("refs/heads/%s" % name, sha, msg="gbp import-orig: failure rollback of %s" % name) + elif action == 'abortmerge': + gbp.log.info('Rolling back failed merge of %s' % name) + self.abort_merge() else: raise GitRepositoryError("Don't know how to %s %s %s" % (action, reftype, name)) except GitRepositoryError as e: @@ -146,6 +154,16 @@ class ImportOrigDebianGitRepository(DebianGitRepository): self.rrr_branch(branch, 'delete') return ret + def merge(self, *args, **kwargs): + commit = args[0] if args else kwargs['commit'] + try: + return super(ImportOrigDebianGitRepository, self).merge(*args, **kwargs) + except GitRepositoryError: + # Only cleanup in the error case to undo working copy + # changes. Resetting the refs handles the other cases. + self.rrr_merge(commit) + raise + def prepare_pristine_tar(archive, pkg, version): """ @@ -359,7 +377,7 @@ def debian_branch_merge_by_merge(repo, tag, version, options): try: repo.merge(tag) except GitRepositoryError: - raise GbpError("Merge failed, please resolve.") + raise GbpError("Automatic merge failed.") repo.set_branch(branch) @@ -612,7 +630,7 @@ def main(argv): # Make sure the very last line as an error message gbp.log.err("Rolled back changes after import error.") except Exception as e: - gbp.log.error("Automatic rollback failed: %s" % e) + gbp.log.error("%s" % e) gbp.log.error("Clean up manually and please report a bug: %s" % repo.rollback_errors) |