def run(self, merge_type=None, directory="."): from bzrlib.plugins.rewrite.rebase import RebaseState1, WorkingTreeRevisionRewriter from bzrlib.workingtree import WorkingTree wt = WorkingTree.open_containing(directory)[0] wt.lock_write() try: state = RebaseState1(wt) replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type) # Abort if there are any conflicts if len(wt.conflicts()) != 0: raise BzrCommandError( gettext( "There are still conflicts present. " "Resolve the conflicts and then run " "'bzr resolve' and try again." ) ) # Read plan file try: replace_map = state.read_plan()[1] except NoSuchFile: raise BzrCommandError(gettext("No rebase to continue")) oldrevid = state.read_active_revid() if oldrevid is not None: oldrev = wt.branch.repository.get_revision(oldrevid) replayer.commit_rebase(oldrev, replace_map[oldrevid][0]) finish_rebase(state, wt, replace_map, replayer) finally: wt.unlock()
def run(self, merge_type=None, directory="."): from bzrlib.plugins.rewrite.rebase import ( RebaseState1, rebase, WorkingTreeRevisionRewriter, ) from bzrlib.workingtree import WorkingTree wt = WorkingTree.open_containing(directory)[0] wt.lock_write() try: state = RebaseState1(wt) replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type) # Abort if there are any conflicts if len(wt.conflicts()) != 0: raise BzrCommandError("There are still conflicts present. " "Resolve the conflicts and then run " "'bzr resolve' and try again.") # Read plan file try: replace_map = state.read_plan()[1] except NoSuchFile: raise BzrCommandError("No rebase to continue") oldrevid = state.read_active_revid() if oldrevid is not None: oldrev = wt.branch.repository.get_revision(oldrevid) replayer.commit_rebase(oldrev, replace_map[oldrevid][0]) try: # Start executing plan from current Branch.last_revision() rebase(wt.branch.repository, replace_map, replayer) except ConflictsInTree: raise BzrCommandError("A conflict occurred replaying a commit." " Resolve the conflict and run 'bzr rebase-continue' or " "run 'bzr rebase-abort'.") # Remove plan file state.remove_plan() finally: wt.unlock()
def test_already_merged(self): """We need to use a merge base that makes sense. A | \ B D | \| C E Rebasing E on C should result in: A -> B -> C -> D' -> E' Ancestry: A: B: A C: A, B D: A E: A, B, D D': A, B, C E': A, B, C, D' """ oldwt = self.make_branch_and_tree("old") self.build_tree(['old/afile']) file("old/afile", "w").write("A\n" * 10) oldwt.add(["afile"]) oldwt.commit("base", rev_id="A") newwt = oldwt.bzrdir.sprout("new").open_workingtree() file("old/afile", "w").write("A\n"*10 + "B\n") oldwt.commit("bla", rev_id="B") file("old/afile", "w").write("A\n" * 10 + "C\n") oldwt.commit("bla", rev_id="C") self.build_tree(['new/bfile']) newwt.add(["bfile"]) file("new/bfile", "w").write("D\n") newwt.commit("bla", rev_id="D") file("new/afile", "w").write("E\n" + "A\n"*10 + "B\n") file("new/bfile", "w").write("D\nE\n") newwt.add_pending_merge("B") newwt.commit("bla", rev_id="E") newwt.branch.repository.fetch(oldwt.branch.repository) newwt.lock_write() replayer = WorkingTreeRevisionRewriter(newwt, RebaseState1(newwt)) replayer("D", "D'", ["C"]) newwt.unlock() oldrev = newwt.branch.repository.get_revision("D") newrev = newwt.branch.repository.get_revision("D'") self.assertEquals(["C"], newrev.parent_ids) newwt.lock_write() replayer = WorkingTreeRevisionRewriter(newwt, RebaseState1(newwt)) self.assertRaises(ConflictsInTree, replayer, "E", "E'", ["D'"]) newwt.unlock() self.assertEquals("E\n" + "A\n" * 10 + "C\n", open("new/afile", 'r').read()) newwt.set_conflicts(ConflictList()) oldrev = newwt.branch.repository.get_revision("E") replayer.commit_rebase(oldrev, "E'") newrev = newwt.branch.repository.get_revision("E'") self.assertEquals(["D'"], newrev.parent_ids) self.assertThat(newwt.branch, RevisionHistoryMatches(["A", "B", "C", "D'", "E'"]))