Skip to content

Commit

Permalink
fix: validation should not fail if local branch doesn't exist, but re…
Browse files Browse the repository at this point in the history
…mote does

When only validating repositories, validation would fail if there were
no local branches. Commits can still be listed based given a remote branch.
Local branches do not exist after a repository is cloned unless it is checked out.
  • Loading branch information
renatav committed Feb 3, 2024
1 parent c01fc00 commit 8e10776
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions taf/updater/updater_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,14 +674,15 @@ def get_target_repositories_commits(self):
for branch in self.state.target_branches_data_from_auth_repo[
repository.name
]:
local_branch_exists = repository.branch_exists(
branch, include_remotes=False
)
branch_exists = repository.branch_exists(branch, include_remotes=True)
if repository not in self.state.cloned_target_repositories:
if self.only_validate:
branch_exists = repository.branch_exists(
branch, include_remotes=False
)
if not branch_exists:
self.state.targets_data = {}
msg = f"{repository.name} does not contain a local branch named {branch} and cannot be validated. Please update the repositories."
msg = f"{repository.name} does not contain a branch named {branch} and cannot be validated. Please update the repositories."
taf_logger.error(msg)
raise UpdateFailedError(msg)
else:
Expand Down Expand Up @@ -716,10 +717,7 @@ def get_target_repositories_commits(self):
)
fetched_commits_on_target_repo_branch.insert(0, old_head)
else:
branch_exists = repository.branch_exists(
branch, include_remotes=False
)
if branch_exists:
if local_branch_exists:
# this happens in the case when last_validated_commit does not exist
# we want to validate all commits, so combine existing commits and
# fetched commits
Expand All @@ -730,20 +728,19 @@ def get_target_repositories_commits(self):
)
else:
fetched_commits_on_target_repo_branch = []
if not self.only_validate:
try:
fetched_commits = repository.all_commits_on_branch(
branch=f"origin/{branch}"
)
try:
fetched_commits = repository.all_commits_on_branch(
branch=f"origin/{branch}"
)

# if the local branch does not exist (the branch was not checked out locally)
# fetched commits will include already validated commits
# check which commits are newer that the previous head commit
for commit in fetched_commits:
if commit not in fetched_commits_on_target_repo_branch:
fetched_commits_on_target_repo_branch.append(commit)
except GitError:
pass
# if the local branch does not exist (the branch was not checked out locally)
# fetched commits will include already validated commits
# check which commits are newer that the previous head commit
for commit in fetched_commits:
if commit not in fetched_commits_on_target_repo_branch:
fetched_commits_on_target_repo_branch.append(commit)
except GitError:
pass
self.state.fetched_commits_per_target_repos_branches[repository.name][
branch
] = fetched_commits_on_target_repo_branch
Expand Down

0 comments on commit 8e10776

Please sign in to comment.