1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
1 |
# Copyright (C) 2005 by Canonical Ltd
|
2 |
# -*- coding: utf-8 -*-
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
3 |
#
|
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
4 |
# This program is free software; you can redistribute it and/or modify
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
8 |
#
|
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
9 |
# This program is distributed in the hope that it will be useful,
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
13 |
#
|
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
14 |
# You should have received a copy of the GNU General Public License
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
||
1692.3.1
by Robert Collins
Fix push to work with just a branch, no need for a working tree. |
19 |
"""Black-box tests for bzr push."""
|
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
20 |
|
21 |
import os |
|
22 |
||
1692.3.1
by Robert Collins
Fix push to work with just a branch, no need for a working tree. |
23 |
import bzrlib |
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
24 |
from bzrlib.branch import Branch |
1711.2.3
by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???) |
25 |
from bzrlib.bzrdir import BzrDirMetaFormat1 |
1614.2.16
by Olaf Conradi
Modified blackbox test cases to use bzrlib API. |
26 |
from bzrlib.osutils import abspath |
1711.2.3
by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???) |
27 |
from bzrlib.repository import RepositoryFormatKnit1 |
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
28 |
from bzrlib.tests.blackbox import ExternalBase |
1614.2.16
by Olaf Conradi
Modified blackbox test cases to use bzrlib API. |
29 |
from bzrlib.uncommit import uncommit |
1785.1.1
by John Arbash Meinel
Fix the output of 'bzr push' so that it prints the location correctly. |
30 |
from bzrlib.urlutils import local_path_from_url |
1711.2.3
by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???) |
31 |
from bzrlib.workingtree import WorkingTree |
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
32 |
|
33 |
||
34 |
class TestPush(ExternalBase): |
|
35 |
||
36 |
def test_push_remember(self): |
|
37 |
"""Push changes from one branch to another and test push location."""
|
|
1614.2.16
by Olaf Conradi
Modified blackbox test cases to use bzrlib API. |
38 |
transport = self.get_transport() |
39 |
tree_a = self.make_branch_and_tree('branch_a') |
|
40 |
branch_a = tree_a.branch |
|
41 |
self.build_tree(['branch_a/a']) |
|
42 |
tree_a.add('a') |
|
43 |
tree_a.commit('commit a') |
|
1666.1.4
by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in |
44 |
tree_b = branch_a.bzrdir.sprout('branch_b').open_workingtree() |
45 |
branch_b = tree_b.branch |
|
46 |
tree_c = branch_a.bzrdir.sprout('branch_c').open_workingtree() |
|
47 |
branch_c = tree_c.branch |
|
1614.2.16
by Olaf Conradi
Modified blackbox test cases to use bzrlib API. |
48 |
self.build_tree(['branch_a/b']) |
49 |
tree_a.add('b') |
|
50 |
tree_a.commit('commit b') |
|
51 |
self.build_tree(['branch_b/c']) |
|
52 |
tree_b.add('c') |
|
53 |
tree_b.commit('commit c') |
|
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
54 |
# initial push location must be empty
|
1614.2.16
by Olaf Conradi
Modified blackbox test cases to use bzrlib API. |
55 |
self.assertEqual(None, branch_b.get_push_location()) |
1785.1.2
by John Arbash Meinel
Push should only save the location if it can actually connect (doesn't need to succeed) |
56 |
|
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
57 |
# test push for failure without push location set
|
1614.2.16
by Olaf Conradi
Modified blackbox test cases to use bzrlib API. |
58 |
os.chdir('branch_a') |
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
59 |
out = self.runbzr('push', retcode=3) |
60 |
self.assertEquals(out, |
|
61 |
('','bzr: ERROR: No push location known or specified.\n')) |
|
1785.1.2
by John Arbash Meinel
Push should only save the location if it can actually connect (doesn't need to succeed) |
62 |
|
63 |
# test not remembered if cannot actually push
|
|
64 |
self.run_bzr('push', '../path/which/doesnt/exist', retcode=3) |
|
65 |
out = self.run_bzr('push', retcode=3) |
|
66 |
self.assertEquals( |
|
67 |
('', 'bzr: ERROR: No push location known or specified.\n'), |
|
68 |
out) |
|
69 |
||
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
70 |
# test implicit --remember when no push location set, push fails
|
1785.1.1
by John Arbash Meinel
Fix the output of 'bzr push' so that it prints the location correctly. |
71 |
out = self.run_bzr('push', '../branch_b', retcode=3) |
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
72 |
self.assertEquals(out, |
73 |
('','bzr: ERROR: These branches have diverged. ' |
|
74 |
'Try a merge then push with overwrite.\n')) |
|
1614.2.16
by Olaf Conradi
Modified blackbox test cases to use bzrlib API. |
75 |
self.assertEquals(abspath(branch_a.get_push_location()), |
76 |
abspath(branch_b.bzrdir.root_transport.base)) |
|
1785.1.2
by John Arbash Meinel
Push should only save the location if it can actually connect (doesn't need to succeed) |
77 |
|
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
78 |
# test implicit --remember after resolving previous failure
|
1614.2.16
by Olaf Conradi
Modified blackbox test cases to use bzrlib API. |
79 |
uncommit(branch=branch_b, tree=tree_b) |
80 |
transport.delete('branch_b/c') |
|
1785.1.1
by John Arbash Meinel
Fix the output of 'bzr push' so that it prints the location correctly. |
81 |
out = self.run_bzr('push') |
82 |
path = branch_a.get_push_location() |
|
83 |
self.assertEquals(('Using saved location: %s\n' |
|
84 |
% (local_path_from_url(path),) |
|
85 |
, 'All changes applied successfully.\n' |
|
86 |
'1 revision(s) pushed.\n'), out) |
|
87 |
self.assertEqual(path, |
|
88 |
branch_b.bzrdir.root_transport.base) |
|
1614.2.9
by Olaf Conradi
Added testcases for using push with --remember. Moved remember code to |
89 |
# test explicit --remember
|
1785.1.1
by John Arbash Meinel
Fix the output of 'bzr push' so that it prints the location correctly. |
90 |
self.run_bzr('push', '../branch_c', '--remember') |
91 |
self.assertEquals(branch_a.get_push_location(), |
|
92 |
branch_c.bzrdir.root_transport.base) |
|
1692.3.1
by Robert Collins
Fix push to work with just a branch, no need for a working tree. |
93 |
|
94 |
def test_push_without_tree(self): |
|
95 |
# bzr push from a branch that does not have a checkout should work.
|
|
96 |
b = self.make_branch('.') |
|
97 |
out, err = self.run_bzr('push', 'pushed-location') |
|
98 |
self.assertEqual('', out) |
|
99 |
self.assertEqual('0 revision(s) pushed.\n', err) |
|
100 |
b2 = bzrlib.branch.Branch.open('pushed-location') |
|
101 |
self.assertEndsWith(b2.base, 'pushed-location/') |
|
1692.3.6
by Robert Collins
Show the correct number of revisions pushed when pushing a new branch (Robert Collins). |
102 |
|
103 |
def test_push_new_branch_revision_count(self): |
|
104 |
# bzr push of a branch with revisions to a new location
|
|
105 |
# should print the number of revisions equal to the length of the
|
|
106 |
# local branch.
|
|
107 |
t = self.make_branch_and_tree('tree') |
|
108 |
self.build_tree(['tree/file']) |
|
109 |
t.add('file') |
|
110 |
t.commit('commit 1') |
|
111 |
os.chdir('tree') |
|
112 |
out, err = self.run_bzr('push', 'pushed-to') |
|
113 |
os.chdir('..') |
|
114 |
self.assertEqual('', out) |
|
115 |
self.assertEqual('1 revision(s) pushed.\n', err) |
|
1711.2.3
by John Arbash Meinel
Fix push to only push revisions in the current ancestry. (bug???) |
116 |
|
117 |
def test_push_only_pushes_history(self): |
|
118 |
# Knit branches should only push the history for the current revision.
|
|
119 |
format = BzrDirMetaFormat1() |
|
120 |
format.repository_format = RepositoryFormatKnit1() |
|
121 |
shared_repo = self.make_repository('repo', format=format, shared=True) |
|
122 |
shared_repo.set_make_working_trees(True) |
|
123 |
||
124 |
def make_shared_tree(path): |
|
125 |
shared_repo.bzrdir.root_transport.mkdir(path) |
|
126 |
shared_repo.bzrdir.create_branch_convenience('repo/' + path) |
|
127 |
return WorkingTree.open('repo/' + path) |
|
128 |
tree_a = make_shared_tree('a') |
|
129 |
self.build_tree(['repo/a/file']) |
|
130 |
tree_a.add('file') |
|
131 |
tree_a.commit('commit a-1', rev_id='a-1') |
|
132 |
f = open('repo/a/file', 'ab') |
|
133 |
f.write('more stuff\n') |
|
134 |
f.close() |
|
135 |
tree_a.commit('commit a-2', rev_id='a-2') |
|
136 |
||
137 |
tree_b = make_shared_tree('b') |
|
138 |
self.build_tree(['repo/b/file']) |
|
139 |
tree_b.add('file') |
|
140 |
tree_b.commit('commit b-1', rev_id='b-1') |
|
141 |
||
142 |
self.assertTrue(shared_repo.has_revision('a-1')) |
|
143 |
self.assertTrue(shared_repo.has_revision('a-2')) |
|
144 |
self.assertTrue(shared_repo.has_revision('b-1')) |
|
145 |
||
146 |
# Now that we have a repository with shared files, make sure
|
|
147 |
# that things aren't copied out by a 'push'
|
|
148 |
os.chdir('repo/b') |
|
149 |
self.run_bzr('push', '../../push-b') |
|
150 |
pushed_tree = WorkingTree.open('../../push-b') |
|
151 |
pushed_repo = pushed_tree.branch.repository |
|
152 |
self.assertFalse(pushed_repo.has_revision('a-1')) |
|
153 |
self.assertFalse(pushed_repo.has_revision('a-2')) |
|
154 |
self.assertTrue(pushed_repo.has_revision('b-1')) |
|
155 |
||
1843.2.1
by Aaron Bentley
Add failing tests for funky ids |
156 |
def test_push_funky_id(self): |
157 |
t = self.make_branch_and_tree('tree') |
|
158 |
os.chdir('tree') |
|
159 |
self.build_tree(['filename']) |
|
160 |
t.add('filename', 'funky-chars<>%&;"\'') |
|
161 |
t.commit('commit filename') |
|
162 |
self.run_bzr('push', '../new-tree') |