/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
0.369.1 by Jelmer Vernooij
Implement conflict handling.
32
from ..workingtree import (
33
    FLAG_STAGEMASK,
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
34
    changes_between_git_tree_and_working_copy,
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
35
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
36
from ....tests import TestCaseWithTransport
0.262.1 by Jelmer Vernooij
Fix WorkingTree.conflicts().
37
38
39
class GitWorkingTreeTests(TestCaseWithTransport):
40
41
    def setUp(self):
42
        super(GitWorkingTreeTests, self).setUp()
43
        self.tree = self.make_branch_and_tree('.', format="git")
44
0.369.1 by Jelmer Vernooij
Implement conflict handling.
45
    def test_conflict_list(self):
0.369.2 by Jelmer Vernooij
Fix tests.
46
        self.assertIsInstance(
47
                self.tree.conflicts(),
48
                _mod_conflicts.ConflictList)
0.369.1 by Jelmer Vernooij
Implement conflict handling.
49
50
    def test_add_conflict(self):
51
        self.build_tree(['conflicted'])
52
        self.tree.add(['conflicted'])
53
        with self.tree.lock_tree_write():
54
            self.tree.index['conflicted'] = self.tree.index['conflicted'][:9] + (FLAG_STAGEMASK, )
55
        conflicts = self.tree.conflicts()
56
        self.assertEqual(1, len(conflicts))
0.385.1 by Jelmer Vernooij
Use specific_files argument to Tree.iter_entries_by_dir.
57
58
    def test_revert_empty(self):
59
        self.build_tree(['a'])
60
        self.tree.add(['a'])
61
        self.assertTrue(self.tree.is_versioned('a'))
62
        self.tree.revert(['a'])
63
        self.assertFalse(self.tree.is_versioned('a'))
0.391.7 by Jelmer Vernooij
Fix reporting of missing files in .iter_changes.
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)