mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
Add worktree support and consolidate branch management UI (#78)
* Fix git credential saving and improve host matching - Fix token masking bug in GitCredentialDialog that corrupted tokens on edit - Add tokenEdited state to preserve original token when not modified - Default new credential host to https://github.com - Add normalizeHostname helper for consistent host comparison - Improve credential lookup logging to show configured vs requested hosts - Remove overly permissive fuzzy matching that could leak tokens * Make OpenCode reload non-fatal when saving git credentials Settings are now saved to database even if the OpenCode server reload fails. The reload error is returned separately so the UI can inform the user that credentials were saved but the server needs a manual restart. * Fix git fetch using credentials in silent mode Previously, silent mode (used for UI fetch operations) would skip credential lookup entirely and return empty, causing auth failures. Now credentials are always looked up via IPC regardless of silent mode. * Add worktree support and consolidate branch management UI * Remove duplicate SECURE_COOKIES property from auth config * Bump version to 0.7.8
This commit is contained in:
1 parent
fb9413782a
commit
204e79c713
12 files changed
+149
-489
No files matched your search
@@ -1,138 +0,0 @@
|
||||
import { useState } from "react";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { createRepo, createBranch } from "@/api/repos";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Loader2 } from "lucide-react";
|
||||
|
||||
interface AddBranchWorkspaceDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
repoUrl: string;
|
||||
repoId: number;
|
||||
}
|
||||
|
||||
export function AddBranchWorkspaceDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
repoUrl,
|
||||
repoId,
|
||||
}: AddBranchWorkspaceDialogProps) {
|
||||
const [branch, setBranch] = useState("");
|
||||
const [useWorktree, setUseWorktree] = useState(false);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: () => {
|
||||
if (useWorktree) {
|
||||
return createRepo(repoUrl, undefined, branch || undefined, undefined, true)
|
||||
}
|
||||
return createBranch(repoId, branch)
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["repos"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["branches", repoId] });
|
||||
queryClient.invalidateQueries({ queryKey: ["repo", repoId] });
|
||||
setBranch("");
|
||||
setUseWorktree(false);
|
||||
onOpenChange(false);
|
||||
},
|
||||
});
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (branch.trim()) {
|
||||
mutation.mutate();
|
||||
}
|
||||
};
|
||||
|
||||
const handleCheckboxChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
e.stopPropagation();
|
||||
setUseWorktree(e.target.checked);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-[90%] sm:max-w-[500px] bg-[#141414] border-[#2a2a2a]">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-xl bg-gradient-to-r from-white to-gray-300 bg-clip-text text-transparent">
|
||||
Add Branch
|
||||
</DialogTitle>
|
||||
<p className="text-sm text-zinc-400 mt-1">
|
||||
Create a new branch for{" "}
|
||||
{repoUrl.split("/").pop()?.replace(".git", "")}
|
||||
</p>
|
||||
</DialogHeader>
|
||||
<form onSubmit={handleSubmit} className="space-y-4 mt-4">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm text-zinc-400">Branch *</label>
|
||||
<Input
|
||||
placeholder="feature-branch, main, etc."
|
||||
value={branch}
|
||||
onChange={(e) => setBranch(e.target.value)}
|
||||
disabled={mutation.isPending}
|
||||
className="bg-[#1a1a1a] border-[#2a2a2a] text-white placeholder:text-zinc-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="worktree-checkbox"
|
||||
checked={useWorktree}
|
||||
onChange={handleCheckboxChange}
|
||||
disabled={mutation.isPending}
|
||||
className="w-4 h-4 rounded border-gray-600 bg-gray-800 text-blue-600 focus:ring-blue-600 focus:ring-2 cursor-pointer accent-blue-600"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
/>
|
||||
<label
|
||||
htmlFor="worktree-checkbox"
|
||||
className="text-sm text-zinc-400 cursor-pointer select-none"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
if (!mutation.isPending) {
|
||||
setUseWorktree(!useWorktree);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Create as worktree
|
||||
</label>
|
||||
</div>
|
||||
<p className="text-xs text-zinc-500">
|
||||
{useWorktree
|
||||
? "Creates a separate workspace directory - allows working on multiple branches simultaneously"
|
||||
: "Creates a local branch in the current repository"}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={!branch || mutation.isPending}
|
||||
className="w-full bg-blue-600 hover:bg-blue-700 text-white"
|
||||
>
|
||||
{mutation.isPending ? (
|
||||
<>
|
||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
||||
{useWorktree ? "Creating worktree..." : "Creating branch..."}
|
||||
</>
|
||||
) : useWorktree ? (
|
||||
"Create Worktree"
|
||||
) : (
|
||||
"Create Branch"
|
||||
)}
|
||||
</Button>
|
||||
{mutation.isError && (
|
||||
<p className="text-sm text-red-400">{mutation.error.message}</p>
|
||||
)}
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
import { useState, useCallback } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { GitBranch, Check, Plus, Loader2 } from "lucide-react";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { listBranches, switchBranch, GitAuthError } from "@/api/repos";
|
||||
import { AddBranchWorkspaceDialog } from "@/components/repo/AddBranchWorkspaceDialog";
|
||||
import { showToast } from "@/lib/toast";
|
||||
|
||||
interface BranchSwitcherProps {
|
||||
repoId: number;
|
||||
currentBranch: string;
|
||||
isWorktree?: boolean;
|
||||
repoUrl?: string | null;
|
||||
className?: string;
|
||||
iconOnly?: boolean;
|
||||
}
|
||||
|
||||
export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, className, iconOnly }: BranchSwitcherProps) {
|
||||
const [addBranchOpen, setAddBranchOpen] = useState(false);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const { data: branches, isLoading: branchesLoading, refetch: refetchBranches } = useQuery({
|
||||
queryKey: ["branches", repoId],
|
||||
queryFn: () => listBranches(repoId),
|
||||
enabled: false,
|
||||
staleTime: Infinity,
|
||||
});
|
||||
|
||||
const activeBranch = branches?.branches?.find(b => b.current)?.name ?? currentBranch;
|
||||
|
||||
const handleDropdownOpenChange = useCallback((open: boolean) => {
|
||||
if (open && repoId) {
|
||||
refetchBranches();
|
||||
}
|
||||
}, [repoId, refetchBranches]);
|
||||
|
||||
const switchBranchMutation = useMutation({
|
||||
mutationFn: (branch: string) => switchBranch(repoId, branch),
|
||||
onSuccess: async (updatedRepo) => {
|
||||
queryClient.setQueryData(["repo", repoId], updatedRepo);
|
||||
queryClient.invalidateQueries({ queryKey: ["repos"] });
|
||||
await refetchBranches();
|
||||
showToast.success(`Switched to branch: ${updatedRepo.currentBranch}`);
|
||||
},
|
||||
onError: (error) => {
|
||||
if (error instanceof GitAuthError) {
|
||||
showToast.error('Authentication failed. Please update your Git token in Settings or run "gh auth login".');
|
||||
} else {
|
||||
showToast.error(error.message || 'Failed to switch branch');
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const showLoading = switchBranchMutation.isPending || (branchesLoading && !branches);
|
||||
|
||||
return (
|
||||
<>
|
||||
<DropdownMenu onOpenChange={handleDropdownOpenChange}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={switchBranchMutation.isPending}
|
||||
className={`h-6 px-1 sm:px-2 text-[10px] sm:text-xs text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:bg-accent gap-1 border border-blue-500/20 ${iconOnly ? 'w-6' : ''} ${className || ""}`}
|
||||
>
|
||||
{showLoading ? (
|
||||
<Loader2 className="w-3 h-3 animate-spin" />
|
||||
) : (
|
||||
<GitBranch className="w-3 h-3" />
|
||||
)}
|
||||
{!iconOnly && <span className="truncate">{activeBranch}</span>}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent sideOffset={0} align="end" className="bg-card border-border min-w-50 max-w-[95vw] sm:max-w-none">
|
||||
{isWorktree ? (
|
||||
<DropdownMenuItem disabled className="text-muted-foreground">
|
||||
<div className="flex items-center gap-2 w-full">
|
||||
<GitBranch className="w-3 h-3" />
|
||||
<span className="flex-1">Worktree: {activeBranch}</span>
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
) : (
|
||||
<>
|
||||
{repoUrl && (
|
||||
<>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setAddBranchOpen(true)}
|
||||
className="text-muted-foreground hover:text-foreground hover:bg-accent cursor-pointer"
|
||||
>
|
||||
<div className="flex items-center gap-2 w-full">
|
||||
<Plus className="w-3 h-3" />
|
||||
<span className="flex-1">Add Branch</span>
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
</>
|
||||
)}
|
||||
<div className="max-h-[60vh] overflow-y-auto w-full">
|
||||
{branchesLoading && !branches ? (
|
||||
<DropdownMenuItem disabled className="text-muted-foreground">
|
||||
Loading branches...
|
||||
</DropdownMenuItem>
|
||||
) : branches?.branches && branches.branches.length > 0 ? (
|
||||
branches.branches.filter(b => b.type === 'local').map((branch) => (
|
||||
<DropdownMenuItem
|
||||
key={branch.name}
|
||||
onClick={() => switchBranchMutation.mutate(branch.name)}
|
||||
disabled={switchBranchMutation.isPending}
|
||||
className="text-muted-foreground hover:text-foreground hover:bg-accent cursor-pointer"
|
||||
>
|
||||
<div className="flex items-center gap-2 w-full">
|
||||
<GitBranch className="w-3 h-3" />
|
||||
<span className="flex-1">{branch.name}</span>
|
||||
{branch.name === activeBranch && <Check className="w-3 h-3 text-green-500" />}
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
))
|
||||
) : (
|
||||
<DropdownMenuItem disabled className="text-muted-foreground">
|
||||
No branches available
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{repoUrl && (
|
||||
<AddBranchWorkspaceDialog
|
||||
open={addBranchOpen}
|
||||
onOpenChange={setAddBranchOpen}
|
||||
repoUrl={repoUrl}
|
||||
repoId={repoId}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Loader2, Trash2, Download, GitBranch, FolderOpen, AlertCircle } from "lucide-react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { downloadRepo } from "@/api/repos";
|
||||
import { showToast } from "@/lib/toast";
|
||||
import type { GitStatusResponse } from "@/types/git";
|
||||
|
||||
import { BranchSwitcher } from "./BranchSwitcher";
|
||||
import { SourceControlPanel } from "@/components/source-control/SourceControlPanel";
|
||||
|
||||
interface RepoCardProps {
|
||||
repo: {
|
||||
@@ -38,6 +37,7 @@ export function RepoCard({
|
||||
}: RepoCardProps) {
|
||||
const navigate = useNavigate();
|
||||
const [isDownloading, setIsDownloading] = useState(false);
|
||||
const [showSourceControl, setShowSourceControl] = useState(false);
|
||||
|
||||
const repoName = repo.repoUrl
|
||||
? repo.repoUrl.split("/").slice(-1)[0].replace(".git", "")
|
||||
@@ -53,7 +53,7 @@ export function RepoCard({
|
||||
const unstagedCount = gitStatus?.files.filter((f) => !f.staged).length || 0;
|
||||
|
||||
const handleCardClick = () => {
|
||||
if (isReady) {
|
||||
if (isReady && !showSourceControl) {
|
||||
navigate(`/repos/${repo.id}`);
|
||||
}
|
||||
};
|
||||
@@ -96,11 +96,7 @@ export function RepoCard({
|
||||
{isReady && (
|
||||
<div className={`w-2 h-2 rounded-full shrink-0 ${isDirty ? 'bg-orange-500' : 'bg-green-500'}`} />
|
||||
)}
|
||||
{repo.isWorktree && (
|
||||
<Badge variant="secondary" className="text-xs px-1.5 py-0 shrink-0">
|
||||
worktree
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -113,7 +109,7 @@ export function RepoCard({
|
||||
</span>
|
||||
) : (
|
||||
<>
|
||||
<span className="flex items-center gap-1 shrink-0">
|
||||
<span className={`flex items-center gap-1 shrink-0 ${repo.isWorktree ? 'text-purple-400' : ''}`}>
|
||||
<GitBranch className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="truncate max-w-[80px]">{branchToDisplay || "main"}</span>
|
||||
</span>
|
||||
@@ -145,14 +141,16 @@ export function RepoCard({
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 shrink-0" onClick={(e) => e.stopPropagation()}>
|
||||
<BranchSwitcher
|
||||
repoId={repo.id}
|
||||
currentBranch={branchToDisplay || ""}
|
||||
isWorktree={repo.isWorktree}
|
||||
repoUrl={repo.repoUrl}
|
||||
iconOnly={true}
|
||||
className="h-8 w-8"
|
||||
/>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={(e) => handleActionClick(e, () => setShowSourceControl(true))}
|
||||
disabled={!isReady}
|
||||
className="h-8 w-8 p-0"
|
||||
title="Source Control"
|
||||
>
|
||||
<GitBranch className="w-4 h-4" />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
@@ -195,6 +193,16 @@ export function RepoCard({
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<SourceControlPanel
|
||||
repoId={repo.id}
|
||||
isOpen={showSourceControl}
|
||||
onClose={() => setShowSourceControl(false)}
|
||||
currentBranch={branchToDisplay || ""}
|
||||
repoUrl={repo.repoUrl}
|
||||
isRepoWorktree={repo.isWorktree}
|
||||
repoName={repoName}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user