mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 05:39:57 -05:00
repos: submodule links must stay in the repo; import checks before it moves
* A submodule's working-tree `.git` names the git directory git uses for it. Before any submodule command (update, or deinit when submodules are turned off), and before an import, every `.git` below the top of the working tree must be a file pointing inside the repo's own .git/modules; a link, a directory, or a file pointing elsewhere could make git use a config that was never checked. * Import validates and sanitizes the clone where it is, then moves it, and moves it back if marking it fails, so a refused or failed import never leaves a clone moved without a Repo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d0ea6ab313
commit
4b034ae3ee
4 changed files with 141 additions and 14 deletions
|
|
@ -13,7 +13,7 @@ from wrolpi.downloader import Downloader, Download, DownloadContext, DownloadRes
|
|||
from wrolpi.errors import DownloadError
|
||||
from .lib import git_command, git_env, find_readme, get_repo_size, is_valid_branch, read_readme_text, \
|
||||
submodule_fetch_config, resolve_repo_addresses, pin_config, HostAddresses, clone_ownership_error, mark_clone, \
|
||||
sanitize_git_config, new_clone_token
|
||||
sanitize_git_config, new_clone_token, working_tree_git_error
|
||||
from .models import Repository
|
||||
|
||||
__all__ = ['GitDownloader', 'git_downloader', 'PreparedRepo', 'ExecutedRepo', 'parse_git_progress']
|
||||
|
|
@ -185,6 +185,10 @@ class GitDownloader(Downloader):
|
|||
git commands that git runs)."""
|
||||
directory = prepared.directory
|
||||
git = lambda *args, **kwargs: self._git(download, ctx, directory, *args, **kwargs) # noqa: E731
|
||||
# Every submodule command uses the git directory a submodule's `.git` names; it must be one that was checked.
|
||||
if (error := await asyncio.to_thread(working_tree_git_error, directory)) and (
|
||||
prepared.submodules or (directory / '.git/modules').is_dir()):
|
||||
return error
|
||||
if not prepared.submodules:
|
||||
if (directory / '.git/modules').is_dir():
|
||||
# Submodules were turned off; the repo is a mirror of only its own files now.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue