1
# Copyright (C) 2020 Jelmer Vernooij <jelmer@jelmer.uk>
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.
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.
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
20
TestCaseWithTransport,
23
from .scenarios import load_tests_apply_scenarios
25
from ..workspace import (
32
load_tests = load_tests_apply_scenarios
35
class CheckCleanTreeTests(TestCaseWithTransport):
37
def make_test_tree(self, format=None):
38
tree = self.make_branch_and_tree('.', format=format)
39
self.build_tree_contents([
41
('debian/control', """\
43
Vcs-Git: https://example.com/blah
44
Testsuite: autopkgtest
50
('debian/changelog', 'Some contents')])
51
tree.add(['debian', 'debian/changelog', 'debian/control'])
52
tree.commit('Initial thingy.')
55
def test_pending_changes(self):
56
tree = self.make_test_tree()
57
self.build_tree_contents([('debian/changelog', 'blah')])
58
with tree.lock_write():
60
WorkspaceDirty, check_clean_tree, tree)
62
def test_pending_changes_bzr_empty_dir(self):
63
# See https://bugs.debian.org/914038
64
tree = self.make_test_tree(format='bzr')
65
self.build_tree_contents([('debian/upstream/', )])
66
with tree.lock_write():
68
WorkspaceDirty, check_clean_tree, tree)
70
def test_pending_changes_git_empty_dir(self):
71
# See https://bugs.debian.org/914038
72
tree = self.make_test_tree(format='git')
73
self.build_tree_contents([('debian/upstream/', )])
74
with tree.lock_write():
75
check_clean_tree(tree)
77
def test_pending_changes_git_dir_with_ignored(self):
78
# See https://bugs.debian.org/914038
79
tree = self.make_test_tree(format='git')
80
self.build_tree_contents([
81
('debian/upstream/', ),
82
('debian/upstream/blah', ''),
83
('.gitignore', 'blah\n'),
85
tree.add('.gitignore')
86
tree.commit('add gitignore')
87
with tree.lock_write():
88
check_clean_tree(tree)
91
tree = self.make_test_tree()
92
self.build_tree_contents([('debian/foo', 'blah')])
93
with tree.lock_write():
95
WorkspaceDirty, check_clean_tree,
99
def vary_by_inotify():
101
('with_inotify', dict(_use_inotify=True)),
102
('without_inotify', dict(_use_inotify=False)),
106
def vary_by_format():
108
('bzr', dict(_format='bzr')),
109
('git', dict(_format='git')),
113
class WorkspaceTests(TestCaseWithTransport):
115
scenarios = multiply_scenarios(
120
def test_root_add(self):
121
tree = self.make_branch_and_tree('.', format=self._format)
122
with Workspace(tree, use_inotify=self._use_inotify) as ws:
123
self.build_tree_contents([('afile', 'somecontents')])
124
changes = [c for c in ws.iter_changes() if c.path[1] != '']
125
self.assertEqual(1, len(changes), changes)
126
self.assertEqual((None, 'afile'), changes[0].path)
127
ws.commit(message='Commit message')
128
self.assertEqual(list(ws.iter_changes()), [])
129
self.build_tree_contents([('afile', 'newcontents')])
130
[change] = list(ws.iter_changes())
131
self.assertEqual(('afile', 'afile'), change.path)
133
def test_root_remove(self):
134
tree = self.make_branch_and_tree('.', format=self._format)
135
self.build_tree_contents([('afile', 'somecontents')])
138
with Workspace(tree, use_inotify=self._use_inotify) as ws:
140
changes = list(ws.iter_changes())
141
self.assertEqual(1, len(changes), changes)
142
self.assertEqual(('afile', None), changes[0].path)
143
ws.commit(message='Commit message')
144
self.assertEqual(list(ws.iter_changes()), [])
146
def test_subpath_add(self):
147
tree = self.make_branch_and_tree('.', format=self._format)
148
self.build_tree(['subpath/'])
150
tree.commit('add subpath')
152
tree, subpath='subpath', use_inotify=self._use_inotify) as ws:
153
self.build_tree_contents([('outside', 'somecontents')])
154
self.build_tree_contents([('subpath/afile', 'somecontents')])
155
changes = [c for c in ws.iter_changes() if c.path[1] != 'subpath']
156
self.assertEqual(1, len(changes), changes)
157
self.assertEqual((None, 'subpath/afile'), changes[0].path)
158
ws.commit(message='Commit message')
159
self.assertEqual(list(ws.iter_changes()), [])
161
def test_dirty(self):
162
tree = self.make_branch_and_tree('.', format=self._format)
163
self.build_tree(['subpath'])
165
WorkspaceDirty, Workspace(tree, use_inotify=self._use_inotify).__enter__)
167
def test_reset(self):
168
tree = self.make_branch_and_tree('.', format=self._format)
169
with Workspace(tree, use_inotify=self._use_inotify) as ws:
170
self.build_tree(['blah'])
172
self.assertPathDoesNotExist('blah')
174
def test_tree_path(self):
175
tree = self.make_branch_and_tree('.', format=self._format)
177
tree.commit('Add subdir')
178
with Workspace(tree, use_inotify=self._use_inotify) as ws:
179
self.assertEqual('foo', ws.tree_path('foo'))
180
self.assertEqual('', ws.tree_path())
181
with Workspace(tree, subpath='subdir', use_inotify=self._use_inotify) as ws:
182
self.assertEqual('subdir/foo', ws.tree_path('foo'))
183
self.assertEqual('subdir/', ws.tree_path())
185
def test_abspath(self):
186
tree = self.make_branch_and_tree('.', format=self._format)
188
tree.commit('Add subdir')
189
with Workspace(tree, use_inotify=self._use_inotify) as ws:
190
self.assertEqual(tree.abspath('foo'), ws.abspath('foo'))
191
self.assertEqual(tree.abspath(''), ws.abspath())
192
with Workspace(tree, subpath='subdir', use_inotify=self._use_inotify) as ws:
193
self.assertEqual(tree.abspath('subdir/foo'), ws.abspath('foo'))
194
self.assertEqual(tree.abspath('subdir') + '/', ws.abspath(''))
195
self.assertEqual(tree.abspath('subdir') + '/', ws.abspath())
197
def test_open_containing(self):
198
tree = self.make_branch_and_tree('.', format=self._format)
200
tree.commit('Add subdir')
201
ws = Workspace.from_path('subdir')
202
self.assertEqual(ws.tree.abspath('.'), tree.abspath('.'))
203
self.assertEqual(ws.subpath, 'subdir')
204
self.assertEqual(None, ws.use_inotify)