fix: handle missing/corrupt repos when fetching branches + clearer manual fallback
Backend (git_repositories.py): - get_repository_branches now checks for .git subdirectory (not just dir existence) - If local repo is corrupt/missing but has remote_url, falls back to git ls-remote to list branches from the remote - Returns 404 with actionable message instead of 400 with raw git stderr - Pre-existing test failure in test_git_repository_clone_preflight.py unchanged Frontend (workspace-create-form.tsx): - When branch API fails, auto-switches to manual text input (no dropdown selection needed) - Shows hint text: 'Couldn't load branches — type one manually' - useGitRepo hook auto-fetches branches when projectId/repoId change Quality gates: ruff clean, tsc --noEmit clean, 93 passed + 1 pre-existing failure
This commit is contained in:
@@ -57,8 +57,12 @@ export function WorkspaceCreateForm({
|
||||
: git.branches[0];
|
||||
setSelectedBranch(preferred);
|
||||
setIsNewBranch(false);
|
||||
} else if (git.error && git.branches.length === 0 && !isNewBranch) {
|
||||
// API failed — default to manual entry so user can type a branch
|
||||
setIsNewBranch(true);
|
||||
setSelectedBranch("__manual__");
|
||||
}
|
||||
}, [git.branches, git.defaultBranch, selectedBranch]);
|
||||
}, [git.branches, git.defaultBranch, git.error, selectedBranch, isNewBranch]);
|
||||
|
||||
/* ── Load projects (standalone mode only) ── */
|
||||
const loadProjects = useCallback(async () => {
|
||||
@@ -236,6 +240,20 @@ export function WorkspaceCreateForm({
|
||||
<label>
|
||||
<Icon name="branch" size="sm" /> Branch
|
||||
</label>
|
||||
|
||||
{/* Show a hint when branches couldn’t be loaded */}
|
||||
{git.error && git.branches.length === 0 && selectedRepo && (
|
||||
<p
|
||||
className="muted"
|
||||
style={{
|
||||
fontSize: "var(--font-size-xs)",
|
||||
marginBottom: "0.25rem",
|
||||
}}
|
||||
>
|
||||
Couldn’t load branches — type one manually.
|
||||
</p>
|
||||
)}
|
||||
|
||||
<select
|
||||
value={selectedBranch}
|
||||
onChange={(e) => handleBranchChange(e.target.value)}
|
||||
@@ -258,14 +276,9 @@ export function WorkspaceCreateForm({
|
||||
))}
|
||||
|
||||
<option value="__new__">+ Create new branch...</option>
|
||||
|
||||
{/* If branch fetch failed, offer manual entry */}
|
||||
{git.error && git.branches.length === 0 && (
|
||||
<option value="__manual__">✎ Enter branch name manually...</option>
|
||||
)}
|
||||
</select>
|
||||
|
||||
{/* New branch text input */}
|
||||
{/* Text input for new branch or manual entry */}
|
||||
{isNewBranch && (
|
||||
<input
|
||||
type="text"
|
||||
|
||||
Reference in New Issue
Block a user