Skip to content

Commit

Permalink
Fix: Fix setting last updated commit when pushing and update when onl…
Browse files Browse the repository at this point in the history
…y auth repo updated

If only the auth repo was updated, commits from which the update of target repos should start were not being determined correctly. Additionally, checking if repo is a test repo did not work for bare repos. Only update last validated commit if pushing to the default branch.
  • Loading branch information
renatav committed Jan 4, 2025
1 parent 82377f5 commit 12e9941
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
29 changes: 15 additions & 14 deletions taf/auth_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,23 @@ def commit_and_push(
if commit:
if commit_msg is None:
commit_msg = input("\nEnter commit message and press ENTER\n\n")
self.commit(commit_msg)

if push:
push_successful = self.push()
if push_successful:
new_commit_branch = self.default_branch
if new_commit_branch:
new_commit = self.top_commit_of_branch(new_commit_branch)
if new_commit:
new_commit = self.commit(commit_msg)

if new_commit and push:
push_successful = self.push()
if push_successful:
current_branch = self.get_current_branch()
if current_branch == self.default_branch:
self.set_last_validated_of_repo(
self.name, new_commit, set_last_validated_commit=True
)
self._log_notice(
f"Updated last_validated_commit to {new_commit}"
)
else:
self._log_warning(
"Default branch is None, skipping last_validated_commit update."
)
else:
self._log_warning(
"Default branch is None, skipping last_validated_commit update."
)

def get_target(self, target_name, commit=None, safely=True) -> Optional[Dict]:
if commit is None:
Expand Down Expand Up @@ -335,7 +333,10 @@ def auth_repo_commits_after_repos_last_validated(

repo = self.pygit_repo

walker = repo.walk(repo.head.target, pygit2.GIT_SORT_TOPOLOGICAL)
default_branch = repo.lookup_branch(self.default_branch)
top_commit = default_branch.peel()

walker = repo.walk(top_commit.id, pygit2.GIT_SORT_TOPOLOGICAL)

traversed_commits = []
for commit in walker:
Expand Down
7 changes: 4 additions & 3 deletions taf/updater/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from typing import Dict, Tuple, Any
from attr import define, field
from logdecorator import log_on_error
from taf.auth_repo import AuthenticationRepository
from taf.git import GitRepository
from taf.updater.types.update import OperationType, UpdateType
from taf.updater.updater_pipeline import (
Expand Down Expand Up @@ -636,11 +637,11 @@ def validate_repository(
else:
library_dir = Path(library_dir).resolve()

auth_repo = AuthenticationRepository(path=auth_path)
expected_repo_type = (
UpdateType.TEST
if (auth_path / "targets" / "test-auth-repo").exists()
else UpdateType.OFFICIAL
UpdateType.TEST if auth_repo.is_test_repo else UpdateType.OFFICIAL
)

auth_repo_name = None

try:
Expand Down
8 changes: 6 additions & 2 deletions taf/updater/updater_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,10 +1065,13 @@ def set_auth_commit_for_target_repos(self):
repo_name: self._get_last_validated_commit(repo_name)
for repo_name in self.state.users_target_repositories
}
last_commits_per_repos[
self.state.users_auth_repo.name
] = self._get_last_validated_commit(self.state.users_auth_repo.name)

last_validated_target_commits = list(set(last_commits_per_repos.values()))
last_validated_commits = list(set(last_commits_per_repos.values()))

if len(last_validated_target_commits) > 1:
if len(last_validated_commits) > 1:
# not all target repositories were updated at the same time
# updater was run with --exclude-targets
# check if the repositories are in sync according to that data
Expand Down Expand Up @@ -2118,6 +2121,7 @@ def _update_tuf_current_revision(git_fetcher, updater, auth_repo_name):
# using refresh, we have updated all main roles
# we still need to update the delegated roles (if there are any)
# and validate any target files

current_targets = git_fetcher.get_current_targets()
for target_path in current_targets:
target_filepath = target_path.replace("\\", "/")
Expand Down

0 comments on commit 12e9941

Please sign in to comment.