fix(steps/git): use config_writer to set force-fetch refspec
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user