diff --git a/apps/web/src/pages/sessions.tsx b/apps/web/src/pages/sessions.tsx index bf74bad..f2df26c 100644 --- a/apps/web/src/pages/sessions.tsx +++ b/apps/web/src/pages/sessions.tsx @@ -3,7 +3,7 @@ import { useNavigate } from "react-router-dom"; import { listProjects } from "../api/projects"; import type { Project } from "../types"; -import { listRepositories, type GitRepository } from "../api/git_repositories"; +import { listRepositories, listRepositoryBranches, type GitRepository, type Branch } from "../api/git_repositories"; import { getUserSessions, type Session, @@ -43,6 +43,12 @@ export const SessionsPage = () => { const [branch, setBranch] = useState("main"); const [sshKeys, setSshKeys] = useState([]); + const [branches, setBranches] = useState([]); + const [isLoadingBranches, setIsLoadingBranches] = useState(false); + const [isCreatingNewBranch, setIsCreatingNewBranch] = useState(false); + const [newBranchName, setNewBranchName] = useState(""); + const [baseBranch, setBaseBranch] = useState(""); + const [dirtyDeleteSession, setDirtyDeleteSession] = useState(null); const [dirtyDeleteFiles, setDirtyDeleteFiles] = useState([]); @@ -116,6 +122,33 @@ export const SessionsPage = () => { void loadSshKeys(); }, []); + useEffect(() => { + const loadBranches = async () => { + if (!selectedRepo || !selectedProject || cloneMode !== "clone") { + setBranches([]); + setIsCreatingNewBranch(false); + setNewBranchName(""); + setBaseBranch(""); + return; + } + setIsLoadingBranches(true); + try { + const data = await listRepositoryBranches(selectedProject, selectedRepo); + setBranches(data.branches); + const defaultBranch = data.default_branch; + setBaseBranch(defaultBranch); + if (!branch || !data.branches.find((b) => b.name === branch)) { + setBranch(defaultBranch); + } + } catch { + setBranches([]); + } finally { + setIsLoadingBranches(false); + } + }; + void loadBranches(); + }, [selectedRepo, selectedProject, cloneMode]); + // Poll health every 30 seconds for active instances useEffect(() => { const checkHealth = async () => { @@ -213,7 +246,8 @@ export const SessionsPage = () => { selectedToolType, displayName || undefined, cloneMode, - cloneMode === "clone" ? branch : undefined + isCreatingNewBranch ? baseBranch : branch, + isCreatingNewBranch ? newBranchName : undefined ); // Auto-start the instance @@ -227,6 +261,10 @@ export const SessionsPage = () => { setDisplayName(""); setCloneMode("mount"); setBranch("main"); + setIsCreatingNewBranch(false); + setNewBranchName(""); + setBaseBranch(""); + setBranches([]); await loadSessions(); } catch (error) { setCreateStatus("error"); @@ -687,14 +725,61 @@ export const SessionsPage = () => { <> + {isCreatingNewBranch && ( + <> + + + + )} + {selectedRepo && (
{(() => {