Skip to content

Commit

Permalink
chore: using --force for running git checkout to prevent issues like #…
Browse files Browse the repository at this point in the history
  • Loading branch information
tromai committed Oct 31, 2023
1 parent 1b7740b commit a9bc8c5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/macaron/slsa_analyzer/git_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def check_out_repo_target(git_obj: Git, branch_name: str = "", digest: str = "",

try:
# Switch to the target branch by running ``git checkout <branch_name>`` in the target repository.
git_obj.repo.git.checkout(res_branch)
# We need to use force checkout to prevent issues similar to https://github.com/oracle/macaron/issues/530.
git_obj.repo.git.checkout("--force", res_branch)
except GitCommandError as error:
logger.error("Cannot checkout branch %s. Error: %s", res_branch, error)
return False
Expand Down Expand Up @@ -150,8 +151,9 @@ def check_out_repo_target(git_obj: Git, branch_name: str = "", digest: str = "",

if digest:
# Checkout the specific commit that the user want by running ``git checkout <commit>`` in the target repository.
# We need to use force checkout to prevent issues similar to https://github.com/oracle/macaron/issues/530.
try:
git_obj.repo.git.checkout(digest)
git_obj.repo.git.checkout("--force", digest)
except GitCommandError as error:
logger.error(
"Commit %s cannot be checked out. Error: %s",
Expand Down

0 comments on commit a9bc8c5

Please sign in to comment.