/breezy/trunk

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/trunk

« back to all changes in this revision

Viewing changes to breezy/tests/per_workingtree/test_smart_add.py

Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import sys
21
21
 
22
22
from ... import (
 
23
    add as _mod_add,
23
24
    errors,
24
25
    ignores,
25
26
    osutils,
37
38
    )
38
39
 
39
40
 
 
41
class RecordingAddAction(_mod_add.AddAction):
 
42
 
 
43
    def __init__(self):
 
44
        self.adds = []
 
45
 
 
46
    def __call__(self, wt, parent_ie, path, kind):
 
47
        self.adds.append((wt, path, kind))
 
48
 
 
49
 
40
50
class TestSmartAddTree(per_workingtree.TestCaseWithWorkingTree):
41
51
 
42
52
    def test_single_file(self):
43
53
        tree = self.make_branch_and_tree('tree')
44
54
        self.build_tree(['tree/a'])
45
 
        tree.smart_add(['tree'])
 
55
        action = RecordingAddAction()
 
56
        tree.smart_add(['tree'], action=action)
46
57
 
47
 
        tree.lock_read()
48
 
        try:
 
58
        with tree.lock_read():
49
59
            files = [(path, status, kind)
50
60
                     for path, status, kind, file_id, parent_id
51
 
                     in tree.list_files(include_root=True)]
52
 
        finally:
53
 
            tree.unlock()
 
61
                      in tree.list_files(include_root=True)]
54
62
        self.assertEqual([('', 'V', 'directory'), ('a', 'V', 'file')],
55
63
                         files)
 
64
        self.assertEqual([(tree, 'a', 'file')], action.adds)
56
65
 
57
66
    def assertFilenameSkipped(self, filename):
58
67
        tree = self.make_branch_and_tree('tree')
74
83
    def test_save_false(self):
75
84
        """Dry-run add doesn't permanently affect the tree."""
76
85
        wt = self.make_branch_and_tree('.')
77
 
        wt.lock_write()
78
 
        try:
 
86
        with wt.lock_write():
79
87
            self.build_tree(['file'])
80
88
            wt.smart_add(['file'], save=False)
81
89
            # the file should not be added - no id.
82
90
            self.assertEqual(wt.path2id('file'), None)
83
 
        finally:
84
 
            wt.unlock()
85
91
        # and the disk state should be the same - reopen to check.
86
92
        wt = wt.controldir.open_workingtree()
87
93
        self.assertFalse(wt.is_versioned('file'))
91
97
        paths = ("original/", "original/file1", "original/file2")
92
98
        self.build_tree(paths)
93
99
        wt = self.make_branch_and_tree('.')
94
 
        wt.smart_add((u".",))
 
100
        action = RecordingAddAction()
 
101
        wt.smart_add((u".",), action=action)
95
102
        for path in paths:
96
103
            self.assertTrue(wt.is_versioned(path))
 
104
        if wt.has_versioned_directories():
 
105
            self.assertEqual(
 
106
                {(wt, 'original', 'directory'),
 
107
                 (wt, 'original/file1', 'file'),
 
108
                 (wt, 'original/file2', 'file')},
 
109
                set(action.adds))
 
110
        else:
 
111
            self.assertEqual(
 
112
                {(wt, 'original/file1', 'file'),
 
113
                 (wt, 'original/file2', 'file')},
 
114
                set(action.adds))
97
115
 
98
116
    def test_skip_nested_trees(self):
99
117
        """Test smart-adding a nested tree ignors it and warns."""