fix: support cloning non-default branches by parsing branch from URL (#1956)
This commit is contained in:
@@ -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);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user