diff --git a/app/lib/hooks/useGit.ts b/app/lib/hooks/useGit.ts index 387f794..b10bc2d 100644 --- a/app/lib/hooks/useGit.ts +++ b/app/lib/hooks/useGit.ts @@ -50,6 +50,13 @@ export function useGit() { fileData.current = {}; + let branch: string | undefined; + let baseUrl = url; + + if (url.includes('#')) { + [baseUrl, branch] = url.split('#'); + } + /* * Skip Git initialization for now - let isomorphic-git handle it * This avoids potential issues with our manual initialization @@ -78,23 +85,24 @@ export function useGit() { fs, http, dir: webcontainer.workdir, - url, + url: baseUrl, depth: 1, singleBranch: true, + ref: branch, corsProxy: '/api/git-proxy', headers, onProgress: (event) => { console.log('Git clone progress:', event); }, - onAuth: (url) => { - let auth = lookupSavedPassword(url); + onAuth: (baseUrl) => { + let auth = lookupSavedPassword(baseUrl); if (auth) { - console.log('Using saved authentication for', url); + console.log('Using saved authentication for', baseUrl); return auth; } - console.log('Repository requires authentication:', url); + console.log('Repository requires authentication:', baseUrl); if (confirm('This repository requires authentication. Would you like to enter your GitHub credentials?')) { auth = { @@ -106,16 +114,18 @@ export function useGit() { return { cancel: true }; } }, - onAuthFailure: (url, _auth) => { - console.error(`Authentication failed for ${url}`); - toast.error(`Authentication failed for ${url.split('/')[2]}. Please check your credentials and try again.`); + onAuthFailure: (baseUrl, _auth) => { + console.error(`Authentication failed for ${baseUrl}`); + toast.error( + `Authentication failed for ${baseUrl.split('/')[2]}. Please check your credentials and try again.`, + ); throw new Error( - `Authentication failed for ${url.split('/')[2]}. Please check your credentials and try again.`, + `Authentication failed for ${baseUrl.split('/')[2]}. Please check your credentials and try again.`, ); }, - onAuthSuccess: (url, auth) => { - console.log(`Authentication successful for ${url}`); - saveGitAuth(url, auth); + onAuthSuccess: (baseUrl, auth) => { + console.log(`Authentication successful for ${baseUrl}`); + saveGitAuth(baseUrl, auth); }, });