Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for InvalidGitRepositoryError under certain conditions #15735

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions awx/main/tasks/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,16 @@
project_path = project.get_project_path(check_if_exists=False)
if project.scm_type == 'git' and (scm_branch and scm_branch != project.scm_branch):
if os.path.exists(project_path):
git_repo = git.Repo(project_path)
if git_repo.head.is_detached:
is_commit = True
original_branch = git_repo.head.commit
else:
original_branch = git_repo.active_branch
try:
git_repo = git.Repo(project_path)

Check warning on line 788 in awx/main/tasks/jobs.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tasks/jobs.py#L787-L788

Added lines #L787 - L788 were not covered by tests
if git_repo.head.is_detached:
is_commit = True
original_branch = git_repo.head.commit

Check warning on line 791 in awx/main/tasks/jobs.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tasks/jobs.py#L790-L791

Added lines #L790 - L791 were not covered by tests
else:
original_branch = git_repo.active_branch
except git.exc.InvalidGitRepositoryError:
logger.error(f"Invalid git repository at {project_path}. Removing directory and continuing.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log would lose too much information. I'd prefer convert logger.error to logger.exception. Because, diving into questions about what this fixes, the answers were too broad. It could be because the entire directory contents were deleted, but it could be due to a ratelimiting error leaving corrupted data. Not having the specific error pinned down in the planning of this, we definitely need to at absolute minimum have that information in the logs when this happens.

shutil.rmtree(project_path)

Check warning on line 796 in awx/main/tasks/jobs.py

View check run for this annotation

Codecov / codecov/patch

awx/main/tasks/jobs.py#L793-L796

Added lines #L793 - L796 were not covered by tests

return self.sync_and_copy_without_lock(project, private_data_dir, scm_branch=scm_branch)
finally:
Expand Down
Loading