Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path>`

Expand All @@ -87,9 +87,9 @@ repository's `.gitignore`.
### `--base-dir <path>`

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
Expand Down Expand Up @@ -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-<hash>/pool-1-1
FREE - /path/to/repo /private/tmp/worktree-manager/repo-<hash>/pool-1-2
ALLOCATED BenE/add-unit-menu /path/to/repo /private/tmp/worktree-manager/repo-<repo-name>/pool-1-1
FREE - /path/to/repo /private/tmp/worktree-manager/repo-<repo-name>/pool-1-2
```

### `verify`
Expand Down Expand Up @@ -287,7 +287,7 @@ worktrees (
```

All worktrees are created under
`/private/tmp/worktree-manager/repo-<hash>/pool-<repo>-<slot>` by default.
`/private/tmp/worktree-manager/repo-<repo-name>/pool-<repo>-<slot>` 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
Expand Down
2 changes: 1 addition & 1 deletion cmd/worktree-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
package manager

import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions internal/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading