mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 15:36:18 -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
|
|
@ -207,3 +207,33 @@ async def test_import_refuses(test_session, test_directory, async_client, test_w
|
|||
repo = await lib.import_repository(test_session, 'code/ssh-clone', url='https://git.example.com/owner/library',
|
||||
confirm=True)
|
||||
assert repo.url == 'https://git.example.com/owner/library'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_import_checks_before_moving(test_session, test_directory, async_client, test_wrolpi_config,
|
||||
user_clone):
|
||||
"""Everything which can refuse an import is checked before the clone is moved."""
|
||||
directory, _ = user_clone()
|
||||
(directory / 'other').mkdir()
|
||||
(directory / 'other/.git').write_text(f'gitdir: {test_directory}\n')
|
||||
with pytest.raises(InvalidRepo, match='outside'):
|
||||
await lib.import_repository(test_session, 'code/kiwix-tools', confirm=True)
|
||||
test_session.rollback()
|
||||
assert (directory / '.git').is_dir()
|
||||
assert not (test_directory / 'repos/kiwix-tools').exists()
|
||||
assert test_session.query(Repository).count() == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_import_moves_back_on_failure(test_session, test_directory, async_client, test_wrolpi_config,
|
||||
user_clone):
|
||||
"""If the import fails after the move, the clone is moved back."""
|
||||
from mock import mock
|
||||
directory, _ = user_clone()
|
||||
with mock.patch('modules.repos.lib.mark_clone', side_effect=OSError('disk full')):
|
||||
with pytest.raises(OSError):
|
||||
await lib.import_repository(test_session, 'code/kiwix-tools', confirm=True)
|
||||
test_session.rollback()
|
||||
assert (directory / '.git').is_dir()
|
||||
assert not (test_directory / 'repos/kiwix-tools').exists()
|
||||
assert test_session.query(Repository).count() == 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue