diff --git a/README.md b/README.md index 71c4ab0..124b356 100644 --- a/README.md +++ b/README.md @@ -99,11 +99,11 @@ Columns: ### `git-wt migrate` -Bring existing branch worktrees under `git-wt` management. +Bring existing Git worktrees under `git-wt` management. - Moves the main worktree into `/main/` when it is still a plain clone at `` or on the old layout at `/main`. -- Creates managed worktrees for local branches that do not already have one. - Renames existing non-managed branch worktrees into the managed path format. +- Does not create worktrees for local branches that do not already have one. Use `--prompt` | `-p` to review the proposed migrations before applying them. diff --git a/internal/gitwt/gitwt_migrate.go b/internal/gitwt/gitwt_migrate.go index 9477bf8..e34773c 100644 --- a/internal/gitwt/gitwt_migrate.go +++ b/internal/gitwt/gitwt_migrate.go @@ -259,8 +259,7 @@ func migrationCandidatesFromRepository(repository *Repository) ([]migrateCandida return nil, fmt.Errorf("get current directory: %w", err) } - branchesByWorktree := make(map[string]string, len(porcelainWorktrees)) - candidates := make([]migrateCandidate, 0) + candidates := make([]migrateCandidate, 0, len(porcelainWorktrees)) for _, porcelainWorktree := range porcelainWorktrees { if porcelainWorktree.BranchRef == "" { continue @@ -271,7 +270,6 @@ func migrationCandidatesFromRepository(repository *Repository) ([]migrateCandida continue } - branchesByWorktree[branchName] = porcelainWorktree.Path if filepath.Clean(porcelainWorktree.Path) == filepath.Clean(mainPath) { continue } @@ -291,25 +289,6 @@ func migrationCandidatesFromRepository(repository *Repository) ([]migrateCandida }) } - branches, err := repository.localBranches() - if err != nil { - return nil, err - } - - for _, branchName := range branches { - if _, ok := branchesByWorktree[branchName]; ok { - continue - } - - targetPath := managedWorktreePath(mainPath, branchName) - candidates = append(candidates, migrateCandidate{ - Action: "create", - Name: branchName, - TargetPath: targetPath, - DisplayTargetPath: currentRelativePath(currentDirectory, targetPath), - }) - } - slices.SortFunc(candidates, func(left, right migrateCandidate) int { return cmp.Compare(left.Name, right.Name) }) diff --git a/internal/gitwt/gitwt_test.go b/internal/gitwt/gitwt_test.go index 017ae67..a828133 100644 --- a/internal/gitwt/gitwt_test.go +++ b/internal/gitwt/gitwt_test.go @@ -905,6 +905,8 @@ func TestListFailsWhenBranchHasNoUpstream(t *testing.T) { testRepository := newTestRepository(t) testRepository.createLocalBranch(t, branchName) + legacyPath := filepath.Join(testRepository.rootPath, "legacy-no-upstream") + runGitCommand(t, testRepository.mainPath, "worktree", "add", legacyPath, branchName) testRepository.runGitWT(t, "migrate") result := testRepository.runGitWT(t, "list") @@ -1143,7 +1145,7 @@ func TestMigrateMovesPlainCloneMainIntoNestedLayout(t *testing.T) { } } -func TestMigratePlainCloneCreatesBranchWorktreesUnderRoot(t *testing.T) { +func TestMigratePlainCloneLeavesExistingBranchesWithoutWorktrees(t *testing.T) { const branchName = "dev" testRepository := newPlainCloneTestRepository(t) @@ -1158,13 +1160,9 @@ func TestMigratePlainCloneCreatesBranchWorktreesUnderRoot(t *testing.T) { } testRepository.assertPathPresent(t, nestedMainPath) - testRepository.assertPathPresent(t, nestedBranchPath) + testRepository.assertPathMissing(t, nestedBranchPath) assertCurrentBranchAtPath(t, nestedMainPath, "main") - assertCurrentBranchAtPath(t, nestedBranchPath, branchName) assertMainWorktreePath(t, nestedMainPath) - if filepath.Dir(filepath.Dir(nestedBranchPath)) != testRepository.rootPath { - t.Fatalf("expected branch worktree under plain clone root %s, got %s", testRepository.rootPath, nestedBranchPath) - } } func TestMigrateMovesMainAndOldLayoutFeatureWorktrees(t *testing.T) { @@ -1194,7 +1192,7 @@ func TestMigrateMovesMainAndOldLayoutFeatureWorktrees(t *testing.T) { } } -func TestMigrateCreatesWorktreesForExistingBranches(t *testing.T) { +func TestMigrateDoesNotCreateWorktreesForExistingBranches(t *testing.T) { const branchOne = "feature/alpha" const branchTwo = "feature/beta" @@ -1207,10 +1205,8 @@ func TestMigrateCreatesWorktreesForExistingBranches(t *testing.T) { t.Fatalf("migrate failed: %v\n%s", result.err, result.stderr) } - testRepository.assertPathPresent(t, testRepository.worktreePath(branchOne)) - testRepository.assertPathPresent(t, testRepository.worktreePath(branchTwo)) - assertCurrentBranchAtPath(t, testRepository.worktreePath(branchOne), branchOne) - assertCurrentBranchAtPath(t, testRepository.worktreePath(branchTwo), branchTwo) + testRepository.assertPathMissing(t, testRepository.worktreePath(branchOne)) + testRepository.assertPathMissing(t, testRepository.worktreePath(branchTwo)) testRepository.assertPathPresent(t, testRepository.mainPath) assertCurrentBranchAtPath(t, testRepository.mainPath, "main") }