Skip to content

Conversation

fernandosantos-br
Copy link
Collaborator

…dling

@Copilot Copilot AI review requested due to automatic review settings July 23, 2025 22:35
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Enhances the current commit resolution logic in GitUtils by adding a fallback mechanism to improve reliability when resolving Git references. The change adds error handling and alternative resolution strategies when the primary reference resolution fails.

  • Implements nested try-catch blocks for robust current commit resolution
  • Adds fallback logic to try remote branch format when local branch resolution fails
  • Includes debug and warning logging for better troubleshooting

self.logger.debug(
f"Successfully resolved current ref: {git_info.current_ref}"
)
except Exception:
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

Catching generic Exception is too broad. Consider catching specific Git-related exceptions like GitCommandError or BadName to avoid masking unexpected errors.

Suggested change
except Exception:
except BadName:

Copilot uses AI. Check for mistakes.

)
self.logger.debug(f"Trying remote ref: {remote_ref}")
current_commit = self.repo.commit(remote_ref)
except Exception as e:
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

Catching generic Exception is too broad. Consider catching specific Git-related exceptions like GitCommandError or BadName to avoid masking unexpected errors.

Suggested change
except Exception as e:
except (GitCommandError, BadName) as e:

Copilot uses AI. Check for mistakes.

"refs/heads/", "origin/"
)
self.logger.debug(f"Trying remote ref: {remote_ref}")
current_commit = self.repo.commit(remote_ref)
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

This line can raise an exception that won't be caught by the inner try-catch block at line 147, potentially causing the outer catch block to trigger unexpectedly. The remote_ref resolution should be wrapped in its own try-catch block.

Suggested change
current_commit = self.repo.commit(remote_ref)
try:
current_commit = self.repo.commit(remote_ref)
except Exception as e:
self.logger.debug(
f"Failed to resolve remote ref '{remote_ref}': {e}"
)
raise

Copilot uses AI. Check for mistakes.

"refs/pull"
):
# Resolve current commit with fallback logic
try:
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

[nitpick] The nested try-catch structure creates complex control flow. Consider extracting the commit resolution logic into a separate method to improve readability and maintainability.

Copilot uses AI. Check for mistakes.

@fernandosantos-br fernandosantos-br merged commit d517e9e into main Jul 23, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants