Skip to content

Commit 299ce78

Browse files
authored
Merge pull request #10417 from bensze01/abicheck-worktree-submodules-3.6
[3.6 backport] Use submodule work trees during ABI check
2 parents f2021e2 + 616f9fd commit 299ce78

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

scripts/abi_check.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,32 @@ def _update_git_submodules(self, git_worktree_path, version):
197197
"""If the crypto submodule is present, initialize it.
198198
if version.crypto_revision exists, update it to that revision,
199199
otherwise update it to the default revision"""
200-
update_output = subprocess.check_output(
201-
[self.git_command, "submodule", "update", "--init", '--recursive'],
202-
cwd=git_worktree_path,
200+
submodule_output = subprocess.check_output(
201+
[self.git_command, "submodule", "foreach", "--recursive",
202+
f'git worktree add --detach "{git_worktree_path}/$displaypath" HEAD'],
203+
cwd=self.repo_path,
203204
stderr=subprocess.STDOUT
204205
)
206+
self.log.debug(submodule_output.decode("utf-8"))
207+
208+
try:
209+
# Try to update the submodules using local commits
210+
# (Git will sometimes insist on fetching the remote without --no-fetch
211+
# if the submodules are shallow clones)
212+
update_output = subprocess.check_output(
213+
[self.git_command, "submodule", "update", "--init", '--recursive', '--no-fetch'],
214+
cwd=git_worktree_path,
215+
stderr=subprocess.STDOUT
216+
)
217+
except subprocess.CalledProcessError as err:
218+
self.log.debug(err.stdout.decode("utf-8"))
219+
220+
# Checkout with --no-fetch failed, falling back to fetching from origin
221+
update_output = subprocess.check_output(
222+
[self.git_command, "submodule", "update", "--init", '--recursive'],
223+
cwd=git_worktree_path,
224+
stderr=subprocess.STDOUT
225+
)
205226
self.log.debug(update_output.decode("utf-8"))
206227
if not (os.path.exists(os.path.join(git_worktree_path, "crypto"))
207228
and version.crypto_revision):
@@ -378,8 +399,15 @@ def _get_storage_format_tests(self, version, git_worktree_path):
378399
def _cleanup_worktree(self, git_worktree_path):
379400
"""Remove the specified git worktree."""
380401
shutil.rmtree(git_worktree_path)
402+
submodule_output = subprocess.check_output(
403+
[self.git_command, "submodule", "foreach", "--recursive",
404+
f'git worktree remove "{git_worktree_path}/$displaypath"'],
405+
cwd=self.repo_path,
406+
stderr=subprocess.STDOUT
407+
)
408+
self.log.debug(submodule_output.decode("utf-8"))
381409
worktree_output = subprocess.check_output(
382-
[self.git_command, "worktree", "prune"],
410+
[self.git_command, "worktree", "remove", git_worktree_path],
383411
cwd=self.repo_path,
384412
stderr=subprocess.STDOUT
385413
)

0 commit comments

Comments
 (0)