Skip to content

Fix GitCommitInfo task to handle grafted repository state gracefully #10211

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

Merged
merged 2 commits into from
Jun 16, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 16, 2025

The GitCommitInfo MSBuild task was failing with an error when encountering "grafted" repository states, which can occur when copilot or other git operations create grafted repositories.

Problem:
When git log -n 1 --pretty=%D HEAD returns output starting with "grafted" (e.g., "grafted, HEAD"), the current parsing logic doesn't recognize this format and throws an error:

error : Unable to parse branch name from: grafted, HEAD

This causes the build to fail instead of handling the edge case gracefully.

Solution:
Added support for detecting "grafted" repository states in both the C# implementation (GitCommitInfo.cs) and the corresponding shell script (get-git-branch.sh). When a grafted repository is detected:

  • Logs a warning instead of an error
  • Sets the branch name to "unknown" (consistent with other ambiguous cases)
  • Allows the build to continue successfully

Changes:

  • GitCommitInfo.cs: Added new condition to handle branchFull.StartsWith("grafted")
  • get-git-branch.sh: Added corresponding logic to maintain sync between implementations

Impact:

  • Builds now succeed with a warning instead of failing when encountering grafted repositories
  • All existing branch detection patterns continue to work unchanged
  • Minimal code changes (7 lines added total)

Fixes #10210.


💡 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.

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [copilot] build can fail on <GitCommitInfo/> task Fix GitCommitInfo task to handle grafted repository state gracefully Jun 16, 2025
@Copilot Copilot AI requested a review from jonathanpeppers June 16, 2025 18:31
Copilot finished work on behalf of jonathanpeppers June 16, 2025 18:31
@jonathanpeppers jonathanpeppers marked this pull request as ready for review June 16, 2025 19:07
@jonathanpeppers jonathanpeppers enabled auto-merge (squash) June 16, 2025 19:11
@jonathanpeppers jonathanpeppers merged commit 48fdbad into main Jun 16, 2025
59 checks passed
@jonathanpeppers jonathanpeppers deleted the copilot/fix-10210 branch June 16, 2025 20:12
@github-actions github-actions bot locked and limited conversation to collaborators Jul 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[copilot] build can fail on <GitCommitInfo/> task
2 participants