Repository navigation
Git - remember the last selected worktree location - #348040
Merged
Ladislau Szomoru (lszomoru) merged 1 commit intoNov 13, 2026
Merged
Ladislau Szomoru (lszomoru) merged 1 commit into
Ladislau Szomoru (lszomoru) merged 1 commit into
Conversation
The Create Worktree command again stores the parent folder of the worktree the user created, so it is suggested next time. Repository.createWorktree (also used by the extension API) no longer writes the remembered location, so API callers that pass an explicit path do not overwrite the user's choice. Fixes #284185 Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change restoring the remembered worktree location behavior.
No open issues 🎉
What changed in this PR
Restores Git’s last-selected worktree location behavior, addressing #284185 after the worktree API refactor.
Changes:
- Saves the parent folder after successful interactive worktree creation, including when no location was previously stored.
- Prevents extension API callers from overwriting the user’s remembered location while preserving it as the default for branch-only calls.
| File | Description |
|---|---|
extensions/git/src/repository.ts |
Removes remembered-location writes from shared worktree creation. |
extensions/git/src/commands.ts |
Persists the last-used location in the interactive command. |
Review effort: Balanced
Ladislau Szomoru (lszomoru)
marked this pull request as ready for review
November 13, 2026 08:28
Ladislau Szomoru (lszomoru)
enabled auto-merge (squash)
November 13, 2026 08:28
Alexandru Dima (alexdima)
approved these changes
Nov 13, 2026
Ladislau Szomoru (lszomoru)
deleted the
lszomoru/agents/fix-worktree-location-persistence-bug
branch
November 13, 2026 09:10
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 #284185
Repro steps
<parent>/app).feature-one.<parent>/app.worktrees/feature-one, for example<parent>/custom-worktrees/feature-one(type it or use the folder button).feature-two.<parent>/app.worktrees/feature-twoagain instead of<parent>/custom-worktrees/feature-two.Root cause
Before #278107, the
git.createWorktreecommand saved the parent folder of the worktree the user created under theworktreeRoot:<repository root>global state key whenever it differed from the stored value. The refactor moved this intoRepository.createWorktree()and changed the condition todefaultWorktreeRoot && !pathEquals(newWorktreeRoot, defaultWorktreeRoot). While nothing is stored yet, which is the case for every repository after the refactor,defaultWorktreeRootisundefinedand nothing is ever written. As a result, the first custom location is never remembered and the command keeps suggesting<repo>.worktrees/....Because the write now lived in
Repository.createWorktree(), it also ran for extension API callers (Repository.createWorktreeingit.d.ts). Once a value was stored, an API caller that passes an explicitpathcould overwrite the user's choice. For example, Copilot recreates an unarchived session worktree at its original path.Fix
CommandCenter._createWorktree()(the interactive command) now savespath.dirname()of the created worktree when it differs from the stored value or nothing is stored. This restores the behavior from before Git - refactor create/delete worktree and expose extension API #278107: the folder the user last picked is suggested next time. Picking the default location stores the default folder, which is harmless and makes the setting reflect what the user last used.Repository.createWorktree()still reads the remembered folder to build the default path for branch-only callers, but no longer writes it. Extension API callers, including ones that pass an explicitpath(such as the Agents window or Copilotagents-*/copilot-*worktrees), no longer change the user's remembered location. For branch-only callers the computed parent folder is already the remembered or default folder, so dropping the write there loses nothing.No new git processes; the change only touches global state handling.
Validation
pnpm run gulp compile-extension:gitnode_modules/.bin/tsc -p extensions/git/tsconfig.json --noEmitmain)pnpm run eslint extensions/git/src/commands.ts extensions/git/src/repository.ts./scripts/test-integration.sh --suite gitpath)node test/scenario/out/runScenario.js --dev <scenario>with the fix reverted (before)<parent>/app.worktrees/feature-twoinstead of<parent>/custom-worktrees/feature-twonode test/scenario/out/runScenario.js --dev <scenario>with the fix (after)<parent>/custom-worktrees/feature-twoThe UI scenario (using the
validate-ui-scenarioharness) drives a Code OSS dev build of this branch with a fresh profile against a scratch repository in a temp folder:feature-one), confirm that<parent>/app.worktrees/feature-oneis suggested, replace it with<parent>/custom-worktrees/feature-one, and confirm that the worktree is created on disk.feature-two) and assert that the path input box suggests<parent>/custom-worktrees/feature-two.The "before" run used the same build with only this change reverted. The native folder picker can't be automated, so the scenario types the custom path into the input box. The command accepts a typed path the same way.
Before/after captioned recordings and per-step screenshots exist for both runs. GitHub doesn't accept video uploads through the CLI, so they're available on request. Before: the second Create Worktree suggests
app.worktrees/feature-two. After: it suggestscustom-worktrees/feature-two.No unit test was added: no pure function changed, and the behavior lives in an interactive quick input flow, which the UI scenario above covers.