From 5982192f3c3dcb50b837ca8881f2a8bfb3f11a8e Mon Sep 17 00:00:00 2001 From: caxco93 Date: Sat, 1 Aug 2026 22:07:40 +0200 Subject: [PATCH] Use repository names for worktree pool directories --- README.md | 14 +++++++------- cmd/worktree-manager/main.go | 2 +- internal/manager/manager.go | 5 +---- internal/manager/manager_test.go | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 528dbc7..9cb21b4 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ no CGO or system SQLite is required). ### `-v, --version` -Prints the worktree-manager version (`2.1.1`). +Prints the worktree-manager version (`2.2.0`). ### `-d, --database ` @@ -87,9 +87,9 @@ repository's `.gitignore`. ### `--base-dir ` Selects the directory where managed worktrees are created. It defaults to -`/private/tmp`. Each repository receives its own stable subdirectory beneath -that base directory, avoiding collisions between repositories with the same -name. Pass this option before the command: +`/private/tmp`. Each repository receives a subdirectory named after its local +repository directory beneath that base directory. Pass this option before the +command: ```sh worktree-manager --base-dir /path/to/worktrees acquire BenE/add-unit-menu @@ -239,8 +239,8 @@ Lists all managed worktrees across all repositories: ``` STATUS BRANCH REPO PATH -ALLOCATED BenE/add-unit-menu /path/to/repo /private/tmp/worktree-manager/repo-/pool-1-1 -FREE - /path/to/repo /private/tmp/worktree-manager/repo-/pool-1-2 +ALLOCATED BenE/add-unit-menu /path/to/repo /private/tmp/worktree-manager/repo-/pool-1-1 +FREE - /path/to/repo /private/tmp/worktree-manager/repo-/pool-1-2 ``` ### `verify` @@ -287,7 +287,7 @@ worktrees ( ``` All worktrees are created under -`/private/tmp/worktree-manager/repo-/pool--` by default. +`/private/tmp/worktree-manager/repo-/pool--` by default. Use `--base-dir` to place them below a different base directory. The checked-out branch is named exactly after the requested branch name, or after the generated name when omitted. Released worktrees are detached at the latest default-branch diff --git a/cmd/worktree-manager/main.go b/cmd/worktree-manager/main.go index 96d2df6..88e1a90 100644 --- a/cmd/worktree-manager/main.go +++ b/cmd/worktree-manager/main.go @@ -10,7 +10,7 @@ import ( "github.com/bejo-dev/worktree-manager/internal/manager" ) -const version = "2.1.1" +const version = "2.2.0" const usage = `worktree-manager - manage a reusable pool of git worktrees diff --git a/internal/manager/manager.go b/internal/manager/manager.go index 697fa5f..ca24478 100644 --- a/internal/manager/manager.go +++ b/internal/manager/manager.go @@ -2,8 +2,6 @@ package manager import ( - "crypto/sha256" - "encoding/hex" "errors" "fmt" "io" @@ -516,8 +514,7 @@ func (m *Manager) isManagerPoolPath(repoRoot, path string) bool { } func repositoryDirectoryName(repoRoot string) string { - hash := sha256.Sum256([]byte(filepath.Clean(repoRoot))) - return "repo-" + hex.EncodeToString(hash[:]) + return "repo-" + filepath.Base(filepath.Clean(repoRoot)) } func canonicalPath(path string) (string, error) { diff --git a/internal/manager/manager_test.go b/internal/manager/manager_test.go index 73ffe63..f0ef6fb 100644 --- a/internal/manager/manager_test.go +++ b/internal/manager/manager_test.go @@ -590,6 +590,22 @@ func TestDefaultWorktreeBaseDir(t *testing.T) { } } +func TestWorktreePathUsesRepositoryName(t *testing.T) { + d := newManagerDB(t) + baseDir := t.TempDir() + m := newTestManagerAt(t, d, baseDir) + canonicalBaseDir, err := canonicalPath(baseDir) + if err != nil { + t.Fatal(err) + } + + path := m.worktreePath(&db.Repository{RootPath: "/projects/worktree-manager"}, "pool-1-1") + want := filepath.Join(canonicalBaseDir, "worktree-manager", "repo-worktree-manager", "pool-1-1") + if path != want { + t.Fatalf("expected repository-named pool path %q, got %q", want, path) + } +} + func TestList(t *testing.T) { repo := setupRepo(t) d := newManagerDB(t)