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

Function gitClone

source code/utils/plugins/pluginLoader.ts:536–642  ·  view source on GitHub ↗
(
  gitUrl: string,
  targetPath: string,
  ref?: string,
  sha?: string,
)

Source from the content-addressed store, hash-verified

534 * @param sha - Optional specific commit SHA to checkout
535 */
536export async function gitClone(
537 gitUrl: string,
538 targetPath: string,
539 ref?: string,
540 sha?: string,
541): Promise<void> {
542 // Use --recurse-submodules to initialize submodules
543 // Always start with shallow clone for efficiency
544 const args = [
545 'clone',
546 '--depth',
547 '1',
548 '--recurse-submodules',
549 '--shallow-submodules',
550 ]
551
552 // Add --branch flag for specific ref (works for both branches and tags)
553 if (ref) {
554 args.push('--branch', ref)
555 }
556
557 // If sha is specified, use --no-checkout since we'll checkout the SHA separately
558 if (sha) {
559 args.push('--no-checkout')
560 }
561
562 args.push(gitUrl, targetPath)
563
564 const cloneStarted = performance.now()
565 const cloneResult = await execFileNoThrow(gitExe(), args)
566
567 if (cloneResult.code !== 0) {
568 logPluginFetch(
569 'plugin_clone',
570 gitUrl,
571 'failure',
572 performance.now() - cloneStarted,
573 classifyFetchError(cloneResult.stderr),
574 )
575 throw new Error(`Failed to clone repository: ${cloneResult.stderr}`)
576 }
577
578 // If sha is specified, fetch and checkout that specific commit
579 if (sha) {
580 // Try shallow fetch of the specific SHA first (most efficient)
581 const shallowFetchResult = await execFileNoThrowWithCwd(
582 gitExe(),
583 ['fetch', '--depth', '1', 'origin', sha],
584 { cwd: targetPath },
585 )
586
587 if (shallowFetchResult.code !== 0) {
588 // Some servers don't support fetching arbitrary SHAs
589 // Fall back to unshallow fetch to get full history
590 logForDebugging(
591 `Shallow fetch of SHA ${sha} failed, falling back to unshallow fetch`,
592 )
593 const unshallowResult = await execFileNoThrowWithCwd(

Callers 1

installFromGitFunction · 0.70

Calls 5

execFileNoThrowFunction · 0.85
logPluginFetchFunction · 0.85
classifyFetchErrorFunction · 0.85
execFileNoThrowWithCwdFunction · 0.85
logForDebuggingFunction · 0.85

Tested by

no test coverage detected