forked from admin/brencher
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c57b6b1b69 | ||
|
|
99f8b73654 | ||
|
|
272504eab3 | ||
|
|
fa9f8791bd | ||
|
|
694c28109d | ||
|
|
090ab1f42a | ||
|
|
920249ec30 | ||
|
|
d6207d60e9 | ||
|
|
75126cb2fd | ||
|
|
0e83458044 | ||
|
|
7dc36d7487 | ||
|
|
b0e32f835a | ||
|
|
1c0580750d | ||
|
|
8059cc74ea | ||
|
|
6aed7a26c5 | ||
|
|
0190fc7474 |
@@ -20,16 +20,16 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
token: ${{ secrets.PUSH_TOKEN }}
|
||||
|
||||
- name: Configure git
|
||||
run: |
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git config user.name "GitHub Actions"
|
||||
git config user.email "gitea-actions[bot]@noreply.localhost"
|
||||
git config user.name "Gitea Actions"
|
||||
|
||||
- name: Fetch all branches
|
||||
run: |
|
||||
git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
|
||||
git remote set-url origin "https://x-access-token:${PUSH_TOKEN}@gitea.rudolf.keenetic.link/${GITHUB_REPOSITORY}.git"
|
||||
git fetch --all --prune
|
||||
|
||||
- name: Merge every branch onto main
|
||||
@@ -37,7 +37,6 @@ jobs:
|
||||
run: |
|
||||
set -eo pipefail
|
||||
MAIN=main
|
||||
# Collect remote branch names (exclude HEAD and main)
|
||||
branches=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin/ \
|
||||
| sed 's|^origin/||' \
|
||||
| grep -v -e '^HEAD$' -e '^main$' -e '^origin$' \
|
||||
@@ -49,11 +48,8 @@ jobs:
|
||||
continue
|
||||
fi
|
||||
echo "=== Processing branch: $br ==="
|
||||
# Create/update a local branch from remote
|
||||
git checkout -B "$br" "origin/$br"
|
||||
# Merge origin/main into branch (non-interactive)
|
||||
if git merge --no-edit "origin/$MAIN"; then
|
||||
# Push updated branch to remote (no force)
|
||||
if git push origin "$br"; then
|
||||
echo "Pushed merged $br"
|
||||
else
|
||||
|
||||
@@ -18,16 +18,16 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
token: ${{ secrets.PUSH_TOKEN }}
|
||||
|
||||
- name: Configure git
|
||||
run: |
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git config user.name "GitHub Actions"
|
||||
git config user.email "gitea-actions[bot]@noreply.localhost"
|
||||
git config user.name "Gitea Actions"
|
||||
|
||||
- name: Fetch all branches
|
||||
run: |
|
||||
git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
|
||||
git remote set-url origin "https://x-access-token:${PUSH_TOKEN}@gitea.rudolf.keenetic.link/${GITHUB_REPOSITORY}.git"
|
||||
git fetch --all --prune
|
||||
|
||||
- name: Merge every branch onto main
|
||||
@@ -35,7 +35,6 @@ jobs:
|
||||
run: |
|
||||
set -eo pipefail
|
||||
MAIN=main
|
||||
# Collect remote branch names (exclude HEAD and main)
|
||||
branches=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin/ \
|
||||
| sed 's|^origin/||' \
|
||||
| grep -v -e '^HEAD$' -e '^main$' -e '^origin$' \
|
||||
@@ -47,12 +46,9 @@ jobs:
|
||||
continue
|
||||
fi
|
||||
echo "=== Processing branch: $br ==="
|
||||
# Create/update a local branch from remote
|
||||
git reset --hard HEAD
|
||||
git checkout -B "$br" "origin/$br"
|
||||
# Merge origin/main into branch (non-interactive)
|
||||
if git merge --no-edit --squash "origin/$MAIN"; then
|
||||
# Push updated branch to remote (no force)
|
||||
git reset --soft "origin/$MAIN"
|
||||
git commit -m "Squash"
|
||||
if git push origin "$br" --force-with-lease; then
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
|
||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
|
||||
|
||||
name: Python package
|
||||
|
||||
on:
|
||||
@@ -10,74 +7,40 @@ on:
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
concurrency:
|
||||
group: ci-${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: [
|
||||
# "3.11.3",
|
||||
"3.12.3",
|
||||
"3.13",
|
||||
"3.14",
|
||||
# "3.15",
|
||||
]
|
||||
checker: [
|
||||
"python -c \"import sys; print(f'Python {sys.version}'); print(f'Build: {sys.version_info}'); print(f'Implementation: {sys.implementation}')\"",
|
||||
"pip list",
|
||||
"flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics",
|
||||
"flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics",
|
||||
# "ty check backend",
|
||||
"mypy --no-incremental --config-file mypy.ini backend tests",
|
||||
]
|
||||
python-version: ["3.12.3", "3.13", "3.14"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python ${{ matrix.python-version }}, ${{ matrix.checker }}
|
||||
uses: actions/setup-python@v3
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: 'pip'
|
||||
cache-dependency-path: |
|
||||
requirements.txt
|
||||
requirements-dev.txt
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
pip install -r requirements-dev.txt
|
||||
- name: Run checker
|
||||
run: ${{ matrix.checker }}
|
||||
|
||||
# tests:
|
||||
# runs-on: ubuntu-latest
|
||||
# needs: build
|
||||
# strategy:
|
||||
# fail-fast: false
|
||||
# matrix:
|
||||
# python-version: [
|
||||
# # "3.11.3",
|
||||
# "3.12.3",
|
||||
# "3.13",
|
||||
# "3.14",
|
||||
# # "3.15",
|
||||
# ]
|
||||
# checker: [
|
||||
# "pytest",
|
||||
# ]
|
||||
# steps:
|
||||
# - uses: actions/checkout@v4
|
||||
# - name: Set up Python ${{ matrix.python-version }}, ${{ matrix.checker }}
|
||||
# uses: actions/setup-python@v3
|
||||
# with:
|
||||
# python-version: ${{ matrix.python-version }}
|
||||
# - name: Install dependencies
|
||||
# run: |
|
||||
# # sudo apt-get update
|
||||
# # sudo apt-get upgrade -y
|
||||
# # sudo apt-get install -y --no-install-recommends git docker.io
|
||||
# python -m pip install --upgrade pip
|
||||
# pip install -r requirements-dev.txt
|
||||
# playwright install --with-deps chromium
|
||||
# - name: Run checker
|
||||
# run: "pytest"
|
||||
#
|
||||
#
|
||||
#
|
||||
- name: Lint (flake8)
|
||||
run: |
|
||||
flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics
|
||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||
|
||||
- name: Type-check (mypy)
|
||||
run: mypy --no-incremental --config-file mypy.ini backend tests
|
||||
@@ -17,3 +17,6 @@
|
||||
state: str # 'Active' or 'Pause'
|
||||
pipeline: Dict[str, Any]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,28 @@ from steps.docker import DockerSwarmCheck, DockerSwarmDeploy
|
||||
from steps.git import GitClone, CheckoutMerged, GitUnmerge
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
clone = GitClone(url="https://github.com/rudolf1/uber_backup.git", branchNamePrefix="ansible")
|
||||
# Dual-remote clone for the ansible mirror (the deploy target, not brencher itself).
|
||||
# - gitea_hermes is where the feature branch lives (hermes/ansible:*)
|
||||
# - gitea_admin is the live-deploy source (where brencher-bot reads compose files from)
|
||||
#
|
||||
# Why not github? github.com is unreachable from the brencher container -- the
|
||||
# proxy returns HTTP 403 on CONNECT tunnel, so the URL would always fail to
|
||||
# fetch. See backend/configs/docker_socket_proxy.py for the same migration.
|
||||
#
|
||||
# Why drop branchNamePrefix? GitClone only applies its prefix refspec to a
|
||||
# remote named "origin" (backend/steps/git.py ~L104); neither remote here is
|
||||
# named "origin", so the prefix would be a silent no-op. Both remotes fetch
|
||||
# their full refset instead.
|
||||
#
|
||||
# Why two remotes? The deploy step (DockerSwarmDeploy) checks out a specific
|
||||
# branch and uses the resulting checkout as wd for the compose path. With
|
||||
# gitea_hermes as primary, feature branches opened in the fork are picked up;
|
||||
# gitea_admin provides the live-deploy source as a fallback / for cross-fork
|
||||
# PRs. This matches the form in backend/configs/brencher.py after PR #3.
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/ansible"},
|
||||
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/ansible"},
|
||||
])
|
||||
|
||||
dockerSwarmCheck = DockerSwarmCheck(
|
||||
stack_name="gitea",
|
||||
|
||||
@@ -4,7 +4,10 @@ from steps.docker import DockerComposeBuild, DockerSwarmCheck, DockerSwarmDeploy
|
||||
from steps.git import GitClone, CheckoutMerged, GitUnmerge
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
clone = GitClone(url="https://github.com/rudolf1/uber_backup.git", branchNamePrefix="immoscout")
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/mcps"},
|
||||
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/mcps"},
|
||||
])
|
||||
|
||||
dockerSwarmCheck = DockerSwarmCheck(
|
||||
stack_name="gmail_mcp",
|
||||
@@ -23,7 +26,7 @@ checkoutMerged = CheckoutMerged(clone,
|
||||
buildDocker = DockerComposeBuild(clone,
|
||||
docker_repo_username="",
|
||||
docker_repo_password="",
|
||||
docker_compose_path="gmail-mcp-server/docker-compose.yml",
|
||||
docker_compose_path="docker-compose.yml",
|
||||
docker_repo_url="https://registry.rudolf.keenetic.link",
|
||||
publish=False,
|
||||
envs=lambda: {
|
||||
@@ -39,7 +42,7 @@ deployDocker = DockerSwarmDeploy(
|
||||
"version": "auto-" + checkoutMerged.progress().version,
|
||||
},
|
||||
stack_name="gmail_mcp",
|
||||
docker_compose_path="gmail-mcp-server/docker-compose.yml",
|
||||
docker_compose_path="docker-compose.yml",
|
||||
)
|
||||
|
||||
checkPing1 = UrlCheck(
|
||||
|
||||
@@ -4,7 +4,28 @@ from steps.docker import DockerSwarmCheck, DockerSwarmDeploy
|
||||
from steps.git import GitClone, CheckoutMerged, GitUnmerge
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
clone = GitClone(url="https://github.com/rudolf1/uber_backup.git", branchNamePrefix="ansible")
|
||||
# Dual-remote clone for the ansible mirror (the deploy target, not brencher itself).
|
||||
# - gitea_hermes is where the feature branch lives (hermes/ansible:*)
|
||||
# - gitea_admin is the live-deploy source (where brencher-bot reads compose files from)
|
||||
#
|
||||
# Why not github? github.com is unreachable from the brencher container -- the
|
||||
# proxy returns HTTP 403 on CONNECT tunnel, so the URL would always fail to
|
||||
# fetch. See backend/configs/docker_socket_proxy.py for the same migration.
|
||||
#
|
||||
# Why drop branchNamePrefix? GitClone only applies its prefix refspec to a
|
||||
# remote named "origin" (backend/steps/git.py ~L104); neither remote here is
|
||||
# named "origin", so the prefix would be a silent no-op. Both remotes fetch
|
||||
# their full refset instead.
|
||||
#
|
||||
# Why two remotes? The deploy step (DockerSwarmDeploy) checks out a specific
|
||||
# branch and uses the resulting checkout as wd for the compose path. With
|
||||
# gitea_hermes as primary, feature branches opened in the fork are picked up;
|
||||
# gitea_admin provides the live-deploy source as a fallback / for cross-fork
|
||||
# PRs. This matches the form in backend/configs/brencher.py after PR #3.
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/ansible"},
|
||||
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/ansible"},
|
||||
])
|
||||
|
||||
dockerSwarmCheck = DockerSwarmCheck(
|
||||
stack_name="hermes",
|
||||
|
||||
@@ -4,7 +4,28 @@ from steps.docker import DockerSwarmCheck, DockerSwarmDeploy
|
||||
from steps.git import GitClone, CheckoutMerged, GitUnmerge
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
clone = GitClone(url="https://github.com/rudolf1/uber_backup.git", branchNamePrefix="ansible")
|
||||
# Dual-remote clone for the ansible mirror (the deploy target, not brencher itself).
|
||||
# - gitea_hermes is where the feature branch lives (hermes/ansible:*)
|
||||
# - gitea_admin is the live-deploy source (where brencher-bot reads compose files from)
|
||||
#
|
||||
# Why not github? github.com is unreachable from the brencher container -- the
|
||||
# proxy returns HTTP 403 on CONNECT tunnel, so the URL would always fail to
|
||||
# fetch. See backend/configs/docker_socket_proxy.py for the same migration.
|
||||
#
|
||||
# Why drop branchNamePrefix? GitClone only applies its prefix refspec to a
|
||||
# remote named "origin" (backend/steps/git.py ~L104); neither remote here is
|
||||
# named "origin", so the prefix would be a silent no-op. Both remotes fetch
|
||||
# their full refset instead.
|
||||
#
|
||||
# Why two remotes? The deploy step (DockerSwarmDeploy) checks out a specific
|
||||
# branch and uses the resulting checkout as wd for the compose path. With
|
||||
# gitea_hermes as primary, feature branches opened in the fork are picked up;
|
||||
# gitea_admin provides the live-deploy source as a fallback / for cross-fork
|
||||
# PRs. This matches the form in backend/configs/brencher.py after PR #3.
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/ansible"},
|
||||
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/ansible"},
|
||||
])
|
||||
|
||||
dockerSwarmCheck = DockerSwarmCheck(
|
||||
stack_name="immich",
|
||||
|
||||
+11
-4
@@ -48,8 +48,13 @@ class GitClone(AbstractStep[str]):
|
||||
raise ValueError(f"Remote {name!r} requires a non-empty 'url' (string)")
|
||||
if name in seen:
|
||||
raise ValueError(f"Duplicate remote name: {name!r}")
|
||||
prefix_value = entry.get("prefix")
|
||||
if prefix_value is not None and not isinstance(prefix_value, str):
|
||||
raise ValueError(
|
||||
f"Remote {name!r} 'prefix' must be a string when set, got {type(prefix_value).__name__}"
|
||||
)
|
||||
seen.add(name)
|
||||
normalized.append({"name": name, "url": url_value})
|
||||
normalized.append({"name": name, "url": url_value, "prefix": prefix_value or ""})
|
||||
elif url is not None:
|
||||
if isinstance(url, str):
|
||||
raw = [url]
|
||||
@@ -103,10 +108,12 @@ class GitClone(AbstractStep[str]):
|
||||
remote.set_url(auth_url)
|
||||
else:
|
||||
remote = repo.create_remote(remote_name, auth_url)
|
||||
if remote_name == "origin" and self.branchNamePrefix != "":
|
||||
prefix = entry.get("prefix", "")
|
||||
effective_prefix = prefix or (self.branchNamePrefix if remote_name == "origin" else "")
|
||||
if effective_prefix:
|
||||
with repo.config_writer() as config:
|
||||
config.set_value('remote "origin"', "fetch",
|
||||
f"+refs/heads/{self.branchNamePrefix}/*:refs/remotes/origin/{self.branchNamePrefix}/*")
|
||||
config.set_value(f'remote "{remote_name}"', "fetch",
|
||||
f"+refs/heads/{effective_prefix}/*:refs/remotes/{remote_name}/{effective_prefix}/*")
|
||||
result = remote.fetch(prune=True)
|
||||
if not result or any(fetch_info.flags & fetch_info.ERROR for fetch_info in result):
|
||||
raise BaseException(f"Failed to fetch updates for {repository_url}")
|
||||
|
||||
@@ -11,3 +11,7 @@ types-PyYAML
|
||||
types-requests
|
||||
types-docker
|
||||
testcontainers
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
from enironment import wrap_in_cached, SharedStateConflictError
|
||||
from steps.shared_state import SharedStateHolderInMemory
|
||||
|
||||
from tests.test_remote_repo import RemoteRepoHelper
|
||||
|
||||
@@ -7,6 +8,24 @@ from tests.test_remote_repo import RemoteRepoHelper
|
||||
class TestCachedEnv:
|
||||
"""Tests for the CachedEnv wrapper around GitEnv."""
|
||||
|
||||
def test_inmemory_state_refreshes_removed_branch(self, repo_helper: RemoteRepoHelper) -> None:
|
||||
repo_helper.create_commit(repo_helper.repo, "master", "master", "file1.txt", "content1", "Initial commit")
|
||||
commit1 = repo_helper.create_commit(repo_helper.repo, "master", "branch1", "file2.txt", "content2", "Branch1 commit")
|
||||
commit2 = repo_helper.create_commit(repo_helper.repo, "master", "branch2", "file3.txt", "content3", "Branch2 commit")
|
||||
|
||||
repo_helper.set_desired_branches([("branch1", "HEAD"), ("branch2", "HEAD")])
|
||||
_ = repo_helper.checkout_merged.progress()
|
||||
setattr(repo_helper.mock_check, "version", lambda: f"auto-{commit1.hexsha[:8]}-{commit2.hexsha[:8]}")
|
||||
state = SharedStateHolderInMemory(repo_helper.git_unmerge)
|
||||
|
||||
assert state.progress().branches == [("branch1", commit1.hexsha), ("branch2", commit2.hexsha)]
|
||||
|
||||
repo_helper.delete_branch("branch2")
|
||||
repo_helper.git_clone.progress()
|
||||
|
||||
assert repo_helper.git_unmerge.progress().branches == [("branch1", commit1.hexsha)]
|
||||
assert state.progress().branches == [("branch1", commit1.hexsha)]
|
||||
|
||||
def test_checkout_merged_empty_branches(self, repo_helper: RemoteRepoHelper) -> None:
|
||||
"""Test CheckoutMerged with empty branches list - should fail"""
|
||||
|
||||
|
||||
@@ -101,6 +101,104 @@ class TestGitIntegration:
|
||||
with pytest.raises(ValueError, match="requires either 'url' or 'remotes'"):
|
||||
GitClone()
|
||||
|
||||
def test_git_clone_remotes_per_remote_prefix(self, repo_helper: RemoteRepoHelper) -> None:
|
||||
# Per-remote `prefix` filters fetch refspec so only matching branches are visible.
|
||||
# Two repos, two branches each (one matching the prefix, one not). Only the
|
||||
# matching branch should appear in get_branches() for each remote.
|
||||
def fresh_repo(prefix: str) -> str:
|
||||
path = tempfile.mkdtemp(prefix=prefix)
|
||||
repo = git.Repo.init(path, bare=False)
|
||||
with repo.config_writer() as cw:
|
||||
cw.set_value("user", "email", "test@example.com")
|
||||
cw.set_value("user", "name", "Test User")
|
||||
# Branches literally named `ansible/...` to match the prefix filter.
|
||||
# create_commit creates an initial master, then branches off it.
|
||||
repo_helper.create_commit(repo, "master", "master", "README.md", "content", f"{prefix} init")
|
||||
repo_helper.create_commit(repo, "master", "ansible/master", "AN.md", "ansible", f"{prefix} ansible")
|
||||
repo_helper.create_commit(repo, "master", "ansible/fix", "FIX.md", "fix", f"{prefix} fix")
|
||||
return path
|
||||
|
||||
github_dir = fresh_repo("test_prefix_github_")
|
||||
gitea_dir = fresh_repo("test_prefix_gitea_")
|
||||
try:
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "github", "url": github_dir, "prefix": "ansible"},
|
||||
{"name": "gitea_admin", "url": gitea_dir, "prefix": "ansible"},
|
||||
])
|
||||
clone.env = repo_helper.env
|
||||
|
||||
repo_path = clone.progress()
|
||||
repo = git.Repo(repo_path)
|
||||
|
||||
branches = set(clone.get_branches())
|
||||
# Per-remote refspec was applied: only ansible/* branches fetched.
|
||||
assert "github/ansible/master" in branches, f"missing: {branches}"
|
||||
assert "github/ansible/fix" in branches, f"missing: {branches}"
|
||||
assert "gitea_admin/ansible/master" in branches, f"missing: {branches}"
|
||||
assert "gitea_admin/ansible/fix" in branches, f"missing: {branches}"
|
||||
|
||||
# `master` exists upstream but is NOT visible (filtered by prefix).
|
||||
assert "github/master" not in branches, f"unwanted: {branches}"
|
||||
assert "gitea_admin/master" not in branches, f"unwanted: {branches}"
|
||||
finally:
|
||||
shutil.rmtree(github_dir, ignore_errors=True)
|
||||
shutil.rmtree(gitea_dir, ignore_errors=True)
|
||||
|
||||
def test_git_clone_remotes_mixed_prefix(self, repo_helper: RemoteRepoHelper) -> None:
|
||||
# Some remotes with prefix, others without. Each behaves independently:
|
||||
# prefixed remotes only see matching branches, unprefixed see all.
|
||||
def fresh_repo(prefix: str) -> str:
|
||||
path = tempfile.mkdtemp(prefix=prefix)
|
||||
repo = git.Repo.init(path, bare=False)
|
||||
with repo.config_writer() as cw:
|
||||
cw.set_value("user", "email", "test@example.com")
|
||||
cw.set_value("user", "name", "Test User")
|
||||
repo_helper.create_commit(repo, "master", "master", "README.md", "content", f"{prefix} init")
|
||||
repo_helper.create_commit(repo, "master", "ansible/master", "AN.md", "ansible", f"{prefix} ansible")
|
||||
repo_helper.create_commit(repo, "master", "feature_y", "OTHER.md", "other", f"{prefix} feature")
|
||||
return path
|
||||
|
||||
github_dir = fresh_repo("test_mixed_github_")
|
||||
gitea_dir = fresh_repo("test_mixed_gitea_")
|
||||
try:
|
||||
clone = GitClone(remotes=[
|
||||
{"name": "github", "url": github_dir, "prefix": "ansible"},
|
||||
{"name": "gitea_admin", "url": gitea_dir},
|
||||
])
|
||||
clone.env = repo_helper.env
|
||||
|
||||
repo_path = clone.progress()
|
||||
repo = git.Repo(repo_path)
|
||||
|
||||
branches = set(clone.get_branches())
|
||||
# Prefixed: only ansible/master.
|
||||
assert "github/ansible/master" in branches, f"missing: {branches}"
|
||||
assert "github/feature_y" not in branches, f"unwanted: {branches}"
|
||||
assert "github/master" not in branches, f"unwanted: {branches}"
|
||||
# Unprefixed: all branches visible.
|
||||
assert "gitea_admin/ansible/master" in branches, f"missing: {branches}"
|
||||
assert "gitea_admin/feature_y" in branches, f"missing: {branches}"
|
||||
assert "gitea_admin/master" in branches, f"missing: {branches}"
|
||||
finally:
|
||||
shutil.rmtree(github_dir, ignore_errors=True)
|
||||
shutil.rmtree(gitea_dir, ignore_errors=True)
|
||||
|
||||
def test_git_clone_remotes_prefix_validation(self) -> None:
|
||||
# `prefix` must be a string when set; non-string raises ValueError.
|
||||
with pytest.raises(ValueError, match="'prefix' must be a string"):
|
||||
GitClone(remotes=[
|
||||
{"name": "github", "url": "git@example.com:a/b.git", "prefix": 123},
|
||||
])
|
||||
with pytest.raises(ValueError, match="'prefix' must be a string"):
|
||||
GitClone(remotes=[
|
||||
{"name": "github", "url": "git@example.com:a/b.git", "prefix": ["ansible"]},
|
||||
])
|
||||
# Empty string / None: accepted, treated as no prefix.
|
||||
c1 = GitClone(remotes=[{"name": "github", "url": "git@example.com:a/b.git", "prefix": ""}])
|
||||
assert c1.remotes[0]["prefix"] == ""
|
||||
c2 = GitClone(remotes=[{"name": "github", "url": "git@example.com:a/b.git"}])
|
||||
assert c2.remotes[0]["prefix"] == ""
|
||||
|
||||
def test_checkout_merged_one_branch(self, repo_helper: RemoteRepoHelper) -> None:
|
||||
# Create main branch with initial commit
|
||||
commit1 = repo_helper.create_commit(repo_helper.repo, "master", "master", "file1.txt", "content1",
|
||||
|
||||
@@ -144,6 +144,14 @@ class RemoteRepoHelper:
|
||||
repo.index.add([filename])
|
||||
return repo.index.commit(message)
|
||||
|
||||
def delete_branch(self, branch_name: str) -> None:
|
||||
if not self.repo.head.is_detached and self.repo.active_branch.name == branch_name:
|
||||
remaining_heads = [head for head in self.repo.heads if head.name != branch_name]
|
||||
if not remaining_heads:
|
||||
raise ValueError(f"Cannot delete the only branch: {branch_name}")
|
||||
remaining_heads[0].checkout()
|
||||
self.repo.delete_head(branch_name, force=True)
|
||||
|
||||
def verify_working_directory_files(self, expected_files: List[Tuple[str, str]]) -> None:
|
||||
"""Verify that working directory contains exactly the expected files with correct content.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user