~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_bundle.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-29 17:07:26 UTC
  • mfrom: (1793.2.16 bundles)
  • Revision ID: pqm@pqm.ubuntu.com-20060629170726-bc2f3986d337be18
Clean up bundle command

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
class TestBundle(TestCaseInTempDir):
28
28
 
 
29
    def make_trees(self):
 
30
        grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
 
31
        grandparent_tree.commit('initial commit', rev_id='revision1')
 
32
        parent_bzrdir = grandparent_tree.bzrdir.sprout('parent')
 
33
        parent_tree = parent_bzrdir.open_workingtree()
 
34
        parent_tree.commit('next commit', rev_id='revision2')
 
35
        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
 
36
        branch_tree.commit('last commit', rev_id='revision3')
 
37
 
29
38
    def test_uses_parent(self):
30
39
        """Parent location is used as a basis by default"""
31
 
        
32
 
        parent_tree = BzrDir.create_standalone_workingtree('parent')
33
 
        parent_tree.commit('initial commit', rev_id='revision1')
34
 
        os.chdir('parent')
 
40
        self.make_trees()        
 
41
        os.chdir('grandparent')
35
42
        errmsg = self.run_bzr('bundle', retcode=3)[1]
36
43
        self.assertContainsRe(errmsg, 'No base branch known or specified')
37
 
        branch_tree = parent_tree.bzrdir.sprout('../branch').open_workingtree()
38
 
        branch_tree.commit('next commit', rev_id='revision2')
39
 
        branch_tree.commit('last commit', rev_id='revision3')
40
44
        os.chdir('../branch')
41
 
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
42
 
        self.assertEqual(br.revisions[0].revision_id, 'revision3')
43
 
        self.assertEqual(len(br.revisions), 2)
44
 
        self.assertEqual(br.revisions[1].revision_id, 'revision2')
 
45
        stdout, stderr = self.run_bzr('bundle')
 
46
        self.assertEqual(stderr.count('Using saved location'), 1)
 
47
        br = read_bundle(StringIO(stdout))
 
48
        self.assertRevisions(br, ['revision3'])
 
49
 
 
50
    def assertRevisions(self, bi, expected):
 
51
        self.assertEqual([r.revision_id for r in bi.revisions], expected)
45
52
 
46
53
    def test_uses_submit(self):
47
54
        """Submit location can be used and set"""
48
 
        
49
 
        submit_tree = BzrDir.create_standalone_workingtree('submit')
50
 
        submit_tree.commit('initial commit', rev_id='revision1')
51
 
        parent_tree = submit_tree.bzrdir.sprout('parent').open_workingtree()
52
 
        parent_tree.commit('next commit', rev_id='revision2')
53
 
        branch_tree = parent_tree.bzrdir.sprout('branch').open_workingtree()
54
 
        branch_tree.commit('last commit', rev_id='revision3')
 
55
        self.make_trees()        
55
56
        os.chdir('branch')
56
57
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
57
 
        self.assertEqual(br.revisions[0].revision_id, 'revision3')
58
 
        self.assertEqual(len(br.revisions), 1)
59
 
        br = read_bundle(StringIO(self.run_bzr('bundle', '../submit')[0]))
60
 
        self.assertEqual(len(br.revisions), 2)
 
58
        self.assertRevisions(br, ['revision3'])
 
59
        br = read_bundle(StringIO(self.run_bzr('bundle', '../grandparent')[0]))
 
60
        self.assertRevisions(br, ['revision3', 'revision2'])
61
61
        # submit location should be auto-remembered
62
62
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
63
 
        self.assertEqual(len(br.revisions), 2)
 
63
        self.assertRevisions(br, ['revision3', 'revision2'])
64
64
        self.run_bzr('bundle', '../parent')
65
65
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
66
 
        self.assertEqual(len(br.revisions), 2)
 
66
        self.assertRevisions(br, ['revision3', 'revision2'])
67
67
        self.run_bzr('bundle', '../parent', '--remember')
68
68
        br = read_bundle(StringIO(self.run_bzr('bundle')[0]))
69
 
        self.assertEqual(len(br.revisions), 1)
 
69
        self.assertRevisions(br, ['revision3'])
70
70
        err = self.run_bzr('bundle', '--remember', retcode=3)[1]
71
71
        self.assertContainsRe(err, 
72
72
                              '--remember requires a branch to be specified.')
 
73
 
 
74
    def test_revision_branch_interaction(self):
 
75
        self.make_trees()        
 
76
        os.chdir('branch')
 
77
        bi = read_bundle(StringIO(self.run_bzr('bundle', '../grandparent')[0]))
 
78
        self.assertRevisions(bi, ['revision3', 'revision2'])
 
79
        out = StringIO(self.run_bzr('bundle', '../grandparent', '-r', '-2')[0])
 
80
        bi = read_bundle(out)
 
81
        self.assertRevisions(bi, ['revision2'])
 
82
        bi = read_bundle(StringIO(self.run_bzr('bundle', '-r', '-2..-1')[0]))
 
83
        self.assertRevisions(bi, ['revision3'])
 
84
        self.run_bzr('bundle', '../grandparent', '-r', '-2..-1', retcode=3)