Skip to content

Commit 9e36923

Browse files
committed
wrap: Don't use --branch with shallow clones against HEAD
Fixes #10931
1 parent d0054f2 commit 9e36923

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

mesonbuild/wrap/wrap.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,11 @@ def get_git(self) -> None:
582582
verbose_git(['fetch', self.wrap.get('url'), revno], self.dirname, check=True)
583583
verbose_git(checkout_cmd, self.dirname, check=True)
584584
else:
585-
verbose_git(['-c', 'advice.detachedHead=false', 'clone', *depth_option, '--branch', revno, self.wrap.get('url'),
586-
self.directory], self.subdir_root, check=True)
585+
args = ['-c', 'advice.detachedHead=false', 'clone', *depth_option]
586+
if revno.lower() != 'head':
587+
args += ['--branch', revno]
588+
args += [self.wrap.get('url'), self.directory]
589+
verbose_git(args, self.subdir_root, check=True)
587590
if self.wrap.values.get('clone-recursive', '').lower() == 'true':
588591
verbose_git(['submodule', 'update', '--init', '--checkout', '--recursive', *depth_option],
589592
self.dirname, check=True)

unittests/subprojectscommandtests.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,20 @@ def _git_create_remote_tag(self, name, tag):
103103
self._git_remote(['commit', '--no-gpg-sign', '--allow-empty', '-m', f'tag {tag} commit'], name)
104104
self._git_remote(['tag', '--no-sign', tag], name)
105105

106-
def _wrap_create_git(self, name, revision='master'):
106+
def _wrap_create_git(self, name, revision='master', depth=None):
107107
path = self.root_dir / name
108108
with open(str((self.subprojects_dir / name).with_suffix('.wrap')), 'w', encoding='utf-8') as f:
109+
if depth is None:
110+
depth_line = ''
111+
else:
112+
depth_line = 'depth = {}'.format(depth)
109113
f.write(textwrap.dedent(
110114
'''
111115
[wrap-git]
112116
url={}
113117
revision={}
114-
'''.format(os.path.abspath(str(path)), revision)))
118+
{}
119+
'''.format(os.path.abspath(str(path)), revision, depth_line)))
115120

116121
def _wrap_create_file(self, name, tarball='dummy.tar.gz'):
117122
path = self.root_dir / tarball
@@ -138,6 +143,14 @@ def test_git_update(self):
138143
self.assertPathExists(str(self.subprojects_dir / subp_name))
139144
self._git_config(self.subprojects_dir / subp_name)
140145

146+
# Create a fake remote git repository and a wrap file targeting
147+
# HEAD and depth = 1. Checks that "meson subprojects download" works.
148+
self._git_create_remote_repo(subp_name)
149+
self._wrap_create_git(subp_name, revision='head', depth='1')
150+
self._subprojects_cmd(['download'])
151+
self.assertPathExists(str(self.subprojects_dir / subp_name))
152+
self._git_config(self.subprojects_dir / subp_name)
153+
141154
# Create a new remote branch and update the wrap file. Checks that
142155
# "meson subprojects update --reset" checkout the new branch.
143156
self._git_create_remote_branch(subp_name, 'newbranch')

0 commit comments

Comments
 (0)