~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2008-09-26 22:14:42 UTC
  • mto: This revision was merged to the branch mainline in revision 3747.
  • Revision ID: john@arbash-meinel.com-20080926221442-3r67j99sr9rwe9w0
Make message optional, don't check the memory flag directly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
class TestMissing(TestCaseWithTransport):
30
30
 
31
31
    def test_missing(self):
32
 
        def bzr(*args, **kwargs):
33
 
            return self.run_bzr(*args, **kwargs)[0]
34
32
        missing = "You are missing 1 revision(s):"
35
33
 
36
34
        # create a source branch
37
 
        os.mkdir('a')
38
 
        os.chdir('a')
39
 
        bzr('init')
40
 
        open('a', 'wb').write('initial\n')
41
 
        bzr('add a')
42
 
        bzr('commit -m inital')
 
35
        a_tree = self.make_branch_and_tree('a')
 
36
        self.build_tree_contents([('a/a', 'initial\n')])
 
37
        a_tree.add('a')
 
38
        a_tree.commit(message='initial')
43
39
 
44
40
        # clone and add a differing revision
45
 
        bzr('branch . ../b')
46
 
        os.chdir('../b')
47
 
        open('a', 'ab').write('more\n')
48
 
        bzr('commit -m more')
 
41
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
42
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
 
43
        b_tree.commit(message='more')
49
44
 
50
45
        # run missing in a against b
51
 
        os.chdir('../a')
52
46
        # this should not require missing to take out a write lock on a 
53
47
        # or b. So we take a write lock on both to test that at the same
54
48
        # time. This may let the test pass while the default branch is an
55
49
        # os-locking branch, but it will trigger failures with lockdir based
56
50
        # branches.
57
 
        branch_a = Branch.open('.')
58
 
        branch_a.lock_write()
59
 
        branch_b = Branch.open('../b')
60
 
        branch_b.lock_write()
 
51
        a_branch = a_tree.branch
 
52
        a_branch.lock_write()
 
53
        b_branch = b_tree.branch
 
54
        b_branch.lock_write()
 
55
        os.chdir('a')
61
56
        out,err = self.run_bzr('missing ../b', retcode=1)
62
57
        lines = out.splitlines()
63
58
        # we're missing the extra revision here
68
63
        # we do not expect any error output.
69
64
        self.assertEqual('', err)
70
65
        # unlock the branches for the rest of the test
71
 
        branch_a.unlock()
72
 
        branch_b.unlock()
 
66
        a_branch.unlock()
 
67
        b_branch.unlock()
73
68
 
74
69
        # get extra revision from b
75
 
        bzr('merge ../b')
76
 
        bzr('commit -m merge')
 
70
        a_tree.merge_from_branch(b_branch)
 
71
        a_tree.commit(message='merge')
77
72
 
78
73
        # compare again, but now we have the 'merge' commit extra
79
 
        lines = bzr('missing ../b', retcode=1).splitlines()
 
74
        lines = self.run_bzr('missing ../b', retcode=1)[0].splitlines()
80
75
        self.assertEqual("You have 1 extra revision(s):", lines[0])
81
76
        self.assertEqual(8, len(lines))
82
 
        lines2 = bzr('missing ../b --mine-only', retcode=1)
 
77
        lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
83
78
        lines2 = lines2.splitlines()
84
79
        self.assertEqual(lines, lines2)
85
 
        lines3 = bzr('missing ../b --theirs-only', retcode=1)
86
 
        lines3 = lines3.splitlines()
87
 
        self.assertEqual(0, len(lines3))
 
80
        lines3 = self.run_bzr('missing ../b --theirs-only', retcode=0)[0]
 
81
        self.assertEqualDiff('Other branch is up to date.\n', lines3)
88
82
 
89
83
        # relative to a, missing the 'merge' commit 
90
84
        os.chdir('../b')
91
 
        lines = bzr('missing ../a', retcode=1).splitlines()
 
85
        lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
92
86
        self.assertEqual(missing, lines[0])
93
87
        self.assertEqual(8, len(lines))
94
 
        lines2 = bzr('missing ../a --theirs-only', retcode=1)
 
