/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2018-03-26 01:11:21 UTC
  • mfrom: (0.200.1895 work)
  • mto: (0.200.1934 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180326011121-tjvodob61mqqzpdc
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from __future__ import absolute_import
21
21
 
 
22
import os
 
23
import stat
 
24
 
 
25
from dulwich.objects import (
 
26
    Blob,
 
27
    Tree,
 
28
    ZERO_SHA,
 
29
    )
 
30
 
22
31
from .... import conflicts as _mod_conflicts
23
32
from ..workingtree import (
24
33
    FLAG_STAGEMASK,
 
34
    changes_between_git_tree_and_working_copy,
25
35
    )
26
36
from ....tests import TestCaseWithTransport
27
37
 
51
61
        self.assertTrue(self.tree.is_versioned('a'))
52
62
        self.tree.revert(['a'])
53
63
        self.assertFalse(self.tree.is_versioned('a'))
 
64
 
 
65
 
 
66
class ChangesBetweenGitTreeAndWorkingCopyTests(TestCaseWithTransport):
 
67
 
 
68
    def setUp(self):
 
69
        super(ChangesBetweenGitTreeAndWorkingCopyTests, self).setUp()
 
70
        self.wt = self.make_branch_and_tree('.', format='git')
 
71
 
 
72
    def expectDelta(self, expected_changes,
 
73
                    expected_extras=None, want_unversioned=False):
 
74
        store = self.wt.branch.repository._git.object_store
 
75
        try:
 
76
            tree_id = store[self.wt.branch.repository._git.head()].tree
 
77
        except KeyError:
 
78
            tree_id = None
 
79
        changes, extras = changes_between_git_tree_and_working_copy(
 
80
            store, tree_id, self.wt, want_unversioned=want_unversioned)
 
81
        self.assertEqual(expected_changes, list(changes))
 
82
        if expected_extras is None:
 
83
            expected_extras = set()
 
84
        self.assertEqual(set(expected_extras), set(extras))
 
85
 
 
86
    def test_empty(self):
 
87
        self.expectDelta(
 
88
            [((None, ''), (None, stat.S_IFDIR), (None, Tree().id))])
 
89
 
 
90
    def test_added_file(self):
 
91
        self.build_tree(['a'])
 
92
        self.wt.add(['a'])
 
93
        a = Blob.from_string('contents of a\n')
 
94
        t = Tree()
 
95
        t.add("a", stat.S_IFREG | 0o644, a.id)
 
96
        self.expectDelta(
 
97
            [((None, ''), (None, stat.S_IFDIR), (None, t.id)),
 
98
             ((None, 'a'), (None, stat.S_IFREG | 0o644), (None, a.id))])
 
99
 
 
100
    def test_added_unknown_file(self):
 
101
        self.build_tree(['a'])
 
102
        t = Tree()
 
103
        self.expectDelta(
 
104
            [((None, ''), (None, stat.S_IFDIR), (None, t.id))])
 
105
        a = Blob.from_string('contents of a\n')
 
106
        t = Tree()
 
107
        t.add("a", stat.S_IFREG | 0o644, a.id)
 
108
        self.expectDelta(
 
109
            [((None, ''), (None, stat.S_IFDIR), (None, t.id)),
 
110
             ((None, 'a'), (None, stat.S_IFREG | 0o644), (None, a.id))],
 
111
            ['a'],
 
112
            want_unversioned=True)
 
113
 
 
114
    def test_missing_added_file(self):
 
115
        self.build_tree(['a'])
 
116
        self.wt.add(['a'])
 
117
        os.unlink('a')
 
118
        a = Blob.from_string('contents of a\n')
 
119
        t = Tree()
 
120
        t.add("a", 0, ZERO_SHA)
 
121
        self.expectDelta(
 
122
            [((None, ''), (None, stat.S_IFDIR), (None, t.id)),
 
123
             ((None, 'a'), (None, 0), (None, ZERO_SHA))],
 
124
            [])
 
125
 
 
126
    def test_missing_versioned_file(self):
 
127
        self.build_tree(['a'])
 
128
        self.wt.add(['a'])
 
129
        self.wt.commit('')
 
130
        os.unlink('a')
 
131
        a = Blob.from_string('contents of a\n')
 
132
        oldt = Tree()
 
133
        oldt.add("a", stat.S_IFREG | 0o644, a.id)
 
134
        newt = Tree()
 
135
        newt.add("a", 0, ZERO_SHA)
 
136
        self.expectDelta(
 
137
                [(('', ''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)),
 
138
                 (('a', 'a'), (stat.S_IFREG|0o644, 0), (a.id, ZERO_SHA))])
 
139
 
 
140
    def test_versioned_replace_by_dir(self):
 
141
        self.build_tree(['a'])
 
142
        self.wt.add(['a'])
 
143
        self.wt.commit('')
 
144
        os.unlink('a')
 
145
        os.mkdir('a')
 
146
        olda = Blob.from_string('contents of a\n')
 
147
        oldt = Tree()
 
148
        oldt.add("a", stat.S_IFREG | 0o644, olda.id)
 
149
        newt = Tree()
 
150
        newa = Tree()
 
151
        newt.add("a", stat.S_IFDIR, newa.id)
 
152
        self.expectDelta([
 
153
            (('', ''),
 
154
            (stat.S_IFDIR, stat.S_IFDIR),
 
155
            (oldt.id, newt.id)),
 
156
            (('a', 'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
 
157
            ], want_unversioned=False)
 
158
        self.expectDelta([
 
159
            (('', ''),
 
160
            (stat.S_IFDIR, stat.S_IFDIR),
 
161
            (oldt.id, newt.id)),
 
162
            (('a', 'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
 
163
            ], want_unversioned=True)
 
164
 
 
165
    def test_extra(self):
 
166
        self.build_tree(['a'])
 
167
        newa = Blob.from_string('contents of a\n')
 
168
        newt = Tree()
 
169
        newt.add("a", stat.S_IFREG | 0o644, newa.id)
 
170
        self.expectDelta([
 
171
            ((None, ''),
 
172
            (None, stat.S_IFDIR),
 
173
            (None, newt.id)),
 
174
            ((None, 'a'), (None, stat.S_IFREG | 0o644), (None, newa.id))
 
175
            ], ['a'], want_unversioned=True)