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

Function getGitRepositoryInfoAsync

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

Source from the content-addressed store, hash-verified

176}
177
178async function getGitRepositoryInfoAsync(cwd: string): Promise<GitRepositoryInfo | null> {
179 const topLevel = await runGitAsync(cwd, ["rev-parse", "--show-toplevel"]);
180 if (!topLevel.ok) return null;
181 const rawRepoRoot = topLevel.stdout.trim();
182 if (!rawRepoRoot) return null;
183 let gitCwd: string;
184 try {
185 gitCwd = await realpath(resolve(cwd));
186 } catch {
187 return null;
188 }
189 let repoRoot: string;
190 try {
191 repoRoot = await realpath(rawRepoRoot);
192 } catch {
193 return null;
194 }
195
196 const [gitDir, gitCommonDir] = await Promise.all([
197 runGitAsync(cwd, ["rev-parse", "--git-dir"]),
198 runGitAsync(cwd, ["rev-parse", "--git-common-dir"]),
199 ]);
200
201 return {
202 repoRoot,
203 gitDir: gitDir.ok && gitDir.stdout.trim() ? resolveGitPath(gitCwd, gitDir.stdout.trim()) : resolve(repoRoot, ".git"),
204 gitCommonDir: gitCommonDir.ok && gitCommonDir.stdout.trim()
205 ? resolveGitPath(gitCwd, gitCommonDir.stdout.trim())
206 : gitDir.ok && gitDir.stdout.trim()
207 ? resolveGitPath(gitCwd, gitDir.stdout.trim())
208 : resolve(repoRoot, ".git"),
209 };
210}
211
212function isWithinPath(candidate: string, root: string): boolean {
213 const rel = relative(root, candidate);

Callers 1

Calls 3

runGitAsyncFunction · 0.85
resolveGitPathFunction · 0.85
resolveFunction · 0.70

Tested by

no test coverage detected