~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: 2006-05-30 04:44:48 UTC
  • mto: (1711.2.26 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1734.
  • Revision ID: john@arbash-meinel.com-20060530044448-81612e2e57c3991f
Update documentation and TODO for compare_trees

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
# -*- coding: utf-8 -*-
3
 
# vim: encoding=utf-8
4
 
#
5
 
# This program is free software; you can redistribute it and/or modify
6
 
# it under the terms of the GNU General Public License as published by
7
 
# the Free Software Foundation; either version 2 of the License, or
8
 
# (at your option) any later version.
9
 
#
10
 
# This program is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
# GNU General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License
16
 
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
 
19
 
"""Black-box tests for bzr missing."""
 
1
"""Black-box tests for bzr missing.
 
2
"""
20
3
 
21
4
import os
22
5
 
23
 
from bzrlib import osutils
24
 
 
25
6
from bzrlib.branch import Branch
26
 
from bzrlib.tests import TestCaseWithTransport
27
 
 
28
 
 
29
 
class TestMissing(TestCaseWithTransport):
 
7
from bzrlib.tests import TestCaseInTempDir
 
8
 
 
9
 
 
10
class TestMissing(TestCaseInTempDir):
30
11
 
31
12
    def test_missing(self):
32
13
        missing = "You are missing 1 revision(s):"
33
14
 
34
15
        # create a source branch
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')
 
16
        os.mkdir('a')
 
17
        os.chdir('a')
 
18
        self.capture('init')
 
19
        open('a', 'wb').write('initial\n')
 
20
        self.capture('add a')
 
21
        self.capture('commit -m inital')
39
22
 
40
23
        # clone and add a differing revision
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')
 
24
        self.capture('branch . ../b')
 
25
        os.chdir('../b')
 
26
        open('a', 'ab').write('more\n')
 
27
        self.capture('commit -m more')
44
28
 
45
29
        # run missing in a against b
 
30
        os.chdir('../a')
46
31
        # this should not require missing to take out a write lock on a 
47
32
        # or b. So we take a write lock on both to test that at the same
48
33
        # time. This may let the test pass while the default branch is an
49
34
        # os-locking branch, but it will trigger failures with lockdir based
50
35
        # branches.
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')
56
 
        out,err = self.run_bzr('missing ../b', retcode=1)
 
36
        branch_a = Branch.open('.')
 
37
        branch_a.lock_write()
 
38
        branch_b = Branch.open('../b')
 
39
        branch_b.lock_write()
 
40
        out,err = self.run_bzr('missing', '../b', retcode=1)
57
41
        lines = out.splitlines()
58
42
        # we're missing the extra revision here
59
43
        self.assertEqual(missing, lines[0])
63
47
        # we do not expect any error output.
64
48
        self.assertEqual('', err)
65
49
        # unlock the branches for the rest of the test
66
 
        a_branch.unlock()
67
 
        b_branch.unlock()
 
50
        branch_a.unlock()
 
51
        branch_b.unlock()
68
52
 
69
53
        # get extra revision from b
70
 
        a_tree.merge_from_branch(b_branch)
71
 
        a_tree.commit(message='merge')
 
54
        self.capture('merge ../b')
 
55
        self.capture('commit -m merge')
72
56
 
73
57
        # compare again, but now we have the 'merge' commit extra
74
 
        lines = self.run_bzr('missing ../b', retcode=1)[0].splitlines()
 
58
        lines = self.capture('missing ../b', retcode=1).splitlines()
75
59
        self.assertEqual("You have 1 extra revision(s):", lines[0])
76
60
        self.assertEqual(8, len(lines))
77
 
        lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
 
61
        lines2 = self.capture('missing ../b --mine-only', retcode=1)
78
62
        lines2 = lines2.splitlines()
79
63
        self.assertEqual(lines, lines2)
80
 
        lines3 = self.run_bzr('missing ../b --theirs-only', retcode=0)[0]
81
 
        self.assertEqualDiff('Other branch is up to date.\n', lines3)
 
64
        lines3 = self.capture('missing ../b --theirs-only', retcode=1)
 
65
        lines3 = lines3.splitlines()
 
66
        self.assertEqual(0, len(lines3))
82
67
 
83
68
        # relative to a, missing the 'merge' commit 
84
69
        os.chdir('../b')
85
 
        lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
 
70
        lines = self.capture('missing ../a', retcode=1).splitlines()
86
71
        self.assertEqual(missing, lines[0])
87
72
        self.assertEqual(8, len(lines))
88
 
        lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
 
73
        lines2 = self.capture('missing ../a --theirs-only', retcode=1)
89
74
        lines2 = lines2.splitlines()
90
75
        self.assertEqual(lines, lines2)
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]
 
76
        lines3 = self.capture('missing ../a --mine-only', retcode=1)
 
77
        lines3 = lines3.splitlines()
 
78
        self.assertEqual(0, len(lines3))
 
79
        lines4 = self.capture('missing ../a --short', retcode=1)
94
80
        lines4 = lines4.splitlines()
95
81
        self.assertEqual(4, len(lines4))
96
 
        lines5 = self.run_bzr('missing ../a --line', retcode=1)[0]
 
82
        lines5 = self.capture('missing ../a --line', retcode=1)
97
83
        lines5 = lines5.splitlines()
98
84
        self.assertEqual(2, len(lines5))
99
 
        lines6 = self.run_bzr('missing ../a --reverse', retcode=1)[0]
 
85
        lines6 = self.capture('missing ../a --reverse', retcode=1)
100
86
        lines6 = lines6.splitlines()
101
87
        self.assertEqual(lines6, lines)
102
 
        lines7 = self.run_bzr('missing ../a --show-ids', retcode=1)[0]
 
88
        lines7 = self.capture('missing ../a --show-ids', retcode=1)
103
89
        lines7 = lines7.splitlines()
104
90
        self.assertEqual(11, len(lines7))
105
 
        lines8 = self.run_bzr('missing ../a --verbose', retcode=1)[0]
 
91
        lines8 = self.capture('missing ../a --verbose', retcode=1)
106
92
        lines8 = lines8.splitlines()
107
93
        self.assertEqual("modified:", lines8[-2])
108
94
        self.assertEqual("  a", lines8[-1])
109
95
 
110
 
        os.chdir('../a')
111
 
        self.assertEqualDiff('Other branch is up to date.\n',
112
 
                             self.run_bzr('missing ../b --theirs-only')[0])
113
 
 
 
96
        
114
97
        # after a pull we're back on track
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])
126
 
 
127
 
    def test_missing_check_last_location(self):
128
 
        # check that last location shown as filepath not file URL
129
 
 
130
 
        # create a source branch
131
 
        wt = self.make_branch_and_tree('a')
132
 
        b = wt.branch
133
 
        self.build_tree(['a/foo'])
134
 
        wt.add('foo')
135
 
        wt.commit('initial')
136
 
 
137
 
        os.chdir('a')
138
 
        location = osutils.getcwd() + '/'
139
 
 
140
 
        # clone
141
 
        b.bzrdir.sprout('../b')
142
 
 
143
 
        # check last location
144
 
        lines, err = self.run_bzr('missing', working_dir='../b')
145
 
        self.assertEquals('Using saved parent location: %s\n'
146
 
                          'Branches are up to date.\n' % location,
147
 
                          lines)
148
 
        self.assertEquals('', err)
 
98
        self.capture('pull')
 
99
        self.assertEqual("Branches are up to date.\n", 
 
100
                         self.capture('missing ../a'))
 
101