Skip to content

Extract branch name when in detached mode#2

Merged
efrecon merged 11 commits intomainfrom
bugfix/1-proper-branch-name-at-github
Aug 25, 2025
Merged

Extract branch name when in detached mode#2
efrecon merged 11 commits intomainfrom
bugfix/1-proper-branch-name-at-github

Conversation

@efrecon
Copy link
Copy Markdown
Owner

@efrecon efrecon commented Aug 20, 2025

Prefer known environment variables set by software forges during CI.

Use git name-rev when in detached mode. Detect detached mode by running git symbolic-ref and let it fail when detached.

Whenever necessary, analyze the branch in chunks separated by / and skip the two first ones, this is because git name-rev adds remotes/origin.

Close #1

@efrecon efrecon requested a review from Copilot August 20, 2025 15:02

This comment was marked as outdated.

@efrecon efrecon requested a review from Copilot August 25, 2025 07:42
Copy link
Copy Markdown

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

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-rev when 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>
@efrecon efrecon merged commit 0c3e51b into main Aug 25, 2025
1 check 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.

Name of branch is HEAD in a GitHub Workflow

2 participants