* Check if directory is within a git repository and return repo info
(params: IsGitDirectoryParams)
| 555 | * Check if directory is within a git repository and return repo info |
| 556 | */ |
| 557 | async function handleIsGitDirectory(params: IsGitDirectoryParams): Promise<IsGitDirectoryResponse> { |
| 558 | const startTime = Date.now() |
| 559 | logger.info("[Git:isGitDirectory] Checking directory", JSON.stringify({ directory: params.directory })) |
| 560 | |
| 561 | try { |
| 562 | // Resolve git info (repo root and relative path) |
| 563 | const { repoRoot, relativePath } = await resolveGitInfo(params.directory) |
| 564 | |
| 565 | // Detect main branch using the repo root |
| 566 | let mainBranch = "main" |
| 567 | |
| 568 | // Try to get from remote HEAD |
| 569 | const remoteHeadResult = await execGit(["symbolic-ref", "refs/remotes/origin/HEAD"], repoRoot) |
| 570 | if (remoteHeadResult.success) { |
| 571 | const refName = remoteHeadResult.stdout.trim() |
| 572 | mainBranch = refName.replace("refs/remotes/origin/", "") |
| 573 | } else { |
| 574 | // Check if main exists |
| 575 | const mainExistsResult = await execGit(["show-ref", "--verify", "refs/heads/main"], repoRoot) |
| 576 | if (mainExistsResult.success) { |
| 577 | mainBranch = "main" |
| 578 | } else { |
| 579 | // Check if master exists |
| 580 | const masterExistsResult = await execGit(["show-ref", "--verify", "refs/heads/master"], repoRoot) |
| 581 | if (masterExistsResult.success) { |
| 582 | mainBranch = "master" |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | // Detect gh CLI availability (authenticated GitHub CLI) |
| 588 | let hasGhCli = false |
| 589 | try { |
| 590 | const ghResult = await execCommand("gh", ["auth", "status"], { timeout: 5000 }) |
| 591 | hasGhCli = ghResult.success |
| 592 | } catch { |
| 593 | // gh not installed or not in PATH |
| 594 | } |
| 595 | |
| 596 | logger.info("[Git:isGitDirectory] Git directory found", JSON.stringify({ |
| 597 | directory: params.directory, |
| 598 | repoRoot, |
| 599 | relativePath: relativePath || "(root)", |
| 600 | mainBranch, |
| 601 | hasGhCli, |
| 602 | duration: Date.now() - startTime, |
| 603 | })) |
| 604 | |
| 605 | return { |
| 606 | isGitDirectory: true, |
| 607 | repoRoot, |
| 608 | relativePath, |
| 609 | mainBranch, |
| 610 | hasGhCli, |
| 611 | } |
| 612 | } catch (error: any) { |
| 613 | logger.info("[Git:isGitDirectory] Not a git directory", JSON.stringify({ |
| 614 | directory: params.directory, |
no test coverage detected