5630.2.2
by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail. |
1 |
# Copyright (C) 2011 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
||
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
18 |
from bzrlib import ( |
19 |
workingtree, |
|
20 |
)
|
|
5630.2.2
by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail. |
21 |
from bzrlib.tests import TestCaseWithTransport |
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
22 |
|
23 |
||
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
24 |
class TestRepairWorkingTree(TestCaseWithTransport): |
5630.2.2
by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail. |
25 |
|
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
26 |
def break_dirstate(self, tree, completely=False): |
27 |
"""Write garbage into the dirstate file."""
|
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
28 |
# This test assumes that the format uses a DirState file, which we then
|
29 |
# manually corrupt. If we change the way to get at that dirstate file,
|
|
30 |
# then we can update how this is done
|
|
31 |
self.assertIsNot(None, getattr(tree, 'current_dirstate', None)) |
|
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
32 |
tree.lock_read() |
33 |
try: |
|
34 |
dirstate = tree.current_dirstate() |
|
35 |
dirstate_path = dirstate._filename |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
36 |
self.assertPathExists(dirstate_path) |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
37 |
finally: |
38 |
tree.unlock() |
|
39 |
# We have to have the tree unlocked at this point, so we can safely
|
|
40 |
# mutate the state file on all platforms.
|
|
41 |
if completely: |
|
42 |
f = open(dirstate_path, 'wb') |
|
43 |
else: |
|
44 |
f = open(dirstate_path, 'ab') |
|
45 |
try: |
|
46 |
f.write('garbage-at-end-of-file\n') |
|
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
47 |
finally: |
48 |
f.close() |
|
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
49 |
|
50 |
def make_initial_tree(self): |
|
51 |
tree = self.make_branch_and_tree('tree') |
|
52 |
self.build_tree(['tree/foo', 'tree/dir/', 'tree/dir/bar']) |
|
53 |
tree.add(['foo', 'dir', 'dir/bar']) |
|
54 |
tree.commit('first') |
|
55 |
return tree |
|
56 |
||
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
57 |
def test_repair_refuses_uncorrupted(self): |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
58 |
tree = self.make_initial_tree() |
59 |
# If the tree doesn't appear to be corrupt, we refuse, but prompt the
|
|
60 |
# user to let them know that:
|
|
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
61 |
# a) they may want to use 'bzr revert' instead of repair-workingtree
|
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
62 |
# b) they can use --force if they really want to do this
|
63 |
self.run_bzr_error(['The tree does not appear to be corrupt', |
|
64 |
'"bzr revert"', |
|
65 |
'--force'], |
|
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
66 |
'repair-workingtree -d tree') |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
67 |
|
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
68 |
def test_repair_forced(self): |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
69 |
tree = self.make_initial_tree() |
70 |
tree.rename_one('dir', 'alt_dir') |
|
71 |
self.assertIsNot(None, tree.path2id('alt_dir')) |
|
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
72 |
self.run_bzr('repair-workingtree -d tree --force') |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
73 |
# This requires the tree has reloaded the working state
|
74 |
self.assertIs(None, tree.path2id('alt_dir')) |
|
5784.1.3
by Martin Pool
Switch away from using failUnlessExists and failIfExists |
75 |
self.assertPathExists('tree/alt_dir') |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
76 |
|
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
77 |
def test_repair_corrupted_dirstate(self): |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
78 |
tree = self.make_initial_tree() |
79 |
self.break_dirstate(tree) |
|
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
80 |
self.run_bzr('repair-workingtree -d tree') |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
81 |
tree = workingtree.WorkingTree.open('tree') |
82 |
# At this point, check should be happy
|
|
83 |
tree.check_state() |
|
84 |
||
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
85 |
def test_repair_naive_destroyed_fails(self): |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
86 |
tree = self.make_initial_tree() |
87 |
self.break_dirstate(tree, completely=True) |
|
88 |
self.run_bzr_error(['the header appears corrupt, try passing'], |
|
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
89 |
'repair-workingtree -d tree') |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
90 |
|
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
91 |
def test_repair_destroyed_with_revs_passes(self): |
5630.2.7
by John Arbash Meinel
Handle --force flags and propmting the user for what they might really want. |
92 |
tree = self.make_initial_tree() |
93 |
self.break_dirstate(tree, completely=True) |
|
5630.2.8
by John Arbash Meinel
Rename the command to 'repair-workingtree' as mentioned by vila. |
94 |
self.run_bzr('repair-workingtree -d tree -r -1') |
5630.2.4
by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted. |
95 |
tree = workingtree.WorkingTree.open('tree') |
96 |
# At this point, check should be happy
|
|
97 |
tree.check_state() |