(cwd: string)
| 149 | } |
| 150 | |
| 151 | export 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 | |
| 178 | async function getGitRepositoryInfoAsync(cwd: string): Promise<GitRepositoryInfo | null> { |
| 179 | const topLevel = await runGitAsync(cwd, ["rev-parse", "--show-toplevel"]); |
no test coverage detected