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

Function detachCmds

pkg/cmd/pr/checkout/checkout.go:394–412  ·  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

392// existing linked worktree, FETCH_HEAD must be written inside it (it is
393// per-worktree), so the fetch runs with -C <path>.
394func detachCmds(fetchCmd []string, worktree string, reuseWorktree bool) [][]string {
395 if worktree == "" {
396 return [][]string{
397 fetchCmd,
398 {"checkout", "--detach", "FETCH_HEAD"},
399 }
400 }
401
402 if reuseWorktree {
403 return [][]string{
404 append([]string{"-C", worktree}, fetchCmd...),
405 {"-C", worktree, "checkout", "--detach", "FETCH_HEAD"},
406 }
407 }
408 return [][]string{
409 fetchCmd,
410 {"worktree", "add", "--detach", "--", worktree, "FETCH_HEAD"},
411 }
412}
413
414// syncBranchCmds syncs a branch to ref: a hard reset when force is set,
415// 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