MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / preserveGitStateForIssue

Function preserveGitStateForIssue

source code/utils/git.ts:726–847  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected