19
from bzrlib import shelf
20
from bzrlib.tests import TestCaseWithTransport
21
from bzrlib.tests.script import ScriptRunner
19
from breezy import shelf
20
from breezy.tests import TestCaseWithTransport
21
from breezy.tests.script import ScriptRunner
24
24
class TestShelveList(TestCaseWithTransport):
41
41
self.assertEqual('', err)
42
42
self.assertEqual(' 1: Foo\n', out)
44
def test_shelve_list_via_directory(self):
45
tree = self.make_branch_and_tree('tree')
46
creator = self.make_creator(tree)
47
shelf_id = tree.get_shelf_manager().shelve_changes(creator, 'Foo')
48
out, err = self.run_bzr('shelve -d tree --list', retcode=1)
49
self.assertEqual('', err)
50
self.assertEqual(' 1: Foo\n', out)
44
52
def test_shelve_no_message(self):
45
53
tree = self.make_branch_and_tree('.')
46
54
creator = self.make_creator(tree)
64
72
self.build_tree(['file'])
66
74
self.run_bzr('shelve --all --destroy')
67
self.failIfExists('file')
75
self.assertPathDoesNotExist('file')
68
76
self.assertIs(None, tree.get_shelf_manager().last_shelf())
70
78
def test_unshelve_keep(self):
71
# https://bugs.edge.launchpad.net/bzr/+bug/492091
79
# https://bugs.launchpad.net/bzr/+bug/492091
72
80
tree = self.make_branch_and_tree('.')
73
81
# shelve apparently unhappy working with a tree with no root yet
74
82
tree.commit('make root')
77
85
sr = ScriptRunner()
78
86
sr.run_script(self, '''
80
$ bzr shelve --all -m Foo
89
$ brz shelve --all -m Foo
92
2>Changes shelved with id "1".
96
2>Using changes with id "1".
99
2>All changes applied successfully.
107
class TestUnshelvePreview(TestCaseWithTransport):
109
def test_non_ascii(self):
110
"""Test that we can show a non-ascii diff that would result from unshelving"""
112
init_content = u'Initial: \u0418\u0437\u043d\u0430\u0447\n'.encode('utf-8')
113
more_content = u'More: \u0415\u0449\u0451\n'.encode('utf-8')
114
next_content = init_content + more_content
115
diff_part = b'@@ -1,1 +1,2 @@\n %s+%s' % (init_content, more_content)
117
tree = self.make_branch_and_tree('.')
118
self.build_tree_contents([('a_file', init_content)])
120
tree.commit(message='committed')
121
self.build_tree_contents([('a_file', next_content)])
122
self.run_bzr(['shelve', '--all'])
123
out, err = self.run_bzr_raw(['unshelve', '--preview'], encoding='latin-1')
125
self.assertContainsString(out, diff_part)
92
128
class TestShelveRelpath(TestCaseWithTransport):
98
134
os.chdir('tree/dir')
99
135
self.run_bzr('shelve --all ../file')
137
def test_shelve_via_directory(self):
138
tree = self.make_branch_and_tree('tree')
139
self.build_tree(['tree/file', 'tree/dir/'])
141
self.run_bzr('shelve -d tree/dir --all ../file')
144
class TestShelveUnshelve(TestCaseWithTransport):
146
def test_directory(self):
147
"""Test --directory option"""
148
tree = self.make_branch_and_tree('tree')
149
self.build_tree_contents([('tree/a', b'initial\n')])
151
tree.commit(message='committed')
152
self.build_tree_contents([('tree/a', b'initial\nmore\n')])
153
self.run_bzr('shelve -d tree --all')
154
self.assertFileEqual(b'initial\n', 'tree/a')
155
self.run_bzr('unshelve --directory tree')
156
self.assertFileEqual(b'initial\nmore\n', 'tree/a')