1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
# vim: set fileencoding=utf-8 :
#
# (C) 2021 Andrej Shadura <andrew@shadura.me>
# (C) 2021 Collabora Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, please see
# <http://www.gnu.org/licenses/>
import os
from tests.component import (ComponentTestBase,
ComponentTestGitRepository)
from tests.component.deb.fixtures import RepoFixtures
from gbp.scripts.clone import main as clone
from gbp.scripts.setup_gitattributes import main as setup_gitattributes
sorted_gitattrs = [
'# Added by git-buildpackage to disable .gitattributes found in the upstream tree',
'* -export-ignore',
'* -export-subst',
'* dgit-defuse-attrs',
'[attr]dgit-defuse-attrs -text -eol -crlf -ident -filter -working-tree-encoding',
]
dgit_attributes = [
'*\tdgit-defuse-attrs',
'[attr]dgit-defuse-attrs\t-text -eol -crlf -ident -filter -working-tree-encoding',
'# ^ see GITATTRIBUTES in dgit(7) and dgit setup-new-tree in dgit(1)'
]
dgit34_attributes = [
'*\tdgit-defuse-attrs',
'[attr]dgit-defuse-attrs\t-text -eol -crlf -ident -filter',
'# ^ see dgit(7). To undo, leave a definition of [attr]dgit-defuse-attrs'
]
class TestSetupGitattributes(ComponentTestBase):
"""Test setting up Git attributes"""
@RepoFixtures.native()
def test_setup_gitattrs_do_nothing(self, repo):
"""Test that disabling all knows presets works and gives an error"""
dest = os.path.join(self._tmpdir,
'cloned_repo')
clone(['arg0',
repo.path, dest])
cloned = ComponentTestGitRepository(dest)
self._check_repo_state(cloned, 'master', ['master'])
attrs_file = os.path.join(dest, '.git', 'info', 'attributes')
# file shouldn’t exist at this point yet
self.assertFalse(os.path.exists(attrs_file) and os.path.getsize(attrs_file),
"%s is non-empty" % attrs_file)
os.chdir(cloned.path)
setup_gitattributes(['arg0', '--no-dgit-defuse-attrs'])
# file shouldn’t exist at this point yet
self.assertFalse(os.path.exists(attrs_file) and os.path.getsize(attrs_file),
"%s is non-empty" % attrs_file)
self._check_log(-1,
"gbp:error: Nothing to do, no settings to apply.")
@RepoFixtures.native()
def test_setup_gitattrs(self, repo):
"""Test that setting up Git attributes manually works"""
dest = os.path.join(self._tmpdir,
'cloned_repo')
clone(['arg0',
repo.path, dest])
cloned = ComponentTestGitRepository(dest)
self._check_repo_state(cloned, 'master', ['master'])
attrs_file = os.path.join(dest, '.git', 'info', 'attributes')
# file shouldn’t exist at this point yet
self.assertFalse(os.path.exists(attrs_file) and os.path.getsize(attrs_file),
"%s is non-empty" % attrs_file)
os.chdir(cloned.path)
setup_gitattributes(['arg0'])
assert os.path.exists(attrs_file), "%s is missing" % attrs_file
with open(attrs_file) as f:
attrs = sorted(f.read().splitlines())
self.assertEqual(attrs, sorted_gitattrs)
@RepoFixtures.native()
def test_setup_gitattrs_dgit(self, repo):
"""Test that setting up Git attributes manually works even with dgit"""
dest = os.path.join(self._tmpdir,
'cloned_repo')
clone(['arg0',
repo.path, dest])
cloned = ComponentTestGitRepository(dest)
self._check_repo_state(cloned, 'master', ['master'])
attrs_file = os.path.join(dest, '.git', 'info', 'attributes')
# file shouldn’t exist at this point yet
self.assertFalse(os.path.exists(attrs_file) and os.path.getsize(attrs_file),
"%s is non-empty" % attrs_file)
with open(attrs_file, 'w') as f:
f.write('\n'.join(dgit_attributes))
os.chdir(cloned.path)
setup_gitattributes(['arg0', '--verbose'])
assert os.path.exists(attrs_file), "%s is missing" % attrs_file
with open(attrs_file) as f:
attrs = sorted(f.read().splitlines())
expected_gitattrs = sorted(sorted_gitattrs + [
'# Old dgit macro disabled:',
'# [attr]dgit-defuse-attrs\t-text -eol -crlf -ident -filter -working-tree-encoding',
'# ^ see GITATTRIBUTES in dgit(7) and dgit setup-new-tree in dgit(1)',
])
self.assertEqual(attrs, expected_gitattrs)
@RepoFixtures.native()
def test_setup_gitattrs_dgit34(self, repo):
"""Test that setting up Git attributes manually works even with a very old dgit"""
dest = os.path.join(self._tmpdir,
'cloned_repo')
clone(['arg0',
repo.path, dest])
cloned = ComponentTestGitRepository(dest)
self._check_repo_state(cloned, 'master', ['master'])
attrs_file = os.path.join(dest, '.git', 'info', 'attributes')
# file shouldn’t exist at this point yet
self.assertFalse(os.path.exists(attrs_file) and os.path.getsize(attrs_file),
"%s is non-empty" % attrs_file)
with open(attrs_file, 'w') as f:
f.write('\n'.join(dgit34_attributes))
os.chdir(cloned.path)
setup_gitattributes(['arg0', '--verbose'])
assert os.path.exists(attrs_file), "%s is missing" % attrs_file
with open(attrs_file) as f:
attrs = sorted(f.read().splitlines())
expected_gitattrs = sorted(sorted_gitattrs + [
'# Old dgit macro disabled:',
'# [attr]dgit-defuse-attrs\t-text -eol -crlf -ident -filter',
'# ^ see dgit(7). To undo, leave a definition of [attr]dgit-defuse-attrs',
])
self.assertEqual(attrs, expected_gitattrs)
|