MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / installFromGitSubdir

Function installFromGitSubdir

src/utils/plugins/pluginLoader.ts:719–852  ·  view source on GitHub ↗
(
  url: string,
  targetPath: string,
  subdirPath: string,
  ref?: string,
  sha?: string,
)

Source from the content-addressed store, hash-verified

717 * the plugin files with no .git directory.
718 */
719export async function installFromGitSubdir(
720 url: string,
721 targetPath: string,
722 subdirPath: string,
723 ref?: string,
724 sha?: string,
725): Promise<string | undefined> {
726 if (!(await checkGitAvailable())) {
727 throw new Error(
728 'git-subdir plugin source requires git to be installed and on PATH. ' +
729 'Install git (version 2.25 or later for sparse-checkout cone mode) and try again.',
730 )
731 }
732
733 const gitUrl = resolveGitSubdirUrl(url)
734 // Clone into a sibling temp dir (same filesystem → rename works, no EXDEV).
735 const cloneDir = `${targetPath}.clone`
736
737 const cloneArgs = [
738 'clone',
739 '--depth',
740 '1',
741 '--filter=tree:0',
742 '--no-checkout',
743 ]
744 if (ref) {
745 cloneArgs.push('--branch', ref)
746 }
747 cloneArgs.push(gitUrl, cloneDir)
748
749 const cloneResult = await execFileNoThrow(gitExe(), cloneArgs)
750 if (cloneResult.code !== 0) {
751 throw new Error(
752 `Failed to clone repository for git-subdir source: ${cloneResult.stderr}`,
753 )
754 }
755
756 try {
757 const sparseResult = await execFileNoThrowWithCwd(
758 gitExe(),
759 ['sparse-checkout', 'set', '--cone', '--', subdirPath],
760 { cwd: cloneDir },
761 )
762 if (sparseResult.code !== 0) {
763 throw new Error(
764 `git sparse-checkout set failed (git >= 2.25 required for cone mode): ${sparseResult.stderr}`,
765 )
766 }
767
768 // Capture the resolved commit SHA before discarding the clone. The
769 // extracted subdir has no .git, so the caller can't rev-parse it later.
770 // If the source specified a full 40-char sha we already know it; otherwise
771 // read HEAD (which points to ref's tip after --branch, or the remote
772 // default branch if no ref was given).
773 let resolvedSha: string | undefined
774
775 if (sha) {
776 const fetchSha = await execFileNoThrowWithCwd(

Callers 1

cachePluginFunction · 0.85

Calls 9

resolveGitSubdirUrlFunction · 0.85
execFileNoThrowWithCwdFunction · 0.85
validatePathWithinBaseFunction · 0.85
renameFunction · 0.85
isENOENTFunction · 0.85
rmFunction · 0.85
execFileNoThrowFunction · 0.50
logForDebuggingFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected