Extract branch name when in detached mode#2
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the branch name detection functionality to work reliably in detached HEAD state, which commonly occurs in CI environments during pull/merge requests. The implementation adds fallback mechanisms to extract branch names from CI environment variables and uses git name-rev when git symbolic-ref fails.
- Enhanced branch detection with CI environment variable support for GitHub Actions, GitLab CI, and Bitbucket Pipelines
- Added fallback to
git name-revwhen in detached HEAD state - Improved error handling and user feedback for branch name determination failures
Reviewed Changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pre_commit_hooks/branch_check.py | Adds get_forge_branch() and get_branch_name() functions with enhanced branch detection logic |
| README.md | Documents the new branch detection behavior and fallback mechanisms |
| .github/workflows/CI.yml | Adds GitHub Actions workflow for continuous integration testing |
| .github/pre-commit-config.yaml | Adds pre-commit configuration for testing the branch check hook |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prefer known environment variables set by software forges during CI.
Use
git name-revwhen in detached mode. Detect detached mode by runninggit symbolic-refand let it fail when detached.Whenever necessary, analyze the branch in chunks separated by
/and skip the two first ones, this is becausegit name-revaddsremotes/origin.Close #1