diff --git a/taf/updater/updater_pipeline.py b/taf/updater/updater_pipeline.py index e53d5ce3..b1f251cc 100644 --- a/taf/updater/updater_pipeline.py +++ b/taf/updater/updater_pipeline.py @@ -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: @@ -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 @@ -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