Files
root 469af15045
GitHub Git mirror / mirror (push) Skipped
Development CI / check-and-package (push) Successful in 4m3s
Development CI / image (push) Successful in 28s
Development CI / deploy-development (push) Successful in 11s
ci: separate dev deployment, main checks and GitHub mirroring
2026-10-29 21:03:01 +08:00

37 lines
1.8 KiB
Python

"""Verify strict mirroring with isolated local repositories."""
import os
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from mirror import git, references, synchronize
class MirrorTests(unittest.TestCase):
def test_full_history_tags_deletions_and_failed_source(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
source, target = root / 'source', root / 'target.git'
subprocess.run(['git', 'init', '-b', 'main', str(source)], check=True, capture_output=True)
subprocess.run(['git', 'init', '--bare', str(target)], check=True, capture_output=True)
(source / 'note.md').write_text('synthetic note')
git(source, 'add', '.')
git(source, '-c', 'user.name=Test', '-c', '[email protected]', 'commit', '-m', 'test')
git(source, 'branch', 'dev')
git(source, '-c', 'user.name=Test', '-c', '[email protected]', 'tag', '-a', 'test-tag', '-m', 'test')
state = root / 'state'
synchronize(state, str(source), str(target), os.environ.copy())
self.assertEqual(references(source), references(target))
git(source, 'branch', '-D', 'dev')
git(source, 'tag', '-d', 'test-tag')
git(target, 'branch', 'target-only', 'main')
synchronize(state, str(source), str(target), os.environ.copy())
self.assertEqual(references(source), references(target))
before = references(target)
with self.assertRaises(subprocess.CalledProcessError):
synchronize(state, str(root / 'missing'), str(target), os.environ.copy())
self.assertEqual(before, references(target))