fix: offer stash/migrate options when creating a branch with dirty worktree#304986
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: offer stash/migrate options when creating a branch with dirty worktree#304986yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…rktree When creating a branch from a specific ref with uncommitted changes, git checkout -b fails with DirtyWorkTree but the error is not handled gracefully. Unlike the regular checkout command, the branch creation command does not offer the user the option to stash, migrate, or force discard their changes. Add error handling for DirtyWorkTree in _branch() that mirrors the existing _checkout() behavior, presenting the user with Stash & Checkout, Migrate Changes, and Force Checkout options. Closes microsoft#191900
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
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.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
When using "Git: Create Branch From..." with uncommitted changes, if the target ref differs from the current HEAD, git fails with a DirtyWorkTree error that is not handled gracefully. The user sees a generic error without any option to stash, migrate, or discard their changes.
This is inconsistent with the regular checkout behavior, which presents a dialog with "Stash & Checkout", "Migrate Changes", and "Force Checkout" options.
Closes #191900
What is the new behavior?
The
_branch()method now catchesDirtyWorkTreeerrors and presents the same dialog as the checkout command:This mirrors the existing error handling in
_checkout().Additional context
The fix follows the exact same pattern used in
_checkout()(around line 2960 of commands.ts) for handling DirtyWorkTree errors, ensuring consistent behavior across all branch switching operations.