summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorL. E. Segovia <amy@amyspark.me>2022-11-30 18:39:54 -0300
committerXavier Claessens <xclaesse@gmail.com>2022-12-07 13:29:04 -0500
commit35599c536271c2d05c82b0f649ad1ab2f2d351d1 (patch)
treef22acbc5ace35d791a602bf00cd31ee5997c8f26
parentbcd50e71d51eac2fa8e1afbb30cb7d5260e0f42a (diff)
downloadmeson-35599c536271c2d05c82b0f649ad1ab2f2d351d1.tar.gz
wrap: Don't use --branch with shallow clones against HEAD
Fixes #10931
-rw-r--r--mesonbuild/wrap/wrap.py7
-rw-r--r--unittests/subprojectscommandtests.py18
2 files changed, 21 insertions, 4 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index e8c955a67..d949f430e 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -582,8 +582,11 @@ class Resolver:
verbose_git(['fetch', self.wrap.get('url'), revno], self.dirname, check=True)
verbose_git(checkout_cmd, self.dirname, check=True)
else:
- verbose_git(['-c', 'advice.detachedHead=false', 'clone', *depth_option, '--branch', revno, self.wrap.get('url'),
- self.directory], self.subdir_root, check=True)
+ args = ['-c', 'advice.detachedHead=false', 'clone', *depth_option]
+ if revno.lower() != 'head':
+ args += ['--branch', revno]
+ args += [self.wrap.get('url'), self.directory]
+ verbose_git(args, self.subdir_root, check=True)
if self.wrap.values.get('clone-recursive', '').lower() == 'true':
verbose_git(['submodule', 'update', '--init', '--checkout', '--recursive', *depth_option],
self.dirname, check=True)
diff --git a/unittests/subprojectscommandtests.py b/unittests/subprojectscommandtests.py
index edd6ac168..bca124d4d 100644
--- a/unittests/subprojectscommandtests.py
+++ b/unittests/subprojectscommandtests.py
@@ -103,15 +103,20 @@ class SubprojectsCommandTests(BasePlatformTests):
self._git_remote(['commit', '--no-gpg-sign', '--allow-empty', '-m', f'tag {tag} commit'], name)
self._git_remote(['tag', '--no-sign', tag], name)
- def _wrap_create_git(self, name, revision='master'):
+ def _wrap_create_git(self, name, revision='master', depth=None):
path = self.root_dir / name
with open(str((self.subprojects_dir / name).with_suffix('.wrap')), 'w', encoding='utf-8') as f:
+ if depth is None:
+ depth_line = ''
+ else:
+ depth_line = 'depth = {}'.format(depth)
f.write(textwrap.dedent(
'''
[wrap-git]
url={}
revision={}
- '''.format(os.path.abspath(str(path)), revision)))
+ {}
+ '''.format(os.path.abspath(str(path)), revision, depth_line)))
def _wrap_create_file(self, name, tarball='dummy.tar.gz'):
path = self.root_dir / tarball
@@ -205,6 +210,15 @@ class SubprojectsCommandTests(BasePlatformTests):
self._subprojects_cmd(['update', '--reset'])
self.assertEqual(self._git_local_commit(subp_name), self._git_remote_commit(subp_name))
+ # Create a fake remote git repository and a wrap file targeting
+ # HEAD and depth = 1. Checks that "meson subprojects download" works.
+ subp_name = 'sub3'
+ self._git_create_remote_repo(subp_name)
+ self._wrap_create_git(subp_name, revision='head', depth='1')
+ self._subprojects_cmd(['download'])
+ self.assertPathExists(str(self.subprojects_dir / subp_name))
+ self._git_config(self.subprojects_dir / subp_name)
+
@skipIfNoExecutable('true')
def test_foreach(self):
self._create_project(self.subprojects_dir / 'sub_file')