MCPcopy Index your code
hub / github.com/Noumena-Network/code / preserveGitStateForIssue

Function preserveGitStateForIssue

src/utils/git.ts:739–860  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

737 * - Shallow clone: falls back to HEAD-only mode
738 */
739export async function preserveGitStateForIssue(): Promise<PreservedGitState | null> {
740 try {
741 const isGit = await getIsGit()
742 if (!isGit) {
743 return null
744 }
745
746 // Check for shallow clone - fall back to simpler mode
747 if (await isShallowClone()) {
748 logForDebugging('Shallow clone detected, using HEAD-only mode for issue')
749 const [{ stdout: patch }, untrackedFiles] = await Promise.all([
750 execFileNoThrow(gitExe(), ['diff', 'HEAD']),
751 captureUntrackedFiles(),
752 ])
753 return {
754 remote_base_sha: null,
755 remote_base: null,
756 patch: patch || '',
757 untracked_files: untrackedFiles,
758 format_patch: null,
759 head_sha: null,
760 branch_name: null,
761 }
762 }
763
764 // Find the best remote base
765 const remoteBase = await findRemoteBase()
766
767 if (!remoteBase) {
768 // No remote found - use HEAD-only mode
769 logForDebugging('No remote found, using HEAD-only mode for issue')
770 const [{ stdout: patch }, untrackedFiles] = await Promise.all([
771 execFileNoThrow(gitExe(), ['diff', 'HEAD']),
772 captureUntrackedFiles(),
773 ])
774 return {
775 remote_base_sha: null,
776 remote_base: null,
777 patch: patch || '',
778 untracked_files: untrackedFiles,
779 format_patch: null,
780 head_sha: null,
781 branch_name: null,
782 }
783 }
784
785 // Get the merge-base with remote
786 const { stdout: mergeBase, code: mergeBaseCode } = await execFileNoThrow(
787 gitExe(),
788 ['merge-base', 'HEAD', remoteBase],
789 { preserveOutputOnError: false },
790 )
791
792 if (mergeBaseCode !== 0 || !mergeBase.trim()) {
793 // Merge-base failed - fall back to HEAD-only
794 logForDebugging('Merge-base failed, using HEAD-only mode for issue')
795 const [{ stdout: patch }, untrackedFiles] = await Promise.all([
796 execFileNoThrow(gitExe(), ['diff', 'HEAD']),

Callers

nothing calls this directly

Calls 6

captureUntrackedFilesFunction · 0.85
findRemoteBaseFunction · 0.85
isShallowCloneFunction · 0.70
logForDebuggingFunction · 0.70
execFileNoThrowFunction · 0.70
logErrorFunction · 0.70

Tested by

no test coverage detected