MCPcopy Create free account
hub / github.com/backnotprop/plannotator / getGitRepositoryInfo

Function getGitRepositoryInfo

packages/shared/workspace-status.ts:151–176  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

149}
150
151export function getGitRepositoryInfo(cwd: string): GitRepositoryInfo | null {
152 const topLevel = runGit(cwd, ["rev-parse", "--show-toplevel"]);
153 if (!topLevel.ok) return null;
154 const rawRepoRoot = topLevel.stdout.trim();
155 if (!rawRepoRoot) return null;
156 let gitCwd: string;
157 try {
158 gitCwd = realpathSync(resolve(cwd));
159 } catch {
160 return null;
161 }
162 const repoRoot = realpathSync(rawRepoRoot);
163
164 const gitDir = runGit(cwd, ["rev-parse", "--git-dir"]);
165 const gitCommonDir = runGit(cwd, ["rev-parse", "--git-common-dir"]);
166
167 return {
168 repoRoot,
169 gitDir: gitDir.ok && gitDir.stdout.trim() ? resolveGitPath(gitCwd, gitDir.stdout.trim()) : resolve(repoRoot, ".git"),
170 gitCommonDir: gitCommonDir.ok && gitCommonDir.stdout.trim()
171 ? resolveGitPath(gitCwd, gitCommonDir.stdout.trim())
172 : gitDir.ok && gitDir.stdout.trim()
173 ? resolveGitPath(gitCwd, gitDir.stdout.trim())
174 : resolve(repoRoot, ".git"),
175 };
176}
177
178async function getGitRepositoryInfoAsync(cwd: string): Promise<GitRepositoryInfo | null> {
179 const topLevel = await runGitAsync(cwd, ["rev-parse", "--show-toplevel"]);

Callers 1

getGitMetadataWatchPathsFunction · 0.85

Calls 3

resolveGitPathFunction · 0.85
runGitFunction · 0.70
resolveFunction · 0.70

Tested by

no test coverage detected