Skip to content

Commit d80918b

Browse files
feat: allow specifying remote branch as base when creating new worktree (#1005)
- Update `GitState.getBranches` to include remote branches - Update `WorktreeSelect` to display remote branches with a cloud icon - Allow filtering and selecting remote branches in the UI Resolves #958 🤖 Generated with [Pochi](https://getpochi.com) Co-authored-by: Pochi <[email protected]>
1 parent 3385c56 commit d80918b

File tree

2 files changed

+45
-26
lines changed

2 files changed

+45
-26
lines changed

packages/vscode-webui/src/components/worktree-select.tsx

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import {
2626
} from "@getpochi/common/vscode-webui-bridge";
2727
import { DropdownMenuPortal } from "@radix-ui/react-dropdown-menu";
2828
import { useQuery } from "@tanstack/react-query";
29-
import { CheckIcon, CirclePlus, GitBranchIcon, PlusIcon } from "lucide-react";
29+
import {
30+
CheckIcon,
31+
CirclePlus,
32+
CloudIcon,
33+
GitBranchIcon,
34+
PlusIcon,
35+
} from "lucide-react";
3036
import { useState } from "react";
3137
import { useTranslation } from "react-i18next";
3238

@@ -68,9 +74,13 @@ function BaseBranchSelector({
6874
const [search, setSearch] = useState("");
6975
const { t } = useTranslation();
7076

71-
const filteredBranches = branches?.filter((branch) =>
72-
branch.toLowerCase().includes(search.toLowerCase()),
73-
);
77+
const filteredBranches = branches?.filter((branch) => {
78+
const branchName = branch.replace(/^origin\//, "");
79+
return (
80+
branchName.toLowerCase().includes(search.toLowerCase()) ||
81+
branch.toLowerCase().includes(search.toLowerCase())
82+
);
83+
});
7484

7585
const [selectedIndex, setSelectedIndex] = useState(0);
7686

@@ -142,26 +152,36 @@ function BaseBranchSelector({
142152
{t("worktreeSelect.noBranchFound")}
143153
</div>
144154
)}
145-
{filteredBranches?.map((branch, index) => (
146-
<DropdownMenuItem
147-
key={branch}
148-
onSelect={() => {
149-
onChange(branch === value ? "" : branch);
150-
setOpen(false);
151-
setSearch("");
152-
}}
153-
className={cn(
154-
"cursor-pointer",
155-
selectedIndex === index &&
156-
"bg-accent/60 text-accent-foreground",
157-
value === branch && "bg-accent text-accent-foreground",
158-
)}
159-
onMouseEnter={() => setSelectedIndex(index)}
160-
>
161-
<GitBranchIcon className={cn(" h-4 w-4 shrink-0")} />
162-
<span className="truncate">{branch}</span>
163-
</DropdownMenuItem>
164-
))}
155+
{filteredBranches?.map((branch, index) => {
156+
const isRemote = branch.startsWith("origin/");
157+
const displayName = isRemote
158+
? branch
159+
: branch.replace(/^heads\//, "");
160+
return (
161+
<DropdownMenuItem
162+
key={branch}
163+
onSelect={() => {
164+
onChange(branch === value ? "" : branch);
165+
setOpen(false);
166+
setSearch("");
167+
}}
168+
className={cn(
169+
"cursor-pointer",
170+
selectedIndex === index &&
171+
"bg-accent/60 text-accent-foreground",
172+
value === branch && "bg-accent text-accent-foreground",
173+
)}
174+
onMouseEnter={() => setSelectedIndex(index)}
175+
>
176+
{isRemote ? (
177+
<CloudIcon className={cn(" h-4 w-4 shrink-0")} />
178+
) : (
179+
<GitBranchIcon className={cn(" h-4 w-4 shrink-0")} />
180+
)}
181+
<span className="truncate">{displayName}</span>
182+
</DropdownMenuItem>
183+
);
184+
})}
165185
</div>
166186
</DropdownMenuContent>
167187
</DropdownMenu>

packages/vscode/src/integrations/git/git-state.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ export class GitState implements vscode.Disposable {
8181
if (!repo) {
8282
return [];
8383
}
84-
return (await repo.getBranches({ remote: false, sort: "committerdate" }))
84+
return (await repo.getBranches({ remote: true, sort: "committerdate" }))
8585
.filter((ref) => ref.type === 0 || ref.type === 1) // Head or RemoteHead
8686
.map((ref) => ref.name)
8787
.filter((name): name is string => !!name);
8888
}
89-
9089
/**
9190
* Initialize the Git state monitor
9291
*/

0 commit comments

Comments
 (0)