Skip to content

Commit 8a68560

Browse files
authored
fix: support cloning non-default branches by parsing branch from URL (#1956)
1 parent 1117d4e commit 8a68560

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

app/lib/hooks/useGit.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export function useGit() {
5050

5151
fileData.current = {};
5252

53+
let branch: string | undefined;
54+
let baseUrl = url;
55+
56+
if (url.includes('#')) {
57+
[baseUrl, branch] = url.split('#');
58+
}
59+
5360
/*
5461
* Skip Git initialization for now - let isomorphic-git handle it
5562
* This avoids potential issues with our manual initialization
@@ -78,23 +85,24 @@ export function useGit() {
7885
fs,
7986
http,
8087
dir: webcontainer.workdir,
81-
url,
88+
url: baseUrl,
8289
depth: 1,
8390
singleBranch: true,
91+
ref: branch,
8492
corsProxy: '/api/git-proxy',
8593
headers,
8694
onProgress: (event) => {
8795
console.log('Git clone progress:', event);
8896
},
89-
onAuth: (url) => {
90-
let auth = lookupSavedPassword(url);
97+
onAuth: (baseUrl) => {
98+
let auth = lookupSavedPassword(baseUrl);
9199

92100
if (auth) {
93-
console.log('Using saved authentication for', url);
101+
console.log('Using saved authentication for', baseUrl);
94102
return auth;
95103
}
96104

97-
console.log('Repository requires authentication:', url);
105+
console.log('Repository requires authentication:', baseUrl);
98106

99107
if (confirm('This repository requires authentication. Would you like to enter your GitHub credentials?')) {
100108
auth = {
@@ -106,16 +114,18 @@ export function useGit() {
106114
return { cancel: true };
107115
}
108116
},
109-
onAuthFailure: (url, _auth) => {
110-
console.error(`Authentication failed for ${url}`);
111-
toast.error(`Authentication failed for ${url.split('/')[2]}. Please check your credentials and try again.`);
117+
onAuthFailure: (baseUrl, _auth) => {
118+
console.error(`Authentication failed for ${baseUrl}`);
119+
toast.error(
120+
`Authentication failed for ${baseUrl.split('/')[2]}. Please check your credentials and try again.`,
121+
);
112122
throw new Error(
113-
`Authentication failed for ${url.split('/')[2]}. Please check your credentials and try again.`,
123+
`Authentication failed for ${baseUrl.split('/')[2]}. Please check your credentials and try again.`,
114124
);
115125
},
116-
onAuthSuccess: (url, auth) => {
117-
console.log(`Authentication successful for ${url}`);
118-
saveGitAuth(url, auth);
126+
onAuthSuccess: (baseUrl, auth) => {
127+
console.log(`Authentication successful for ${baseUrl}`);
128+
saveGitAuth(baseUrl, auth);
119129
},
120130
});
121131

0 commit comments

Comments
 (0)