1
# Copyright (C) 2005 Canonical Ltd
2
# -*- coding: utf-8 -*-
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.
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.
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
19
"""Black-box tests for bzr missing."""
1
"""Black-box tests for bzr missing.
23
from bzrlib import osutils
25
6
from bzrlib.branch import Branch
26
from bzrlib.tests import TestCaseWithTransport
29
class TestMissing(TestCaseWithTransport):
7
from bzrlib.tests import TestCaseInTempDir
9
class TestMissing(TestCaseInTempDir):
31
10
def test_missing(self):
32
11
missing = "You are missing 1 revision(s):"
34
13
# create a source branch
35
a_tree = self.make_branch_and_tree('a')
36
self.build_tree_contents([('a/a', 'initial\n')])
38
a_tree.commit(message='initial')
17
open('a', 'wb').write('initial\n')
19
self.capture('commit -m inital')
40
21
# 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')
22
self.capture('branch . ../b')
24
open('a', 'ab').write('more\n')
25
self.capture('commit -m more')
45
# run missing in a against b
46
# this should not require missing to take out a write lock on a
47
# or b. So we take a write lock on both to test that at the same
48
# time. This may let the test pass while the default branch is an
49
# os-locking branch, but it will trigger failures with lockdir based
51
a_branch = a_tree.branch
53
b_branch = b_tree.branch
56
out,err = self.run_bzr('missing ../b', retcode=1)
57
lines = out.splitlines()
29
lines = self.capture('missing ../b', retcode=1).splitlines()
58
30
# we're missing the extra revision here
59
31
self.assertEqual(missing, lines[0])
60
# and we expect 8 lines of output which we trust at the moment to be
62
32
self.assertEqual(8, len(lines))
63
# we do not expect any error output.
64
self.assertEqual('', err)
65
# unlock the branches for the rest of the test
69
34
# get extra revision from b
70
a_tree.merge_from_branch(b_branch)
71
a_tree.commit(message='merge')
35
self.capture('merge ../b')
36
self.capture('commit -m merge')
73
38
# compare again, but now we have the 'merge' commit extra
74
lines = self.run_bzr('missing ../b', retcode=1)[0].splitlines()
39
lines = self.capture('missing ../b', retcode=1).splitlines()
75
40
self.assertEqual("You have 1 extra revision(s):", lines[0])
76
41
self.assertEqual(8, len(lines))
77
lines2 = self.run_bzr('missing ../b --mine-only', retcode=1)[0]
42
lines2 = self.capture('missing ../b --mine-only', retcode=1)
78
43
lines2 = lines2.splitlines()
79
44
self.assertEqual(lines, lines2)
80
lines3 = self.run_bzr('missing ../b --theirs-only', retcode=1)[0]
45
lines3 = self.capture('missing ../b --theirs-only', retcode=1)
81
46
lines3 = lines3.splitlines()
82
47
self.assertEqual(0, len(lines3))
84
49
# relative to a, missing the 'merge' commit
86
lines = self.run_bzr('missing ../a', retcode=1)[0].splitlines()
51
lines = self.capture('missing ../a', retcode=1).splitlines()
87
52
self.assertEqual(missing, lines[0])
88
53
self.assertEqual(8, len(lines))
89
lines2 = self.run_bzr('missing ../a --theirs-only', retcode=1)[0]
54
lines2 = self.capture('missing ../a --theirs-only', retcode=1)
90
55
lines2 = lines2.splitlines()
91
56
self.assertEqual(lines, lines2)
92
lines3 = self.run_bzr('missing ../a --mine-only', retcode=1)[0]
57
lines3 = self.capture('missing ../a --mine-only', retcode=1)
93
58
lines3 = lines3.splitlines()
94
59
self.assertEqual(0, len(lines3))
95
lines4 = self.run_bzr('missing ../a --short', retcode=1)[0]
60
lines4 = self.capture('missing ../a --short', retcode=1)
96
61
lines4 = lines4.splitlines()
97
62
self.assertEqual(4, len(lines4))
98
lines5 = self.run_bzr('missing ../a --line', retcode=1)[0]
63
lines5 = self.capture('missing ../a --line', retcode=1)
99
64
lines5 = lines5.splitlines()
100
65
self.assertEqual(2, len(lines5))
101
lines6 = self.run_bzr('missing ../a --reverse', retcode=1)[0]
66
lines6 = self.capture('missing ../a --reverse', retcode=1)
102
67
lines6 = lines6.splitlines()
103
68
self.assertEqual(lines6, lines)
104
lines7 = self.run_bzr('missing ../a --show-ids', retcode=1)[0]
69
lines7 = self.capture('missing ../a --show-ids', retcode=1)
105
70
lines7 = lines7.splitlines()
106
71
self.assertEqual(11, len(lines7))
107
lines8 = self.run_bzr('missing ../a --verbose', retcode=1)[0]
72
lines8 = self.capture('missing ../a --verbose', retcode=1)
108
73
lines8 = lines8.splitlines()
109
74
self.assertEqual("modified:", lines8[-2])
110
75
self.assertEqual(" a", lines8[-1])
112
78
# after a pull we're back on track
113
b_tree.pull(a_branch)
114
self.assertEqual("Branches are up to date.\n", self.run_bzr('missing ../a')[0])
116
def test_missing_check_last_location(self):
117
# check that last location shown as filepath not file URL
119
# create a source branch
120
wt = self.make_branch_and_tree('a')
122
self.build_tree(['a/foo'])
127
location = osutils.getcwd() + '/'
130
b.bzrdir.sprout('../b')
132
# check last location
133
lines, err = self.run_bzr('missing', working_dir='../b')
134
self.assertEquals('Using last location: %s\n'
135
'Branches are up to date.\n' % location,
137
self.assertEquals('', err)
80
self.assertEqual("Branches are up to date.\n",
81
self.capture('missing ../a'))