The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.
TypeScript code-editorcross-platformdapdatabase-clientdebuggerdesktop-appdeveloper-toolsgithttp-clientideintellijlsprusttauriterminal
feat(vcs): mark the current worktree in the Worktrees list (#1506)
l0ng-ai945f09347ee2
diff --git a/src/features/vcs/common.module.css b/src/features/vcs/common.module.cssindex da45e6004..05065dc61 100644--- a/src/features/vcs/common.module.css+++ b/src/features/vcs/common.module.css@@ -305,6 +305,18 @@.manageRowSelected:hover {background: var(--bg-list-selected);}+/* A fixed slot, so the names line up whether or not a row is marked. */+.worktreeMark {+ display: flex;+ flex: none;+ width: 14px;+ margin-right: -4px;+}+/* The branch keeps its width; the path is what gets cut short. */+.worktreeName {+ flex: none;+ max-width: 40%;+}.comparisonDialog > [data-dialog-body] {display: flex;diff --git a/src/features/vcs/gitMenuDialogs.tsx b/src/features/vcs/gitMenuDialogs.tsxindex cc19fb228..5fd455c17 100644--- a/src/features/vcs/gitMenuDialogs.tsx+++ b/src/features/vcs/gitMenuDialogs.tsx@@ -5,12 +5,13 @@ import type { Branch, MergeOptions, Remote, Worktree } from "@/bindings";import { executeAction } from "@/platform/actions";import { call, commands } from "@/platform/ipc";import { notifications } from "@/workbench/contributions";-import { Checkbox, Dialog, IconButton, Input, Select, T, type SelectOption } from "@/ui";+import { Checkbox, Dialog, Icon, IconButton, Input, Select, T, type SelectOption } from "@/ui";import { sortLocal, sortRemote } from "./branches";import { conflictActions, openConflictsInstead, validateBranchName } from "./branchOps";import { confirmDialog, openDialog } from "./dialogs";import { errorMessage, runOp, runRemote, saveAll } from "./ops";import { currentRepo, loadBranches, refreshNow, repoName, selectRepo, useVcs } from "./store";+import { isCurrentWorktree } from "./worktrees";import styles from "./common.module.css";import { tx } from "@/platform/i18n";@@ -660,7 +661,13 @@ export function WorktreesPanel({ className, listClassName }: { className?: strinonClick={() => setSelected(w.path)}onDoubleClick={() => void executeAction("file.openProjectPath", w.path)}>- <span className={styles.fileName}>{w.branch ?? (w.head ? w.head.slice(0, 8) : <T>(bare)</T>)}</span>+ {/* The worktree this window works in, as IDEA marks it. */}+ <span className={styles.worktreeMark}>+ {isCurrentWorktree(w.path, repo) && <Icon name="check" size={14} label={tx("Current worktree")} />}+ </span>+ <span className={clsx(styles.fileName, styles.worktreeName)}>+ {w.branch ?? (w.head ? w.head.slice(0, 8) : <T>(bare)</T>)}+ </span><span className={clsx(styles.fileDir, styles.mono)}>{w.path}</span>{(w.main || w.locked || w.prunable) && (<span className={styles.fileDir}>{w.main ? "main" : w.locked ? tx("locked") : tx("prunable")}</span>diff --git a/src/features/vcs/worktrees.test.ts b/src/features/vcs/worktrees.test.tsnew file mode 100644index 000000000..61ea6e477--- /dev/null+++ b/src/features/vcs/worktrees.test.ts@@ -0,0 +1,18 @@+import { describe, expect, it } from "vitest";+import { isCurrentWorktree } from "./worktrees";++describe("isCurrentWorktree", () => {+ it("matches the repository root this window works in", () => {+ expect(isCurrentWorktree("/work/app", "/work/app")).toBe(true);+ expect(isCurrentWorktree("/work/app-wt", "/work/app")).toBe(false);+ expect(isCurrentWorktree("/work/app/", "/work/app")).toBe(true);+ expect(isCurrentWorktree("/work/app", null)).toBe(false);+ });++ it("ignores the drive letter's case and separators on Windows", () => {+ expect(isCurrentWorktree("c:/Work/app", "C:/Work/app")).toBe(true);+ expect(isCurrentWorktree("C:\\Work\\app", "C:/Work/app")).toBe(true);+ // Only drive paths: elsewhere the case is part of the name.+ expect(isCurrentWorktree("/Work/App", "/work/app")).toBe(false);+ });+});diff --git a/src/features/vcs/worktrees.ts b/src/features/vcs/worktrees.tsnew file mode 100644index 000000000..24139c026--- /dev/null+++ b/src/features/vcs/worktrees.ts@@ -0,0 +1,13 @@+/**+ * Whether worktree `path` (as `git worktree list` prints it) is the repository root `root`+ * this window works in. Git prints `C:/…` with the drive in either case, so drive paths+ * compare case-insensitively; a trailing slash doesn't count.+ */+export function isCurrentWorktree(path: string, root: string | null | undefined): boolean {+ if (!root) return false;+ const norm = (p: string) => {+ const s = p.replace(/\\/g, "/").replace(/(.)\/+$/, "$1");+ return /^[A-Za-z]:\//.test(s) ? s.toLowerCase() : s;+ };+ return norm(path) === norm(root);+}diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.jsonindex 0936780f2..963b30343 100644--- a/src/platform/locales/text/zh.json+++ b/src/platform/locales/text/zh.json@@ -2707,6 +2707,7 @@"New Worktree…": "新建工作树…","Worktrees…": "工作树…","Worktrees": "工作树",+ "Current worktree": "当前工作树","New Worktree": "新建工作树","Git Remotes": "Git 远程","Define Remote": "定义远程",