MCPcopy Index your code
hub / github.com/coder/coder / isRepoDeleted

Function isRepoDeleted

agent/agentgit/agentgit.go:307–326  ·  view source on GitHub ↗

isRepoDeleted returns true when the repo root directory or its .git entry no longer represents a valid git repository. This distinguishes a genuine repo deletion from a transient scan error (e.g. lock contention). It handles three deletion cases: 1. The repo root directory itself was removed. 2. Th

(gitBin string, repoRoot string)

Source from the content-addressed store, hash-verified

305// `git rev-parse --git-dir` fails because the referenced
306// directory is gone.
307func isRepoDeleted(gitBin string, repoRoot string) bool {
308 if _, err := os.Stat(repoRoot); os.IsNotExist(err) {
309 return true
310 }
311 gitPath := filepath.Join(repoRoot, ".git")
312 fi, err := os.Stat(gitPath)
313 if os.IsNotExist(err) {
314 return true
315 }
316 // If .git is a regular file (worktree or submodule), the actual
317 // git object store lives elsewhere. Validate that the target is
318 // still reachable by running git rev-parse.
319 if err == nil && !fi.IsDir() {
320 cmd := exec.CommandContext(context.Background(), gitBin, "-C", repoRoot, "rev-parse", "--git-dir")
321 if err := cmd.Run(); err != nil {
322 return true
323 }
324 }
325 return false
326}
327
328// findRepoRoot uses `git rev-parse --show-toplevel` to find the
329// repository root for the given path.

Callers 1

ScanMethod · 0.85

Calls 2

CommandContextMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected