WorktreeCheckoutCommands returns the commands needed to place branch in target. startPoint must be a remote branch suitable for --track.
(client *git.Client, target WorktreeTarget, branch, startPoint string)
| 43 | // WorktreeCheckoutCommands returns the commands needed to place branch in |
| 44 | // target. startPoint must be a remote branch suitable for --track. |
| 45 | func WorktreeCheckoutCommands(client *git.Client, target WorktreeTarget, branch, startPoint string) ([][]string, bool) { |
| 46 | branchExists := client.HasLocalBranch(context.Background(), branch) |
| 47 | |
| 48 | if target.Reuse { |
| 49 | if branchExists { |
| 50 | return [][]string{{"-C", target.Path, "checkout", branch}}, true |
| 51 | } |
| 52 | return [][]string{{"-C", target.Path, "checkout", "-b", branch, "--track", startPoint}}, false |
| 53 | } |
| 54 | |
| 55 | if branchExists { |
| 56 | return [][]string{{"worktree", "add", "--", target.Path, branch}}, true |
| 57 | } |
| 58 | return [][]string{{"worktree", "add", "--track", "-b", branch, "--", target.Path, startPoint}}, false |
| 59 | } |
| 60 | |
| 61 | // resolveWorktreeTarget asks git where path lives, letting git resolve symlinks, |
| 62 | // "..", case, and trailing slashes for us instead of comparing paths ourselves. |