Git: show commit amend option on detached HEAD#305034
Open
Sathvik-Chowdary-Veerapaneni wants to merge 1 commit intomicrosoft:mainfrom
Open
Git: show commit amend option on detached HEAD#305034Sathvik-Chowdary-Veerapaneni wants to merge 1 commit intomicrosoft:mainfrom
Sathvik-Chowdary-Veerapaneni wants to merge 1 commit intomicrosoft:mainfrom
Conversation
When working on a detached HEAD, the commit button dropdown was returning no secondary commands, hiding the amend option. This change shows commit and commit amend commands for detached HEAD while still excluding post-commit commands (push/sync) that don't apply without a tracking branch. Fixes microsoft#247936
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
Author
|
@microsoft-github-policy-service agree |
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.
Fixes #247936
Problem
When working on a detached HEAD (e.g.,
git checkout HEAD~1), the commit button dropdown in the Source Control view shows no secondary commands. This means the "Commit (Amend)" option is not available, even though amending commits is a common and valid workflow on detached HEADs.Root Cause
In
actionButton.ts,getCommitActionButtonSecondaryCommands()returns an empty array whenHEADis a tag or has no branch name (detached HEAD). This was likely done to avoid showing post-commit commands like "Push" and "Sync" that don't apply without a tracking branch, but it also incorrectly hid the basic "Commit" and "Commit (Amend)" options.Fix
Instead of returning an empty array for detached HEAD, the method now returns a command group containing the "Commit" and "Commit (Amend)" commands. Post-commit commands (push/sync from providers) are still excluded since they require a tracking branch.
The fix matches the existing patterns in
getCommitActionButtonPrimaryCommand()(which already correctly shows a plain "Commit" command for detached HEAD) andpostCommitCommands.tsgetCommitCommands()(which already defines both commit and amend commands).Test Plan
git checkout HEAD~1)