()
| 722 | * - Shallow clone: falls back to HEAD-only mode |
| 723 | */ |
| 724 | export async function preserveGitStateForIssue(): Promise<PreservedGitState | null> { |
| 725 | try { |
| 726 | const isGit = await getIsGit() |
| 727 | if (!isGit) { |
| 728 | return null |
| 729 | } |
| 730 | |
| 731 | // Check for shallow clone - fall back to simpler mode |
| 732 | if (await isShallowClone()) { |
| 733 | logForDebugging('Shallow clone detected, using HEAD-only mode for issue') |
| 734 | const [{ stdout: patch }, untrackedFiles] = await Promise.all([ |
| 735 | execFileNoThrow(gitExe(), ['diff', 'HEAD']), |
| 736 | captureUntrackedFiles(), |
| 737 | ]) |
| 738 | return { |
| 739 | remote_base_sha: null, |
| 740 | remote_base: null, |
| 741 | patch: patch || '', |
| 742 | untracked_files: untrackedFiles, |
| 743 | format_patch: null, |
| 744 | head_sha: null, |
| 745 | branch_name: null, |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | // Find the best remote base |
| 750 | const remoteBase = await findRemoteBase() |
| 751 | |
| 752 | if (!remoteBase) { |
| 753 | // No remote found - use HEAD-only mode |
| 754 | logForDebugging('No remote found, using HEAD-only mode for issue') |
| 755 | const [{ stdout: patch }, untrackedFiles] = await Promise.all([ |
| 756 | execFileNoThrow(gitExe(), ['diff', 'HEAD']), |
| 757 | captureUntrackedFiles(), |
| 758 | ]) |
| 759 | return { |
| 760 | remote_base_sha: null, |
| 761 | remote_base: null, |
| 762 | patch: patch || '', |
| 763 | untracked_files: untrackedFiles, |
| 764 | format_patch: null, |
| 765 | head_sha: null, |
| 766 | branch_name: null, |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | // Get the merge-base with remote |
| 771 | const { stdout: mergeBase, code: mergeBaseCode } = await execFileNoThrow( |
| 772 | gitExe(), |
| 773 | ['merge-base', 'HEAD', remoteBase], |
| 774 | { preserveOutputOnError: false }, |
| 775 | ) |
| 776 | |
| 777 | if (mergeBaseCode !== 0 || !mergeBase.trim()) { |
| 778 | // Merge-base failed - fall back to HEAD-only |
| 779 | logForDebugging('Merge-base failed, using HEAD-only mode for issue') |
| 780 | const [{ stdout: patch }, untrackedFiles] = await Promise.all([ |
| 781 | execFileNoThrow(gitExe(), ['diff', 'HEAD']), |
nothing calls this directly
no test coverage detected