def test_uncommit_to_null(self): tree = self.make_branch_and_tree('branch') tree.lock_write() revid = tree.commit('a revision') tree.unlock() uncommit.uncommit(tree.branch, tree=tree) self.assertEqual([], tree.get_parent_ids())
def test_post_uncommit_to_origin(self): tree = self.make_branch_and_memory_tree('branch') tree.lock_write() tree.add('') revid = tree.commit('a revision') tree.unlock() branch.Branch.hooks.install_named_hook('post_uncommit', self.capture_post_uncommit_hook, None) uncommit.uncommit(tree.branch) # with nothing left we should still get a notification, and # have the branch locked at notification time. self.assertEqual([('post_uncommit', None, tree.branch.base, 1, revid, 0, None, None, True)], self.hook_calls)
def test_pull_remember(self): """Pull changes from one branch to another and test parent location.""" t = self.get_transport() tree_a = self.make_branch_and_tree('branch_a') branch_a = tree_a.branch self.build_tree(['branch_a/a']) tree_a.add('a') tree_a.commit('commit a') tree_b = branch_a.controldir.sprout('branch_b').open_workingtree() branch_b = tree_b.branch tree_c = branch_a.controldir.sprout('branch_c').open_workingtree() branch_c = tree_c.branch self.build_tree(['branch_a/b']) tree_a.add('b') tree_a.commit('commit b') # reset parent parent = branch_b.get_parent() branch_b = branch.Branch.open('branch_b') branch_b.set_parent(None) self.assertEqual(None, branch_b.get_parent()) # test pull for failure without parent set out = self.run_bzr('pull', retcode=3, working_dir='branch_b') self.assertEqual( out, ('', 'brz: ERROR: No pull location known or specified.\n')) # test implicit --remember when no parent set, this pull conflicts self.build_tree(['branch_b/d']) tree_b.add('d') tree_b.commit('commit d') out = self.run_bzr('pull ../branch_a', retcode=3, working_dir='branch_b') self.assertEqual(out, ('', 'brz: ERROR: These branches have diverged.' ' Use the missing command to see how.\n' 'Use the merge command to reconcile them.\n')) tree_b = tree_b.controldir.open_workingtree() branch_b = tree_b.branch self.assertEqual(parent, branch_b.get_parent()) # test implicit --remember after resolving previous failure uncommit.uncommit(branch=branch_b, tree=tree_b) t.delete('branch_b/d') self.run_bzr('pull', working_dir='branch_b') # Refresh the branch object as 'pull' modified it branch_b = branch_b.controldir.open_branch() self.assertEqual(branch_b.get_parent(), parent) # test explicit --remember self.run_bzr('pull ../branch_c --remember', working_dir='branch_b') # Refresh the branch object as 'pull' modified it branch_b = branch_b.controldir.open_branch() self.assertEqual(branch_c.controldir.root_transport.base, branch_b.get_parent())
def test_post_uncommit_not_to_origin(self): tree = self.make_branch_and_memory_tree('branch') tree.lock_write() tree.add('') revid = tree.commit('first revision') revid2 = tree.commit('second revision') revid3 = tree.commit('third revision') tree.unlock() branch.Branch.hooks.install_named_hook('post_uncommit', self.capture_post_uncommit_hook, None) uncommit.uncommit(tree.branch, revno=2) # having uncommitted from up the branch, we should get the # before and after revnos and revids correctly. self.assertEqual([('post_uncommit', None, tree.branch.base, 3, revid3, 1, revid, None, True)], self.hook_calls)
def test_uncommit_bound(self): os.mkdir('a') a = BzrDirMetaFormat1().initialize('a') a.create_repository() a.create_branch() t_a = a.create_workingtree() t_a.commit('commit 1') t_a.commit('commit 2') t_a.commit('commit 3') b = t_a.branch.create_checkout('b').branch uncommit.uncommit(b) self.assertEqual(b.last_revision_info()[0], 2) self.assertEqual(t_a.branch.last_revision_info()[0], 2) # update A's tree to not have the uncommitted revision referenced. t_a.update() t_a.commit('commit 3b') self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b) b.pull(t_a.branch) uncommit.uncommit(b)
def test_post_uncommit_bound(self): master = self.make_branch('master') tree = self.make_branch_and_memory_tree('local') try: tree.branch.bind(master) except errors.UpgradeRequired: # cant bind this format, the test is irrelevant. return tree.lock_write() tree.add('') revid = tree.commit('a revision') tree.unlock() branch.Branch.hooks.install_named_hook('post_uncommit', self.capture_post_uncommit_hook, None) uncommit.uncommit(tree.branch) # with nothing left we should still get a notification, and # have the branch locked at notification time. self.assertEqual([('post_uncommit', tree.branch.base, master.base, 1, revid, 0, None, True, True)], self.hook_calls)
def setUp(self): self.reduceLockdirTimeout() super(TestReconcileWithIncorrectRevisionCache, self).setUp() t = self.get_transport() # we need a revision with two parents in the wrong order # which should trigger reinsertion. # and another with the first one correct but the other two not # which should not trigger reinsertion. # these need to be in different repositories so that we don't # trigger a reconcile based on the other case. # there is no api to construct a broken knit repository at # this point. if we ever encounter a bad graph in a knit repo # we should add a lower level api to allow constructing such cases. # first off the common logic: self.first_tree = self.make_branch_and_tree('wrong-first-parent') self.second_tree = self.make_branch_and_tree( 'reversed-secondary-parents') for t in [self.first_tree, self.second_tree]: t.commit('1', rev_id=b'1') uncommit(t.branch, tree=t) t.commit('2', rev_id=b'2') uncommit(t.branch, tree=t) t.commit('3', rev_id=b'3') uncommit(t.branch, tree=t) #second_tree = self.make_branch_and_tree('reversed-secondary-parents') # second_tree.pull(tree) # XXX won't copy the repo? repo_secondary = self.second_tree.branch.repository # now setup the wrong-first parent case repo = self.first_tree.branch.repository repo.lock_write() repo.start_write_group() inv = Inventory(revision_id=b'wrong-first-parent') inv.root.revision = b'wrong-first-parent' if repo.supports_rich_root(): root_id = inv.root.file_id repo.texts.add_lines((root_id, b'wrong-first-parent'), [], []) sha1 = repo.add_inventory(b'wrong-first-parent', inv, [b'2', b'1']) rev = Revision(timestamp=0, timezone=None, committer="Foo Bar <*****@*****.**>", message="Message", inventory_sha1=sha1, revision_id=b'wrong-first-parent') rev.parent_ids = [b'1', b'2'] repo.add_revision(b'wrong-first-parent', rev) repo.commit_write_group() repo.unlock() # now setup the wrong-secondary parent case repo = repo_secondary repo.lock_write() repo.start_write_group() inv = Inventory(revision_id=b'wrong-secondary-parent') inv.root.revision = b'wrong-secondary-parent' if repo.supports_rich_root(): root_id = inv.root.file_id repo.texts.add_lines((root_id, b'wrong-secondary-parent'), [], []) sha1 = repo.add_inventory( b'wrong-secondary-parent', inv, [b'1', b'3', b'2']) rev = Revision(timestamp=0, timezone=None, committer="Foo Bar <*****@*****.**>", message="Message", inventory_sha1=sha1, revision_id=b'wrong-secondary-parent') rev.parent_ids = [b'1', b'2', b'3'] repo.add_revision(b'wrong-secondary-parent', rev) repo.commit_write_group() repo.unlock()
def test_push_remember(self): """Push changes from one branch to another and test push location.""" transport = self.get_transport() tree_a = self.make_branch_and_tree('branch_a') branch_a = tree_a.branch self.build_tree(['branch_a/a']) tree_a.add('a') tree_a.commit('commit a') tree_b = branch_a.controldir.sprout('branch_b').open_workingtree() branch_b = tree_b.branch tree_c = branch_a.controldir.sprout('branch_c').open_workingtree() branch_c = tree_c.branch self.build_tree(['branch_a/b']) tree_a.add('b') tree_a.commit('commit b') self.build_tree(['branch_b/c']) tree_b.add('c') tree_b.commit('commit c') # initial push location must be empty self.assertEqual(None, branch_b.get_push_location()) # test push for failure without push location set out = self.run_bzr('push', working_dir='branch_a', retcode=3) self.assertEqual(out, ('', 'brz: ERROR: No push location known or specified.\n')) # test not remembered if cannot actually push self.run_bzr('push path/which/doesnt/exist', working_dir='branch_a', retcode=3) out = self.run_bzr('push', working_dir='branch_a', retcode=3) self.assertEqual( ('', 'brz: ERROR: No push location known or specified.\n'), out) # test implicit --remember when no push location set, push fails out = self.run_bzr('push ../branch_b', working_dir='branch_a', retcode=3) self.assertEqual(out, ('', 'brz: ERROR: These branches have diverged. ' 'See "brz help diverged-branches" for more information.\n')) # Refresh the branch as 'push' modified it branch_a = branch_a.controldir.open_branch() self.assertEqual(osutils.abspath(branch_a.get_push_location()), osutils.abspath(branch_b.controldir.root_transport.base)) # test implicit --remember after resolving previous failure uncommit.uncommit(branch=branch_b, tree=tree_b) transport.delete('branch_b/c') out, err = self.run_bzr('push', working_dir='branch_a') # Refresh the branch as 'push' modified it branch_a = branch_a.controldir.open_branch() path = branch_a.get_push_location() self.assertEqual(err, 'Using saved push location: %s\n' 'All changes applied successfully.\n' 'Pushed up to revision 2.\n' % urlutils.local_path_from_url(path)) self.assertEqual(path, branch_b.controldir.root_transport.base) # test explicit --remember self.run_bzr('push ../branch_c --remember', working_dir='branch_a') # Refresh the branch as 'push' modified it branch_a = branch_a.controldir.open_branch() self.assertEqual(branch_a.get_push_location(), branch_c.controldir.root_transport.base)