Skip to content

Commit c823609

Browse files
authored
Merge pull request #44 from utilitywarehouse/as-wt-name
avoid conflicts when links has same basename
2 parents 9379079 + 186f159 commit c823609

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: pkg/mirror/worktree.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package mirror
22

33
import (
44
"context"
5+
"crypto/sha256"
56
"fmt"
67
"log/slog"
78
"path/filepath"
89
"slices"
9-
"strings"
1010
)
1111

1212
type WorkTreeLink struct {
@@ -32,9 +32,11 @@ func (wt *WorkTreeLink) Equals(wtc WorktreeConfig) bool {
3232
// worktreeDirName will generate worktree name for specific worktree link
3333
// two worktree links can be on same ref but with diff pathspecs
3434
// hence we cant just use tree hash as path
35+
// 2 diff worktree links can have same basename hence also including hash of absolute link path
3536
func (w *WorkTreeLink) worktreeDirName(hash string) string {
36-
parts := strings.Split(strings.Trim(w.linkAbs, "/"), "/")
37-
return parts[len(parts)-1] + "-" + hash[:7]
37+
linkHash := fmt.Sprintf("%x", sha256.Sum256([]byte(w.linkAbs)))
38+
base := filepath.Base(w.linkAbs)
39+
return base + "_" + linkHash[:7] + "-" + hash[:7]
3840
}
3941

4042
// currentWorktree reads symlink path of the given worktree link

0 commit comments

Comments
 (0)