-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjump.go
More file actions
33 lines (29 loc) · 736 Bytes
/
jump.go
File metadata and controls
33 lines (29 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"fmt"
"os"
)
// jump outputs a worktree path for the shell wrapper to cd into.
// If name is empty, it navigates to the repository root (when inside a worktree).
// If name is provided, it navigates to that specific worktree.
func jump(name string) error {
wm, err := NewWorktreeManager()
if err != nil {
return err
}
// No name = go to root
if name == "" {
currentName, _ := wm.CurrentWorktreeName()
if currentName != "" {
fmt.Println(wm.Root())
}
return nil
}
// Jump to specific worktree
worktreePath := wm.WorktreePath(name)
if _, err := os.Stat(worktreePath); os.IsNotExist(err) {
return fmt.Errorf("worktree %q does not exist", name)
}
fmt.Println(worktreePath)
return nil
}