fix: support cloning non-default branches by parsing branch from URL (#1956)

This commit is contained in:
Chris Ijoyah
2025-09-05 03:55:26 +02:00
committed by GitHub
parent 1117d4ed34
commit 8a685603be

View File

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