def test_merge_bundle(self): from bzrlib.testament import Testament tree_a = self.make_branch_and_tree('branch_a') self.build_tree_contents([('branch_a/a', 'hello')]) tree_a.add('a') tree_a.commit('message') tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree() self.build_tree_contents([('branch_a/a', 'hey there')]) tree_a.commit('message') self.build_tree_contents([('branch_b/a', 'goodbye')]) tree_b.commit('message') self.run_bzr('bundle ../branch_a -o ../bundle', working_dir='branch_b') self.run_bzr('merge ../bundle', retcode=1, working_dir='branch_a') testament_a = Testament.from_revision(tree_a.branch.repository, tree_b.get_parent_ids()[0]) testament_b = Testament.from_revision(tree_b.branch.repository, tree_b.get_parent_ids()[0]) self.assertEqualDiff(testament_a.as_text(), testament_b.as_text()) tree_a.set_conflicts(conflicts.ConflictList()) tree_a.commit('message') # it is legal to attempt to merge an already-merged bundle err = self.run_bzr('merge ../bundle', working_dir='branch_a')[1] # but it does nothing self.assertFalse(tree_a.changes_from(tree_a.basis_tree()).has_changed()) self.assertEqual('Nothing to do.\n', err)
def test_merge_bundle(self): from bzrlib.testament import Testament tree_a = self.make_branch_and_tree('branch_a') self.build_tree_contents([('branch_a/a', 'hello')]) tree_a.add('a') tree_a.commit('message') tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree() self.build_tree_contents([('branch_a/a', 'hey there')]) tree_a.commit('message') self.build_tree_contents([('branch_b/a', 'goodbye')]) tree_b.commit('message') os.chdir('branch_b') self.run_bzr('bundle ../branch_a -o ../bundle') os.chdir('../branch_a') self.run_bzr('merge ../bundle', retcode=1) testament_a = Testament.from_revision(tree_a.branch.repository, tree_b.get_parent_ids()[0]) testament_b = Testament.from_revision(tree_b.branch.repository, tree_b.get_parent_ids()[0]) self.assertEqualDiff(testament_a.as_text(), testament_b.as_text()) tree_a.set_conflicts(ConflictList()) tree_a.commit('message') # it is legal to attempt to merge an already-merged bundle output = self.run_bzr('merge ../bundle')[1] # but it does nothing self.assertFalse( tree_a.changes_from(tree_a.basis_tree()).has_changed()) self.assertEqual('Nothing to do.\n', output)
def assertEqualSignature(self, repo, revision_id): """Assert a signature is stored correctly in repository.""" self.assertEqual( '-----BEGIN PSEUDO-SIGNED CONTENT-----\n' + Testament.from_revision(repo, revision_id).as_short_text() + '-----END PSEUDO-SIGNED CONTENT-----\n', repo.get_signature_text(revision_id))
def test_signed_commit(self): import bzrlib.gpg import bzrlib.commit as commit oldstrategy = bzrlib.gpg.GPGStrategy wt = self.make_branch_and_tree('.') branch = wt.branch wt.commit("base", allow_pointless=True, rev_id='A') self.assertFalse(branch.repository.has_signature_for_revision_id('A')) try: from bzrlib.testament import Testament # monkey patch gpg signing mechanism bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy conf = config.MemoryStack(''' gpg_signing_command=cat - create_signatures=always ''') commit.Commit(config_stack=conf).commit(message="base", allow_pointless=True, rev_id='B', working_tree=wt) def sign(text): return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text) self.assertEqual( sign( Testament.from_revision(branch.repository, 'B').as_short_text()), branch.repository.get_signature_text('B')) finally: bzrlib.gpg.GPGStrategy = oldstrategy
def test_signed_commit(self): import bzrlib.gpg import bzrlib.commit as commit oldstrategy = bzrlib.gpg.GPGStrategy wt = self.make_branch_and_tree('.') branch = wt.branch wt.commit("base", allow_pointless=True, rev_id='A') self.assertFalse(branch.repository.has_signature_for_revision_id('A')) try: from bzrlib.testament import Testament # monkey patch gpg signing mechanism bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy conf = config.MemoryStack(''' gpg_signing_command=cat - create_signatures=always ''') commit.Commit(config_stack=conf).commit( message="base", allow_pointless=True, rev_id='B', working_tree=wt) def sign(text): return bzrlib.gpg.LoopbackGPGStrategy(None).sign(text) self.assertEqual(sign(Testament.from_revision(branch.repository, 'B').as_short_text()), branch.repository.get_signature_text('B')) finally: bzrlib.gpg.GPGStrategy = oldstrategy
def test_pull_bundle(self): from bzrlib.testament import Testament # Build up 2 trees and prepare for a pull tree_a = self.make_branch_and_tree('branch_a') with open('branch_a/a', 'wb') as f: f.write('hello') tree_a.add('a') tree_a.commit('message') tree_b = tree_a.bzrdir.sprout('branch_b').open_workingtree() # Make a change to 'a' that 'b' can pull with open('branch_a/a', 'wb') as f: f.write('hey there') tree_a.commit('message') # Create the bundle for 'b' to pull self.run_bzr('bundle ../branch_b -o ../bundle', working_dir='branch_a') out, err = self.run_bzr('pull ../bundle', working_dir='branch_b') self.assertEqual(out, 'Now on revision 2.\n') self.assertEqual(err, ' M a\nAll changes applied successfully.\n') self.assertEqualDiff(tree_a.branch.last_revision(), tree_b.branch.last_revision()) testament_a = Testament.from_revision(tree_a.branch.repository, tree_a.get_parent_ids()[0]) testament_b = Testament.from_revision(tree_b.branch.repository, tree_b.get_parent_ids()[0]) self.assertEqualDiff(testament_a.as_text(), testament_b.as_text()) # it is legal to attempt to pull an already-merged bundle out, err = self.run_bzr('pull ../bundle', working_dir='branch_b') self.assertEqual(err, '') self.assertEqual(out, 'No revisions or tags to pull.\n')
def test_sign_existing_revision(self): wt = self.make_branch_and_tree('.') wt.commit("base", allow_pointless=True, rev_id='A') strategy = gpg.LoopbackGPGStrategy(None) repo = wt.branch.repository self.addCleanup(repo.lock_write().unlock) repo.start_write_group() repo.sign_revision('A', strategy) repo.commit_write_group() self.assertEqual( '-----BEGIN PSEUDO-SIGNED CONTENT-----\n' + Testament.from_revision(repo, 'A').as_short_text() + '-----END PSEUDO-SIGNED CONTENT-----\n', repo.get_signature_text('A'))
def test_sign_existing_revision(self): wt = self.make_branch_and_tree('.') wt.commit("base", allow_pointless=True, rev_id='A') strategy = gpg.LoopbackGPGStrategy(None) repo = wt.branch.repository self.addCleanup(repo.lock_write().unlock) repo.start_write_group() repo.sign_revision('A', strategy) repo.commit_write_group() self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' + Testament.from_revision(repo, 'A').as_short_text() + '-----END PSEUDO-SIGNED CONTENT-----\n', repo.get_signature_text('A'))
def test_sign_existing_revision(self): wt = self.make_branch_and_tree('.') branch = wt.branch wt.commit("base", allow_pointless=True, rev_id='A') from bzrlib.testament import Testament strategy = gpg.LoopbackGPGStrategy(None) branch.repository.lock_write() branch.repository.start_write_group() branch.repository.sign_revision('A', strategy) branch.repository.commit_write_group() branch.repository.unlock() self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' + Testament.from_revision(branch.repository, 'A').as_short_text() + '-----END PSEUDO-SIGNED CONTENT-----\n', branch.repository.get_signature_text('A'))
def test_sign_existing_revision(self): wt = self.make_branch_and_tree('.') branch = wt.branch wt.commit("base", allow_pointless=True, rev_id='A') from bzrlib.testament import Testament strategy = gpg.LoopbackGPGStrategy(None) branch.repository.lock_write() branch.repository.start_write_group() branch.repository.sign_revision('A', strategy) branch.repository.commit_write_group() branch.repository.unlock() self.assertEqual( '-----BEGIN PSEUDO-SIGNED CONTENT-----\n' + Testament.from_revision(branch.repository, 'A').as_short_text() + '-----END PSEUDO-SIGNED CONTENT-----\n', branch.repository.get_signature_text('A'))
def test_verify_revision_signatures(self): wt = self.make_branch_and_tree('.') wt.commit("base", allow_pointless=True, rev_id='A') wt.commit("second", allow_pointless=True, rev_id='B') strategy = gpg.LoopbackGPGStrategy(None) repo = wt.branch.repository self.addCleanup(repo.lock_write().unlock) repo.start_write_group() repo.sign_revision('A', strategy) repo.commit_write_group() self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' + Testament.from_revision(repo, 'A').as_short_text() + '-----END PSEUDO-SIGNED CONTENT-----\n', repo.get_signature_text('A')) self.assertEquals( [('A', gpg.SIGNATURE_VALID, None), ('B', gpg.SIGNATURE_NOT_SIGNED, None)], list(repo.verify_revision_signatures(['A', 'B'], strategy)))
def test_verify_revision_signatures(self): wt = self.make_branch_and_tree('.') wt.commit("base", allow_pointless=True, rev_id='A') wt.commit("second", allow_pointless=True, rev_id='B') strategy = gpg.LoopbackGPGStrategy(None) repo = wt.branch.repository self.addCleanup(repo.lock_write().unlock) repo.start_write_group() repo.sign_revision('A', strategy) repo.commit_write_group() self.assertEqual( '-----BEGIN PSEUDO-SIGNED CONTENT-----\n' + Testament.from_revision(repo, 'A').as_short_text() + '-----END PSEUDO-SIGNED CONTENT-----\n', repo.get_signature_text('A')) self.assertEqual([('A', gpg.SIGNATURE_VALID, None), ('B', gpg.SIGNATURE_NOT_SIGNED, None)], list( repo.verify_revision_signatures(['A', 'B'], strategy)))