Merge lp:~gagern/bzr/bug527878-directoryCommonOption into lp:bzr

Proposed by Martin von Gagern
Status: Merged
Approved by: Martin Pool
Approved revision: no longer in the source branch.
Merged at revision: 5284
Proposed branch: lp:~gagern/bzr/bug527878-directoryCommonOption
Merge into: lp:bzr
Diff against target: 313 lines (+107/-16)
8 files modified
NEWS (+4/-0)
bzrlib/builtins.py (+19/-12)
bzrlib/conflicts.py (+6/-4)
bzrlib/tests/blackbox/test_conflicts.py (+13/-0)
bzrlib/tests/blackbox/test_merge_directive.py (+12/-0)
bzrlib/tests/blackbox/test_missing.py (+20/-0)
bzrlib/tests/blackbox/test_shelve.py (+15/-0)
bzrlib/tests/blackbox/test_switch.py (+18/-0)
To merge this branch: bzr merge lp:~gagern/bzr/bug527878-directoryCommonOption
Reviewer Review Type Date Requested Status
Martin Pool Approve
Martin Packman (community) Approve
Review via email: mp+26306@code.launchpad.net

Commit message

Add --directory option to 7 more commands.

Description of the change

Added --directory option to 7 more commands.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

I like the trend here, though I don't personally use most of these commands. New blackbox tests pass here.

review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

