1
2
from bzrlib.diff import _patch_header_date
6
from bzrlib.plugins.bzrtools.hunk_selector import (
10
from bzrlib.plugins.bzrtools.errors import NoColor
12
from bzrtools.hunk_selector import (
16
from bzrtools.errors import NoColor
5
from bzrlib.plugins.bzrtools.hunk_selector import (
9
from bzrlib.plugins.bzrtools.errors import NoColor
19
12
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
41
34
def _check_diff(self, diff=DIFF_1, filename='test_file'):
42
35
old_tree = self.tree.basis_tree()
43
old_date = _patch_header_date(old_tree,
44
old_tree.inventory.path2id(filename),
46
new_date = _patch_header_date(self.tree,
47
self.tree.inventory.path2id(filename),
39
old_date = _patch_header_date(old_tree,
40
old_tree.inventory.path2id(filename),
42
new_date = _patch_header_date(self.tree,
43
self.tree.inventory.path2id(filename), filename)
49
47
keys = { 'filename' : filename , 'old_date': old_date,
50
48
'new_date': new_date}
51
49
hdr = self.DIFF_HEADER % keys
55
53
def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
57
55
old_tree = self.tree.basis_tree()
58
old_date = _patch_header_date(old_tree,
59
old_tree.inventory.path2id(filename),
58
old_date = _patch_header_date(old_tree,
59
old_tree.inventory.path2id(filename),
61
63
diff = diff % { 'filename' : filename, 'old_date': old_date,
62
64
'new_date': new_date}
63
65
shelf = open(os.path.join(self.tree.basedir,
74
76
def __test_loop(self, count):
75
77
self.tree = self.make_branch_and_tree('.')
76
78
self.__create_and_add_test_file()
81
# Modify the test file
82
# write in binary mode because on win32 line-endings should be LF
83
f = file('test_file', 'wb')
84
f.write(self.MODIFIED)
89
new_date = _patch_header_date(self.tree,
90
self.tree.inventory.path2id('test_file'), 'test_file')
93
self.run_bzr('shelve', '--all', retcode=0)
95
# Make sure there is no diff anymore
96
self.assertEqual(self.capture('diff', retcode=0), '')
98
# Make sure the file is actually back the way it was
99
self.assertEqual(file('test_file').read(), self.ORIGINAL)
101
self._check_shelf('00', new_date=new_date)
104
self.run_bzr('unshelve', '--all', retcode=0)
108
# Check the shelved patch was backed up
109
self._check_shelf('00~', new_date=new_date)
111
# Make sure the file is back the way it should be
112
self.assertEqual(file('test_file').read(), self.MODIFIED)
79
self.tree.lock_write()
84
# Modify the test file
85
# write in binary mode because on win32 line-endings should be
87
f = file('test_file', 'wb')
88
f.write(self.MODIFIED)
93
new_date = _patch_header_date(self.tree,
94
self.tree.inventory.path2id('test_file'), 'test_file')
97
self.run_bzr('shelve', '--all', retcode=0)
99
# Make sure there is no diff anymore
100
self.assertEqual(self.capture('diff', retcode=0), '')
102
# Make sure the file is actually back the way it was
103
self.assertEqual(file('test_file').read(), self.ORIGINAL)
105
self._check_shelf('00', new_date=new_date)
108
self.run_bzr('unshelve', '--all', retcode=0)
112
# Check the shelved patch was backed up
113
self._check_shelf('00~', new_date=new_date)
115
# Make sure the file is back the way it should be
116
self.assertEqual(file('test_file').read(), self.MODIFIED)
114
120
def test_shelf_nothing_to_shelve(self):
314
320
def test_shelf_delete(self):
315
321
self.tree = self.make_branch_and_tree('.')
317
self.__create_and_add_test_file()
318
self.__create_and_add_test_file(filename='test_file2')
320
# Modify the test files
321
# write in binary mode because on win32 line-endings should be LF
322
f = file('test_file', 'wb')
323
f.write(self.MODIFIED)
325
f = file('test_file2', 'wb')
326
f.write(self.MODIFIED)
328
new_date = _patch_header_date(self.tree,
329
self.tree.inventory.path2id('test_file'), 'test_file')
322
self.tree.lock_write()
324
self.__create_and_add_test_file()
325
self.__create_and_add_test_file(filename='test_file2')
327
# Modify the test files
328
# write in binary mode because on win32 line-endings should be LF
329
f = file('test_file', 'wb')
330
f.write(self.MODIFIED)
332
f = file('test_file2', 'wb')
333
f.write(self.MODIFIED)
335
new_date = _patch_header_date(self.tree,
336
self.tree.inventory.path2id('test_file'), 'test_file')
331
340
# Shelve the changes
332
341
self.run_bzr('shelve', '--all', 'test_file', retcode=0)
421
430
self.run_bzr('shelf', 'ls', retcode=0)
423
432
old_tree = self.tree.basis_tree()
424
old_date = _patch_header_date(old_tree,
425
old_tree.inventory.path2id('test_file'),
427
new_date = _patch_header_date(self.tree,
428
self.tree.inventory.path2id('test_file'),
434
self.tree.lock_read()
436
old_date = _patch_header_date(old_tree,
437
old_tree.inventory.path2id('test_file'),
439
new_date = _patch_header_date(self.tree,
440
self.tree.inventory.path2id('test_file'), 'test_file')
430
444
# Fake a -p0 shelved patch
431
445
diff = self.DIFF_1 % { 'filename' : 'test_file', 'old_date': old_date,
432
446
'new_date' : new_date}