Skip to content

Commit

Permalink
Merge pull request #1221 from camptocamp/backport/1220-to-3.5
Browse files Browse the repository at this point in the history
[Backport 3.5] Retry from scratch on fetch error
  • Loading branch information
sbrunner authored Feb 11, 2025
2 parents d4f1b3f + eddf471 commit 4f82ad7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
- run: c2cciutils-docker-logs
if: failure()

- run: git reset --hard
- name: Publish
run: c2cciutils-publish
if: env.HAS_SECRETS == 'HAS_SECRETS'
Expand Down
16 changes: 12 additions & 4 deletions app/shared_config_manager/sources/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import json
import logging
import os
import subprocess
import tempfile
from pathlib import Path

from shared_config_manager.configuration import SourceStatus
from shared_config_manager.sources import mode
Expand All @@ -26,11 +28,17 @@ def _checkout(self) -> None:
cwd = self._clone_dir()
repo = self._get_repo()
branch = self.get_branch()
if os.path.isdir(os.path.join(cwd, ".git")):
git_dir = Path(cwd) / ".git"
if git_dir.is_dir():
LOG.info("Fetching a new version of %s", repo)
self._exec("git", "fetch", "--depth=1", "origin", branch, cwd=cwd)
self._exec("git", "checkout", branch, cwd=cwd)
self._exec("git", "reset", "--hard", f"origin/{branch}", cwd=cwd)
try:
self._exec("git", "fetch", "--depth=1", "origin", branch, cwd=cwd)
self._exec("git", "checkout", branch, cwd=cwd)
self._exec("git", "reset", "--hard", f"origin/{branch}", cwd=cwd)
except subprocess.CalledProcessError:
LOG.warning("Failed to fetch a new version of %s, retry checkout", repo)
self._exec("rm", "-rf", git_dir)
self._checkout()
elif self._do_sparse():
LOG.info("Cloning %s (sparse)", repo)
self._exec("git-sparse-clone", repo, branch, cwd, self._config["sub_dir"], cwd=TEMP_DIR)
Expand Down

0 comments on commit 4f82ad7

Please sign in to comment.