/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
2
# Copyright (C) 2011 Canonical Ltd.
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
17
18
"""Tests for Git working trees."""
19
0.358.3 by Jelmer Vernooij
Enable absolute import.
20
from __future__ import absolute_import
21
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
22
import os
23
import stat
24
25
from dulwich.objects import (
26
    Blob,
27
    Tree,
28
    ZERO_SHA,
29
    )
30
0.369.2 by Jelmer Vernooij
Fix tests.
31
from .... import conflicts as _mod_conflicts
6973.1.1 by Jelmer Vernooij
Make InterIndexGitTree suitable for use with MemoryGitTree.
32
from ..tree import (
33
    changes_between_git_tree_and_working_copy,
34
    )
0.369.1 by Jelmer Vernooij
Implement conflict handling.
35
from ..workingtree import (
36
    FLAG_STAGEMASK,
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
37
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
38
from ....tests import TestCaseWithTransport
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
39
40
41
class GitWorkingTreeTests(TestCaseWithTransport):
42
43
    def setUp(self):
44
        super(GitWorkingTreeTests, self).setUp()
45
        self.tree = self.make_branch_and_tree('.', format="git")
46
0.369.1 by Jelmer Vernooij
Implement conflict handling.
47
    def test_conflict_list(self):
0.369.2 by Jelmer Vernooij
Fix tests.
48
        self.assertIsInstance(
49
                self.tree.conflicts(),
50
                _mod_conflicts.ConflictList)
0.369.1 by Jelmer Vernooij
Implement conflict handling.
51
52
    def test_add_conflict(self):
53
        self.build_tree(['conflicted'])
54
        self.tree.add(['conflicted'])
55
        with self.tree.lock_tree_write():
56
            self.tree.index['conflicted'] = self.tree.index['conflicted'][:9] + (FLAG_STAGEMASK, )
0.415.3 by Jelmer Vernooij
Open index on demand.
57
            self.tree._index_dirty = True
0.369.1 by Jelmer Vernooij
Implement conflict handling.
58
        conflicts = self.tree.conflicts()
59
        self.assertEqual(1, len(conflicts))
0.385.1 by Jelmer Vernooij
Use specific_files argument to Tree.iter_entries_by_dir.
60
61
    def test_revert_empty(self):
62
        self.build_tree(['a'])
63
        self.tree.add(['a'])
64
        self.assertTrue(self.tree.is_versioned('a'))
65
        self.tree.revert(['a'])
66
        self.assertFalse(self.tree.is_versioned('a'))
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
67
68
69
class ChangesBetweenGitTreeAndWorkingCopyTests(TestCaseWithTransport):
70
71
    def setUp(self):
72
        super(ChangesBetweenGitTreeAndWorkingCopyTests, self).setUp()
73
        self.wt = self.make_branch_and_tree('.', format='git')
74
75
    def expectDelta(self, expected_changes,
76
                    expected_extras=None, want_unversioned=False):
77
        store = self.wt.branch.repository._git.object_store
78
        try:
79
            tree_id = store[self.wt.branch.repository._git.head()].tree
80
        except KeyError:
81
            tree_id = None
0.415.3 by Jelmer Vernooij
Open index on demand.
82
        with self.wt.lock_read():
83
            changes, extras = changes_between_git_tree_and_working_copy(
84
                store, tree_id, self.wt, want_unversioned=want_unversioned)
85
            self.assertEqual(expected_changes, list(changes))
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
86
        if expected_extras is None:
87
            expected_extras = set()
88
        self.assertEqual(set(expected_extras), set(extras))
89
90
    def test_empty(self):
91
        self.expectDelta(
92
            [((None, ''), (None, stat.S_IFDIR), (None, Tree().id))])
93
94
    def test_added_file(self):
95
        self.build_tree(['a'])
96
        self.wt.add(['a'])
97
        a = Blob.from_string('contents of a\n')
98
        t = Tree()
99
        t.add("a", stat.S_IFREG | 0o644, a.id)
100
        self.expectDelta(
101
            [((None, ''), (None, stat.S_IFDIR), (None, t.id)),
102
             ((None, 'a'), (None, stat.S_IFREG | 0o644), (None, a.id))])
103
104
    def test_added_unknown_file(self):
105
        self.build_tree(['a'])
106
        t = Tree()
107
        self.expectDelta(
108
            [((None, ''), (None, stat.S_IFDIR), (None, t.id))])
109
        a = Blob.from_string('contents of a\n')
110
        t = Tree()
111
        t.add("a", stat.S_IFREG | 0o644, a.id)
112
        self.expectDelta(
113
            [((None, ''), (None, stat.S_IFDIR), (None, t.id)),
114
             ((None, 'a'), (None, stat.S_IFREG | 0o644), (None, a.id))],
115
            ['a'],
116
            want_unversioned=True)
117
118
    def test_missing_added_file(self):
119
        self.build_tree(['a'])
120
        self.wt.add(['a'])
121
        os.unlink('a')
122
        a = Blob.from_string('contents of a\n')
123
        t = Tree()
124
        t.add("a", 0, ZERO_SHA)
125
        self.expectDelta(
126
            [((None, ''), (None, stat.S_IFDIR), (None, t.id)),
127
             ((None, 'a'), (None, 0), (None, ZERO_SHA))],
128
            [])
129
130
    def test_missing_versioned_file(self):
131
        self.build_tree(['a'])
132
        self.wt.add(['a'])
133
        self.wt.commit('')
134
        os.unlink('a')
135
        a = Blob.from_string('contents of a\n')
136
        oldt = Tree()
137
        oldt.add("a", stat.S_IFREG | 0o644, a.id)
138
        newt = Tree()
139
        newt.add("a", 0, ZERO_SHA)
140
        self.expectDelta(
141
                [(('', ''), (stat.S_IFDIR, stat.S_IFDIR), (oldt.id, newt.id)),
142
                 (('a', 'a'), (stat.S_IFREG|0o644, 0), (a.id, ZERO_SHA))])
143
144
    def test_versioned_replace_by_dir(self):
145
        self.build_tree(['a'])
146
        self.wt.add(['a'])
147
        self.wt.commit('')
148
        os.unlink('a')
149
        os.mkdir('a')
150
        olda = Blob.from_string('contents of a\n')
151
        oldt = Tree()
152
        oldt.add("a", stat.S_IFREG | 0o644, olda.id)
153
        newt = Tree()
154
        newa = Tree()
155
        newt.add("a", stat.S_IFDIR, newa.id)
156
        self.expectDelta([
157
            (('', ''),
158
            (stat.S_IFDIR, stat.S_IFDIR),
159
            (oldt.id, newt.id)),
160
            (('a', 'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
161
            ], want_unversioned=False)
162
        self.expectDelta([
163
            (('', ''),
164
            (stat.S_IFDIR, stat.S_IFDIR),
165
            (oldt.id, newt.id)),
166
            (('a', 'a'), (stat.S_IFREG | 0o644, stat.S_IFDIR), (olda.id, newa.id))
167
            ], want_unversioned=True)
168
169
    def test_extra(self):
170
        self.build_tree(['a'])
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
171
        newa = Blob.from_string(b'contents of a\n')
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
172
        newt = Tree()
173
        newt.add("a", stat.S_IFREG | 0o644, newa.id)
174
        self.expectDelta([
175
            ((None, ''),
176
            (None, stat.S_IFDIR),
177
            (None, newt.id)),
178
            ((None, 'a'), (None, stat.S_IFREG | 0o644), (None, newa.id))
179
            ], ['a'], want_unversioned=True)