I wish this could be implemented without scattering code around quite so much, but this is probably a good step

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-05-28 03:56:25 +0000
3+++ NEWS 2010-05-28 14:21:44 +0000
4@@ -17,6 +17,10 @@
5 New Features
6 ************
7
8+* Support ``--directory`` option for a number of additional commands:
9+ conflicts, merge-directive, missing, resolve, shelve, switch, unshelve.
10+ (Martin von Gagern, #527878)
11+
12 Bug Fixes
13 *********
14
15
16=== modified file 'bzrlib/builtins.py'
17--- bzrlib/builtins.py 2010-05-25 17:27:52 +0000
18+++ bzrlib/builtins.py 2010-05-28 14:21:44 +0000
19@@ -4289,6 +4289,7 @@
20 _see_also = ['merge', 'pull']
21 takes_args = ['other_branch?']
22 takes_options = [
23+ 'directory',
24 Option('reverse', 'Reverse the order of revisions.'),
25 Option('mine-only',
26 'Display changes in the local branch only.'),
27@@ -4316,7 +4317,8 @@
28 theirs_only=False,
29 log_format=None, long=False, short=False, line=False,
30 show_ids=False, verbose=False, this=False, other=False,
31- include_merges=False, revision=None, my_revision=None):
32+ include_merges=False, revision=None, my_revision=None,
33+ directory=u'.'):
34 from bzrlib.missing import find_unmerged, iter_log_revisions
35 def message(s):
36 if not is_quiet():
37@@ -4335,7 +4337,7 @@
38 elif theirs_only:
39 restrict = 'remote'
40
41- local_branch = Branch.open_containing(u".")[0]
42+ local_branch = Branch.open_containing(directory)[0]
43 self.add_cleanup(local_branch.lock_read().unlock)
44
45 parent = local_branch.get_parent()
46@@ -5012,6 +5014,7 @@
47 _see_also = ['send']
48
49 takes_options = [
50+ 'directory',
51 RegistryOption.from_kwargs('patch-type',
52 'The type of patch to include in the directive.',
53 title='Patch type',
54@@ -5030,14 +5033,15 @@
55 encoding_type = 'exact'
56
57 def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
58- sign=False, revision=None, mail_to=None, message=None):
59+ sign=False, revision=None, mail_to=None, message=None,
60+ directory=u'.'):
61 from bzrlib.revision import ensure_null, NULL_REVISION
62 include_patch, include_bundle = {
63 'plain': (False, False),
64 'diff': (True, False),
65 'bundle': (True, True),
66 }[patch_type]
67- branch = Branch.open('.')
68+ branch = Branch.open(directory)
69 stored_submit_branch = branch.get_submit_branch()
70 if submit_branch is None:
71 submit_branch = stored_submit_branch
72@@ -5531,7 +5535,8 @@
73 """
74
75 takes_args = ['to_location?']
76- takes_options = [Option('force',
77+ takes_options = ['directory',
78+ Option('force',
79 help='Switch even if local commits will be lost.'),
80 'revision',
81 Option('create-branch', short_name='b',
82@@ -5540,16 +5545,16 @@
83 ]
84
85 def run(self, to_location=None, force=False, create_branch=False,
86- revision=None):
87+ revision=None, directory=u'.'):
88 from bzrlib import switch
89- tree_location = '.'
90+ tree_location = directory
91 revision = _get_one_revision('switch', revision)
92 control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
93 if to_location is None:
94 if revision is None:
95 raise errors.BzrCommandError('You must supply either a'
96 ' revision or a location')
97- to_location = '.'
98+ to_location = tree_location
99 try:
100 branch = control_dir.open_branch()
101 had_explicit_nick = branch.get_config().has_explicit_nickname()
102@@ -5830,6 +5835,7 @@
103 takes_args = ['file*']
104
105 takes_options = [
106+ 'directory',
107 'revision',
108 Option('all', help='Shelve all changes.'),
109 'message',
110@@ -5844,7 +5850,7 @@
111 _see_also = ['unshelve']
112
113 def run(self, revision=None, all=False, file_list=None, message=None,
114- writer=None, list=False, destroy=False):
115+ writer=None, list=False, destroy=False, directory=u'.'):
116 if list:
117 return self.run_for_list()
118 from bzrlib.shelf_ui import Shelver
119@@ -5852,7 +5858,7 @@
120 writer = bzrlib.option.diff_writer_registry.get()
121 try:
122 shelver = Shelver.from_args(writer(sys.stdout), revision, all,
123- file_list, message, destroy=destroy)
124+ file_list, message, destroy=destroy, directory=directory)
125 try:
126 shelver.run()
127 finally:
128@@ -5886,6 +5892,7 @@
129
130 takes_args = ['shelf_id?']
131 takes_options = [
132+ 'directory',
133 RegistryOption.from_kwargs(
134 'action', help="The action to perform.",
135 enum_switch=False, value_switches=True,
136@@ -5899,9 +5906,9 @@
137 ]
138 _see_also = ['shelve']
139
140- def run(self, shelf_id=None, action='apply'):
141+ def run(self, shelf_id=None, action='apply', directory=u'.'):
142 from bzrlib.shelf_ui import Unshelver
143- unshelver = Unshelver.from_args(shelf_id, action)
144+ unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
145 try:
146 unshelver.run()
147 finally:
148
149=== modified file 'bzrlib/conflicts.py'
150--- bzrlib/conflicts.py 2010-04-30 11:35:43 +0000
151+++ bzrlib/conflicts.py 2010-05-28 14:21:44 +0000
152@@ -59,13 +59,14 @@
153 Use bzr resolve when you have fixed a problem.
154 """
155 takes_options = [
156+ 'directory',
157 option.Option('text',
158 help='List paths of files with text conflicts.'),
159 ]
160 _see_also = ['resolve', 'conflict-types']
161
162- def run(self, text=False):
163- wt = workingtree.WorkingTree.open_containing(u'.')[0]
164+ def run(self, text=False, directory=u'.'):
165+ wt = workingtree.WorkingTree.open_containing(directory)[0]
166 for conflict in wt.conflicts():
167 if text:
168 if conflict.typestring != 'text conflict':
169@@ -112,16 +113,17 @@
170 aliases = ['resolved']
171 takes_args = ['file*']
172 takes_options = [
173+ 'directory',
174 option.Option('all', help='Resolve all conflicts in this tree.'),
175 ResolveActionOption(),
176 ]
177 _see_also = ['conflicts']
178- def run(self, file_list=None, all=False, action=None):
179+ def run(self, file_list=None, all=False, action=None, directory=u'.'):
180 if all:
181 if file_list:
182 raise errors.BzrCommandError("If --all is specified,"
183 " no FILE may be provided")
184- tree = workingtree.WorkingTree.open_containing('.')[0]
185+ tree = workingtree.WorkingTree.open_containing(directory)[0]
186 if action is None:
187 action = 'done'
188 else:
189
190=== modified file 'bzrlib/tests/blackbox/test_conflicts.py'
191--- bzrlib/tests/blackbox/test_conflicts.py 2010-02-10 17:52:08 +0000
192+++ bzrlib/tests/blackbox/test_conflicts.py 2010-05-28 14:21:44 +0000
193@@ -70,6 +70,12 @@
194 out, err = self.run_bzr('conflicts --text')
195 self.assertEqual(['my_other_file', 'myfile'], out.splitlines())
196
197+ def test_conflicts_directory(self):
198+ """Test --directory option"""
199+ out, err = self.run_bzr('conflicts --directory a', working_dir='.')
200+ self.assertEqual(3, len(out.splitlines()))
201+ self.assertEqual('', err)
202+
203
204 class TestResolve(TestConflictsBase):
205
206@@ -113,3 +119,10 @@
207 self.build_tree_contents([('tree/file', 'a\n')])
208 note = self.run_bzr('resolve', working_dir='tree')[1]
209 self.assertContainsRe(note, 'All conflicts resolved.')
210+
211+ def test_resolve_all_directory(self):
212+ """Test --directory option"""
213+ out, err = self.run_bzr('resolve --all -d a', working_dir='.')
214+ self.assertEqual('', err)
215+ out, err = self.run_bzr('conflicts')
216+ self.assertEqual(0, len(out.splitlines()))
217
218=== modified file 'bzrlib/tests/blackbox/test_merge_directive.py'
219--- bzrlib/tests/blackbox/test_merge_directive.py 2009-03-23 14:59:43 +0000
220+++ bzrlib/tests/blackbox/test_merge_directive.py 2010-05-28 14:21:44 +0000
221@@ -248,3 +248,15 @@
222 tree1, tree2 = self.prepare_merge_directive()
223 tree1.commit(u'messag\xe9')
224 self.run_bzr('merge-directive ../tree2') # no exception raised
225+
226+ def test_merge_directive_directory(self):
227+ """Test --directory option"""
228+ import re
229+ re_timestamp = re.compile(r'^# timestamp: .*', re.M)
230+ self.prepare_merge_directive()
231+ md1 = self.run_bzr('merge-directive ../tree2')[0]
232+ md1 = re_timestamp.sub('# timestamp: XXX', md1)
233+ os.chdir('..')
234+ md2 = self.run_bzr('merge-directive --directory tree1 tree2')[0]
235+ md2 = re_timestamp.sub('# timestamp: XXX', md2)
236+ self.assertEqualDiff(md1.replace('../tree2', 'tree2'), md2)
237
238=== modified file 'bzrlib/tests/blackbox/test_missing.py'
239--- bzrlib/tests/blackbox/test_missing.py 2009-03-23 14:59:43 +0000
240+++ bzrlib/tests/blackbox/test_missing.py 2010-05-28 14:21:44 +0000
241@@ -200,3 +200,23 @@
242 'Branches are up to date.\n' % location,
243 lines)
244 self.assertEquals('', err)
245+
246+ def test_missing_directory(self):
247+ """Test --directory option"""
248+
249+ # create a source branch
250+ a_tree = self.make_branch_and_tree('a')
251+ self.build_tree_contents([('a/a', 'initial\n')])
252+ a_tree.add('a')
253+ a_tree.commit(message='initial')
254+
255+ # clone and add a differing revision
256+ b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
257+ self.build_tree_contents([('b/a', 'initial\nmore\n')])
258+ b_tree.commit(message='more')
259+
260+ out2, err2 = self.run_bzr('missing --directory a b', retcode=1)
261+ os.chdir('a')
262+ out1, err1 = self.run_bzr('missing ../b', retcode=1)
263+ self.assertEqualDiff(out1, out2)
264+ self.assertEqualDiff(err1, err2)
265
266=== modified file 'bzrlib/tests/blackbox/test_shelve.py'
267--- bzrlib/tests/blackbox/test_shelve.py 2010-05-20 18:23:17 +0000
268+++ bzrlib/tests/blackbox/test_shelve.py 2010-05-28 14:21:44 +0000
269@@ -97,3 +97,18 @@
270 tree.add('file')
271 os.chdir('tree/dir')
272 self.run_bzr('shelve --all ../file')
273+
274+
275+class TestShelveUnshelve(TestCaseWithTransport):
276+
277+ def test_directory(self):
278+ """Test --directory option"""
279+ tree = self.make_branch_and_tree('tree')
280+ self.build_tree_contents([('tree/a', 'initial\n')])
281+ tree.add('a')
282+ tree.commit(message='committed')
283+ self.build_tree_contents([('tree/a', 'initial\nmore\n')])
284+ self.run_bzr('shelve -d tree --all')
285+ self.assertFileEqual('initial\n', 'tree/a')
286+ self.run_bzr('unshelve --directory tree')
287+ self.assertFileEqual('initial\nmore\n', 'tree/a')
288
289=== modified file 'bzrlib/tests/blackbox/test_switch.py'
290--- bzrlib/tests/blackbox/test_switch.py 2010-04-28 07:53:34 +0000
291+++ bzrlib/tests/blackbox/test_switch.py 2010-05-28 14:21:44 +0000
292@@ -252,3 +252,21 @@
293 self.assertLength(0, calls)
294 out, err = self.run_bzr('switch ../branch2')
295 self.assertLength(1, calls)
296+
297+ def test_switch_lightweight_directory(self):
298+ """Test --directory option"""
299+
300+ # create a source branch
301+ a_tree = self.make_branch_and_tree('a')
302+ self.build_tree_contents([('a/a', 'initial\n')])
303+ a_tree.add('a')
304+ a_tree.commit(message='initial')
305+
306+ # clone and add a differing revision
307+ b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
308+ self.build_tree_contents([('b/a', 'initial\nmore\n')])
309+ b_tree.commit(message='more')
310+
311+ self.run_bzr('checkout --lightweight a checkout')
312+ self.run_bzr('switch --directory checkout b')
313+ self.assertFileEqual('initial\nmore\n', 'checkout/a')