ResolveWorktreeTarget validates path and determines whether it is the root of an existing linked worktree for the current repository.
(client *git.Client, path string)
| 22 | // ResolveWorktreeTarget validates path and determines whether it is the root |
| 23 | // of an existing linked worktree for the current repository. |
| 24 | func ResolveWorktreeTarget(client *git.Client, path string) (WorktreeTarget, error) { |
| 25 | target := WorktreeTarget{Path: path} |
| 26 | if err := ensureWorktreePathSafe(path); err != nil { |
| 27 | return target, err |
| 28 | } |
| 29 | |
| 30 | reuse, err := resolveWorktreeTarget(client, path) |
| 31 | if err != nil { |
| 32 | return target, err |
| 33 | } |
| 34 | if !reuse { |
| 35 | if err := ensureWorktreePathEmpty(path); err != nil { |
| 36 | return target, err |
| 37 | } |
| 38 | } |
| 39 | target.Reuse = reuse |
| 40 | return target, nil |
| 41 | } |
| 42 | |
| 43 | // WorktreeCheckoutCommands returns the commands needed to place branch in |
| 44 | // target. startPoint must be a remote branch suitable for --track. |