MCPcopy Create free account
hub / github.com/github/gh-aw / FindGitRoot

Function FindGitRoot

pkg/gitutil/gitutil.go:85–102  ·  view source on GitHub ↗

FindGitRoot finds the root directory of the git repository. Uses pure Go filesystem traversal to avoid requiring the git executable, which can fail when the binary runs under Rosetta 2 on macOS ARM64 or in environments where git is not on PATH. Returns an error if not in a git repository.

()

Source from the content-addressed store, hash-verified

83// environments where git is not on PATH.
84// Returns an error if not in a git repository.
85func FindGitRoot() (string, error) {
86 gitutilLog.Print("Finding git root directory")
87
88 dir, err := os.Getwd()
89 if err != nil {
90 gitutilLog.Printf("Failed to get current directory: %v", err)
91 return "", fmt.Errorf("failed to get current directory: %w", err)
92 }
93
94 root, err := FindGitRootFrom(dir)
95 if err != nil {
96 gitutilLog.Printf("Failed to find git root: %v", err)
97 return "", err
98 }
99
100 gitutilLog.Printf("Found git root: %s", root)
101 return root, nil
102}
103
104// FindGitRootFrom finds the root directory of the git repository starting from
105// the given directory. It traverses upward until it finds a .git entry (file or

Callers 15

findGoModFunction · 0.92
resolveWorkflowTargetDirFunction · 0.92
watchAndCompileWorkflowsFunction · 0.92
runPostProcessingFunction · 0.92
runUpdateForTargetRepoFunction · 0.92
isGitRepoFunction · 0.92
stageWorkflowChangesFunction · 0.92
ensureGitAttributesFunction · 0.92
ensureLogsGitignoreFunction · 0.92

Calls 4

FindGitRootFromFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45