Show branch switcher for worktrees with view changes option

This commit is contained in:
Chris Scott committed 2025-12-14 19:26:26 -05:00
1 parent 99ed632355
commit dc8aeaa26c
2 files changed
+78 -56

No files matched your search

+68 -44
View File
@@ -60,10 +60,6 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
},
});
if (isWorktree) {
return null;
}
const isCurrentBranchInList = branches?.all?.includes(currentBranch) ?? false;
const showLoading = switchBranchMutation.isPending || (branchesLoading && !isCurrentBranchInList);
@@ -86,58 +82,86 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent sideOffset={0} align="end" className="bg-card border-border min-w-[200px]">
{branchesLoading ? (
<DropdownMenuItem disabled className="text-muted-foreground">
Loading branches...
</DropdownMenuItem>
) : branches?.all && branches.all.length > 0 ? (
branches.all.map((branch: string) => (
<DropdownMenuItem
key={branch}
onClick={() => switchBranchMutation.mutate(branch)}
disabled={switchBranchMutation.isPending}
className="text-muted-foreground hover:text-foreground hover:bg-accent cursor-pointer"
>
{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">{branch}</span>
{branch === currentBranch && <Check className="w-3 h-3 text-green-500" />}
<span className="flex-1">Worktree: {currentBranch}</span>
</div>
</DropdownMenuItem>
))
) : (
<DropdownMenuItem disabled className="text-muted-foreground">
No branches available
</DropdownMenuItem>
)}
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => setGitChangesOpen(true)}
className="text-muted-foreground hover:text-foreground hover:bg-accent cursor-pointer"
>
<div className="flex items-center gap-2 w-full">
<GitCommit className="w-3 h-3" />
<span className="flex-1">View Changes</span>
{gitStatus?.hasChanges && (
<span className="text-xs text-yellow-500">
{gitStatus.files.length}
</span>
)}
</div>
</DropdownMenuItem>
{!isWorktree && repoUrl && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => setAddBranchOpen(true)}
onClick={() => setGitChangesOpen(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>
<GitCommit className="w-3 h-3" />
<span className="flex-1">View Changes</span>
{gitStatus?.hasChanges && (
<span className="text-xs text-yellow-500">
{gitStatus.files.length}
</span>
)}
</div>
</DropdownMenuItem>
</>
) : (
<>
{branchesLoading ? (
<DropdownMenuItem disabled className="text-muted-foreground">
Loading branches...
</DropdownMenuItem>
) : branches?.all && branches.all.length > 0 ? (
branches.all.map((branch: string) => (
<DropdownMenuItem
key={branch}
onClick={() => switchBranchMutation.mutate(branch)}
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}</span>
{branch === currentBranch && <Check className="w-3 h-3 text-green-500" />}
</div>
</DropdownMenuItem>
))
) : (
<DropdownMenuItem disabled className="text-muted-foreground">
No branches available
</DropdownMenuItem>
)}
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => setGitChangesOpen(true)}
className="text-muted-foreground hover:text-foreground hover:bg-accent cursor-pointer"
>
<div className="flex items-center gap-2 w-full">
<GitCommit className="w-3 h-3" />
<span className="flex-1">View Changes</span>
{gitStatus?.hasChanges && (
<span className="text-xs text-yellow-500">
{gitStatus.files.length}
</span>
)}
</div>
</DropdownMenuItem>
{repoUrl && (
<>
<DropdownMenuSeparator />
<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>
</>
)}
</>
)}
</DropdownMenuContent>
</DropdownMenu>
+10 -12
View File
@@ -83,7 +83,7 @@ export function RepoCard({
<Badge
className="text-xs px-2.5 py-0.5 bg-purple-600/20 text-purple-600 dark:text-purple-400 border-purple-600/40"
>
worktree
{branchToDisplay || "main"}
</Badge>
)}
{repo.cloneStatus === "cloning" && (
@@ -120,17 +120,15 @@ export function RepoCard({
Open
</Button>
{!repo.isWorktree && (
<BranchSwitcher
repoId={repo.id}
currentBranch={branchToDisplay || ""}
isWorktree={repo.isWorktree}
repoUrl={repo.repoUrl}
repoLocalPath={repo.localPath}
iconOnly={true}
className="h-10 sm:h-9 w-10"
/>
)}
<BranchSwitcher
repoId={repo.id}
currentBranch={branchToDisplay || ""}
isWorktree={repo.isWorktree}
repoUrl={repo.repoUrl}
repoLocalPath={repo.localPath}
iconOnly={true}
className="h-10 sm:h-9 w-10"
/>
<Button
size="sm"