fix(steps/git): use config_writer to set force-fetch refspec
Python package / build (3.12.3) (pull_request) Successful in 2m35s
Python package / build (3.13) (pull_request) Successful in 2m47s
Python package / build (3.14) (pull_request) Canceled after 35s

GitPython Remote does not expose a set_refspec method. Use
repo.config_writer() to set remote.<name>.fetch '+refs/heads/*:refs/remotes/<name>/*'.
This bypasses the default safety against updating remote-tracking refs
that diverge from their upstream (force-pushed branches).

Sets the refspec for every remote, not just 'origin', so multi-remote
configs like connectivity_tester (hermes/ansible + admin/ansible) pick
up force-pushed branches on either side.
This commit is contained in:
hermes
2026-09-18 21:48:34 +00:00
parent 0bb705fc3e
commit 3dd0657733
+6 -1
View File
@@ -103,13 +103,18 @@ class GitClone(AbstractStep[str]):
remote.set_url(auth_url)
else:
remote = repo.create_remote(remote_name, auth_url)
with repo.config_writer() as config:
config.set_value(
f'remote "{remote_name}".fetch',
f'+refs/heads/*:refs/remotes/{remote_name}/*',
)
if remote_name == "origin" and self.branchNamePrefix != "":
with repo.config_writer() as config:
config.set_value('remote "origin"', "fetch",
f"+refs/heads/{self.branchNamePrefix}/*:refs/remotes/origin/{self.branchNamePrefix}/*")
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}")
raise BaseException(f"Failed to fetch updates for {remote_name}")
if not os.path.exists(os.path.join(self.repo_path, ".git")):
raise BaseException(f"Failed to clone repositories {self.remotes} to {self.repo_path}")
except BaseException as e: