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

Function detachCmds

pkg/cmd/pr/checkout/checkout.go:322–340  ·  view source on GitHub ↗

detachCmds returns the commands for a detached checkout. When reusing an existing linked worktree, FETCH_HEAD must be written inside it (it is per-worktree), so the fetch runs with -C .

(fetchCmd []string, worktree string, reuseWorktree bool)

Source from the content-addressed store, hash-verified

320// existing linked worktree, FETCH_HEAD must be written inside it (it is
321// per-worktree), so the fetch runs with -C <path>.
322func detachCmds(fetchCmd []string, worktree string, reuseWorktree bool) [][]string {
323 if worktree == "" {
324 return [][]string{
325 fetchCmd,
326 {"checkout", "--detach", "FETCH_HEAD"},
327 }
328 }
329
330 if reuseWorktree {
331 return [][]string{
332 append([]string{"-C", worktree}, fetchCmd...),
333 {"-C", worktree, "checkout", "--detach", "FETCH_HEAD"},
334 }
335 }
336 return [][]string{
337 fetchCmd,
338 {"worktree", "add", "--detach", "--", worktree, "FETCH_HEAD"},
339 }
340}
341
342// syncBranchCmds syncs a branch to ref: a hard reset when force is set,
343// otherwise a fast-forward-only merge. A non-empty path runs the commands there.

Callers 2

cmdsForExistingRemoteFunction · 0.85
cmdsForMissingRemoteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected