Skip to content

Clarify git check-ref-format --branch behavior in/out of git repo#54

Closed
Copilot wants to merge 1 commit intovalidate-branchfrom
copilot/sub-pr-53
Closed

Clarify git check-ref-format --branch behavior in/out of git repo#54
Copilot wants to merge 1 commit intovalidate-branchfrom
copilot/sub-pr-53

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 3, 2025

Answered review question about whether git check-ref-format --branch behaves identically inside vs outside a git repository.

Behavior Difference

The --branch flag expands "previous checkout syntax" (@{-1}, @{-2}, etc.) to actual branch names only when run inside a git repository. Outside a repo, it treats these as invalid branch names.

Current Implementation

The is_valid_branch_name() function correctly uses cwd=empty_dir to ensure consistent validation independent of repository checkout history:

def is_valid_branch_name(branch: str) -> bool:
    with tempfile.TemporaryDirectory() as empty_dir:
        command = ["git", "check-ref-format", "--branch", branch]
        result = subprocess.run(command, cwd=empty_dir, capture_output=True, text=True)
        return result.returncode == 0

This validates the branch name string itself, not what it might expand to in a specific repository context.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix branch names validation behavior in git repository Clarify git check-ref-format --branch behavior in/out of git repo Dec 3, 2025
Copilot AI requested a review from dwilding December 3, 2025 12:28
@dwilding dwilding closed this Dec 3, 2025
@dwilding dwilding deleted the copilot/sub-pr-53 branch December 3, 2025 12:36
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