MCPcopy Create free account
hub / github.com/cli/cli / WorktreeCheckoutCommands

Function WorktreeCheckoutCommands

pkg/cmd/pr/shared/worktree.go:45–59  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

43// WorktreeCheckoutCommands returns the commands needed to place branch in
44// target. startPoint must be a remote branch suitable for --track.
45func 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.

Callers 2

cmdsForExistingRemoteFunction · 0.92

Calls 1

HasLocalBranchMethod · 0.65

Tested by 1