6
class ShelfTests(bzrlib.tests.TestCaseInTempDir):
6
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
7
7
ORIGINAL = '\n\nhello test world\n\n'
8
8
MODIFIED = '\n\ngoodbye test world\n\n'
9
9
DIFF_HEADER = "=== modified file 'test_file'\n"
32
32
self.__test_loop(10)
34
34
def __test_loop(self, count):
35
from bzrlib.branch import Branch
36
b = Branch.initialize('.')
38
# Create a test file and commit it
39
file('test_file', 'w').write(self.ORIGINAL)
40
b.working_tree().add('test_file')
41
b.working_tree().commit(message='add test_file')
35
tree = self.make_branch_and_tree('.')
36
self.__create_and_add_test_file(tree)
60
55
self.assertEqual(file('test_file').read(), self.ORIGINAL)
62
57
# Check the shelf is right
63
shelf = open(os.path.join(b.base, '.shelf/shelves/default/00')).read()
58
shelf = open(os.path.join(tree.branch.base,
59
'.shelf/shelves/default/00')).read()
64
60
shelf = shelf[shelf.index('\n') + 1:] # skip the message
65
61
self.assertEqual(shelf, self.DIFF_1)
77
73
def test_shelf_nothing_to_shelve(self):
79
from bzrlib.branch import Branch
80
b = Branch.initialize('.')
82
# Create a test file and commit it
83
file('test_file', 'w').write(self.ORIGINAL)
84
b.working_tree().add('test_file')
85
b.working_tree().commit(message='add test_file')
75
tree = self.make_branch_and_tree('.')
76
self.__create_and_add_test_file(tree)
87
78
# Shelve the changes
88
79
self.run_bzr('shelve', retcode=3)
90
if os.path.exists(os.path.join(b.base, '.shelf/shelves/default/00')):
81
if os.path.exists(os.path.join(tree.branch.base,
82
'.shelf/shelves/default/00')):
91
83
self.fail("Shelf exists, but it shouldn't")
85
def __create_and_add_test_file(self, tree):
86
self.build_tree_contents([('test_file', self.ORIGINAL)])
88
tree.commit(message='add test_file')
93
90
def test_shelf_with_revision(self):
94
from bzrlib.branch import Branch
95
b = Branch.initialize('.')
91
tree = self.make_branch_and_tree('.')
97
# Create a test file and commit it
98
file('test_file', 'w').write(self.ORIGINAL)
99
b.working_tree().add('test_file')
100
b.working_tree().commit(message='add test_file')
93
self.__create_and_add_test_file(tree)
102
95
# Modify the test file and commit it
103
file('test_file', 'w').write(self.MODIFIED)
104
b.working_tree().commit(message='update test_file')
96
self.build_tree_contents([('test_file', self.MODIFIED)])
97
tree.commit(message='update test_file')
106
99
# Shelve the changes
107
100
self.run_bzr('shelve', '-r', '1', retcode=0)
120
113
self.assertEqual(file('test_file').read(), self.MODIFIED)
122
115
def test_shelf_with_two_revisions(self):
123
from bzrlib.branch import Branch
124
b = Branch.initialize('.')
116
tree = self.make_branch_and_tree('.')
126
118
cmd = 'shelve -r 1..2'
127
119
(stdout, stderr) = self.run_bzr_captured(cmd.split(), retcode=None)