Skip to content

Comments

feat: support add/switch operations in bare repositories#147

Merged
k1LoW merged 1 commit intok1LoW:mainfrom
usadamasa:support-add-switch-bare
Feb 17, 2026
Merged

feat: support add/switch operations in bare repositories#147
k1LoW merged 1 commit intok1LoW:mainfrom
usadamasa:support-add-switch-bare

Conversation

@usadamasa
Copy link
Contributor

@usadamasa usadamasa commented Feb 16, 2026

Summary

#130 (Phase 2: add/switch operations)

  • Enable git wt <branch> (add/switch mode) in bare repositories and worktrees created from bare repos
  • Remove AssertNotBareRepository() guard for add/switch operations
  • Remove duplicate RepoRoot() (identical to CurrentWorktree())
  • Extract prepareAdd() / copyAfterAdd() helpers to share bare-aware logic between AddWorktree and AddWorktreeWithNewBranch
  • Skip file copying when running from bare root (no working tree to copy from)
  • Skip bare entries in FindWorktreeByBranchOrDir() to prevent matching the bare root as a worktree target
  • Fix ExcludeDirs logic: when source worktree is inside the basedir (bare-derived worktree), do not exclude the basedir from copy

Behavior

From bare root

$ cd /tmp/repo.git
$ git wt feature
# Creates new worktree with new branch "feature"
# No file copying (bare root has no working tree)

$ git wt feature
# Switches to existing worktree (outputs path)

From bare-derived worktree

$ cd /tmp/.wt/main
$ git wt feature2
# Creates new worktree with new branch "feature2"
# Copies untracked/ignored/modified files from current worktree (same as normal repos)

Operations NOT yet supported in bare repos

  • git wt -d <branch> (delete) — still returns error mentioning "bare"

Notes

  • I noticed that staged new files (added with git add but not yet committed) are not being copied. However, since this is out of scope for this PR, I’m leaving it as-is for now.

Test plan

  • Unit tests for AddWorktree / AddWorktreeWithNewBranch from bare repository
  • Unit tests for FindWorktreeByBranchOrDir bare entry skipping
  • E2E tests for direct bare add (new branch)
  • E2E tests for direct bare add with existing branch
  • E2E tests for direct bare add with start-point
  • E2E tests for bare switch to existing worktree
  • E2E tests for dotgit bare add (core.bare=true layout)
  • E2E tests for worktree-from-bare add
  • E2E tests for worktree-from-bare add with file copying (--copyuntracked)
  • E2E tests for bare add chain (bare → wt A → wt B → switch back)
  • E2E tests confirming delete still returns errors for bare repos

🤖 Generated with Claude Code

Enable worktree creation and switching from bare repository roots and
bare-derived worktrees. Previously these operations were blocked by
AssertNotBareRepository() guard.

Key changes:
- Remove RepoRoot() (duplicate of CurrentWorktree()) and unify callers
- Skip bare entries in FindWorktreeByBranchOrDir() to prevent false matches
- Extract prepareAdd()/copyAfterAdd() helpers from AddWorktree and
  AddWorktreeWithNewBranch, with bare-root detection to skip copy
- Fix ExcludeDirs logic: only exclude basedir when srcRoot is outside it,
  so bare-derived worktree copies work correctly
- Remove AssertNotBareRepository() guard for add/switch in cmd/root.go
- Add E2E tests for bare add, existing branch, start-point, switch,
  dotgit bare, and file copy from bare-derived worktrees

Closes k1LoW#130 (Phase 2)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@usadamasa usadamasa marked this pull request as ready for review February 16, 2026 14:37
@k1LoW k1LoW added enhancement New feature or request tagpr:minor labels Feb 17, 2026
@k1LoW
Copy link
Owner

k1LoW commented Feb 17, 2026

@usadamasa GREAT!!! I will start the review soon. Please wait a moment.

@k1LoW
Copy link
Owner

k1LoW commented Feb 17, 2026

@usadamasa LGTM! Thank you!!!

@k1LoW k1LoW merged commit 5bf1301 into k1LoW:main Feb 17, 2026
3 checks passed
@github-actions github-actions bot mentioned this pull request Feb 17, 2026
@usadamasa usadamasa deleted the support-add-switch-bare branch February 17, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tagpr:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants