~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-10-16 21:31:35 UTC
  • mfrom: (3363.19.4 fix-iter-changes)
  • Revision ID: pqm@pqm.ubuntu.com-20081016213135-0115pw9c95l2dyxq
PreviewTree.iter_changes accepts all standard parameters (abentley)

Show diffs side-by-side

added added

removed removed

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