MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / IsWorktree

Function IsWorktree

internal/git/worktree.go:150–181  ·  view source on GitHub ↗

IsWorktree checks if a path is a valid git worktree.

(path string)

Source from the content-addressed store, hash-verified

148
149// IsWorktree checks if a path is a valid git worktree.
150func IsWorktree(path string) bool {
151 cmd := exec.Command("git", "rev-parse", "--is-inside-work-tree")
152 cmd.Dir = path
153 output, err := cmd.Output()
154 if err != nil {
155 return false
156 }
157 if strings.TrimSpace(string(output)) != "true" {
158 return false
159 }
160
161 // Verify it's actually a worktree (not the main repo) by checking for .git file
162 cmd = exec.Command("git", "rev-parse", "--git-common-dir")
163 cmd.Dir = path
164 commonDir, err := cmd.Output()
165 if err != nil {
166 return false
167 }
168
169 cmd = exec.Command("git", "rev-parse", "--git-dir")
170 cmd.Dir = path
171 gitDir, err := cmd.Output()
172 if err != nil {
173 return false
174 }
175
176 // In a worktree, --git-dir differs from --git-common-dir
177 // But we also consider the main worktree valid
178 _ = commonDir
179 _ = gitDir
180 return true
181}
182
183// WorktreePathForPRD returns the worktree path for a given PRD name.
184func WorktreePathForPRD(baseDir, prdName string) string {

Callers 3

cleanupWorktreeSetupMethod · 0.92
CreateWorktreeFunction · 0.85
TestIsWorktreeFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestIsWorktreeFunction · 0.68