88
        lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
95
89
        lines2 = lines2.splitlines()
96
90
        self.assertEqual(lines, lines2)
97
 
        lines3 = bzr('missing ../a --mine-only', retcode=1)
98
 
        lines3 = lines3.splitlines()
99
 
        self.assertEqual(0, len(lines3))
100
 
        lines4 = bzr('missing ../a --short', retcode=1)
 
91
        lines3 = self.run_bzr('missing ../a --mine-only', retcode=0)[0]
 
92
        self.assertEqualDiff('This branch is up to date.\n', lines3)
 
93
        lines4 = self.run_bzr('missing ../a --short', retcode=1)[0]
101
94
        lines4 = lines4.splitlines()
102
95
        self.assertEqual(4, len(lines4))
103
 
        lines5 = bzr('missing ../a --line', retcode=1)
 
96
        lines5 = self.run_bzr('missing ../a --line', retcode=1)[0]
104
97
        lines5 = lines5.splitlines()
105
98
        self.assertEqual(2, len(lines5))
106
 
        lines6 = bzr('missing ../a --reverse', retcode=1)
 
99
        lines6 = self.run_bzr('missing ../a --reverse', retcode=1)[0]
107
100
        lines6 = lines6.splitlines()
108
101
        self.assertEqual(lines6, lines)
109
 
        lines7 = bzr('missing ../a --show-ids', retcode=1)
 
102
        lines7 = self.run_bzr('missing ../a --show-ids', retcode=1)[0]
110
103
        lines7 = lines7.splitlines()
111
104
        self.assertEqual(11, len(lines7))
112
 
        lines8 = bzr('missing ../a --verbose', retcode=1)
 
105
        lines8 = self.run_bzr('missing ../a --verbose', retcode=1)[0]
113
106
        lines8 = lines8.splitlines()
114
107
        self.assertEqual("modified:", lines8[-2])
115
108
        self.assertEqual("  a", lines8[-1])
116
109
 
 
110
        os.chdir('../a')
 
111
        self.assertEqualDiff('Other branch is up to date.\n',
 
112
                             self.run_bzr('missing ../b --theirs-only')[0])
 
113
 
117
114
        # after a pull we're back on track
118
 
        bzr('pull')
119
 
        self.assertEqual("Branches are up to date.\n", bzr('missing ../a'))
 
115
        b_tree.pull(a_branch)
 
116
        self.assertEqualDiff("Branches are up to date.\n",
 
117
                             self.run_bzr('missing ../b')[0])
 
118
        os.chdir('../b')
 
119
        self.assertEqualDiff('Branches are up to date.\n',
 
120
                             self.run_bzr('missing ../a')[0])
 
121
        # If you supply mine or theirs you only know one side is up to date
 
122
        self.assertEqualDiff('This branch is up to date.\n',
 
123
                             self.run_bzr('missing ../a --mine-only')[0])
 
124
        self.assertEqualDiff('Other branch is up to date.\n',
 
125
                             self.run_bzr('missing ../a --theirs-only')[0])
120
126
 
121
127
    def test_missing_check_last_location(self):
122
128
        # check that last location shown as filepath not file URL
123
129
 
124
130
        # create a source branch
125
 
        os.mkdir('a')
126
 
        os.chdir('a')
127
 
        wt = self.make_branch_and_tree('.')
 
131
        wt = self.make_branch_and_tree('a')
128
132
        b = wt.branch
129
 
        self.build_tree(['foo'])
 
133
        self.build_tree(['a/foo'])
130
134
        wt.add('foo')
131
135
        wt.commit('initial')
132
136
 
 
137
        os.chdir('a')
133
138
        location = osutils.getcwd() + '/'
134
139
 
135
140
        # clone
137
142
 
138
143
        # check last location
139
144
        lines, err = self.run_bzr('missing', working_dir='../b')
140
 
        self.assertEquals('Using last location: %s\n'
 
145
        self.assertEquals('Using saved parent location: %s\n'
141
146
                          'Branches are up to date.\n' % location,
142
147
                          lines)
143
148
        self.assertEquals('', err)