MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / cloneRepository

Function cloneRepository

packages/backend/src/git.ts:76–120  ·  view source on GitHub ↗
(
    {
        cloneUrl,
        authHeader,
        path,
        onProgress,
        signal,
    }: {
        cloneUrl: string,
        authHeader?: string,
        path: string,
        onProgress?: onProgressFn
        signal?: AbortSignal
    }
)

Source from the content-addressed store, hash-verified

74}
75
76export const cloneRepository = async (
77 {
78 cloneUrl,
79 authHeader,
80 path,
81 onProgress,
82 signal,
83 }: {
84 cloneUrl: string,
85 authHeader?: string,
86 path: string,
87 onProgress?: onProgressFn
88 signal?: AbortSignal
89 }
90) => {
91 try {
92 await mkdir(path, { recursive: true });
93
94 const git = createGitClientForPath(path, onProgress, signal);
95
96 const cloneArgs = [
97 "--bare",
98 ...(authHeader ? ["-c", `http.extraHeader=${authHeader}`] : [])
99 ];
100
101 await git.clone(cloneUrl, path, cloneArgs);
102
103 await unsetGitConfig({
104 path,
105 keys: ["remote.origin.url"],
106 signal,
107 });
108 } catch (error: unknown) {
109 const baseLog = `Failed to clone repository: ${path}`;
110
111 if (env.SOURCEBOT_LOG_LEVEL !== "debug") {
112 // Avoid printing the remote URL (that may contain credentials) to logs by default.
113 throw new Error(`${baseLog}. Set environment variable SOURCEBOT_LOG_LEVEL=debug to see the full error message.`);
114 } else if (error instanceof Error) {
115 throw new Error(`${baseLog}. Reason: ${error.message}`);
116 } else {
117 throw new Error(`${baseLog}. Error: ${error}`);
118 }
119 }
120};
121
122export const fetchRepository = async (
123 {

Callers 1

indexRepositoryMethod · 0.85

Calls 2

createGitClientForPathFunction · 0.85
unsetGitConfigFunction · 0.85

Tested by

no test coverage detected