From 8242cc7529f1682f163752d4476da2c86a4653a7 Mon Sep 17 00:00:00 2001 From: ozgen Date: Tue, 24 Nov 2026 16:45:42 +0100 Subject: [PATCH 1/3] fix: handle Windows drive-letter casing in repository paths --- src/adapters/vscode/repoWatchers.ts | 11 ++- .../unit/adapters/vscode/repoWatchers.test.ts | 41 +++++++++++ .../registration/registerCommands.test.ts | 70 +++++++++++++++++++ src/test/unit/utils/paths.test.ts | 34 ++++++++- .../views/worklistDecorationProvider.test.ts | 24 ++++++- src/utils/paths.ts | 16 +++-- src/views/worklistDecorationProvider.ts | 16 +---- 7 files changed, 188 insertions(+), 24 deletions(-) create mode 100644 src/test/unit/registration/registerCommands.test.ts diff --git a/src/adapters/vscode/repoWatchers.ts b/src/adapters/vscode/repoWatchers.ts index dfff1d2..bd426f6 100644 --- a/src/adapters/vscode/repoWatchers.ts +++ b/src/adapters/vscode/repoWatchers.ts @@ -1,4 +1,8 @@ import * as vscode from "vscode"; +import { + normalizeFsPathForComparison, + normalizeRepoRelPath, +} from "../../utils/paths"; export type RepoWatchers = { dispose(): void; @@ -31,14 +35,15 @@ export function createRepoWatchers(opts: { }, debounceMs); }; - const norm = (p: string) => p.replace(/\\/g, "/"); + const root = normalizeFsPathForComparison(opts.repoRoot); // Keep this list small and practical. const shouldIgnoreWorktree = (uri: vscode.Uri) => { - const p = norm(uri.fsPath); + const p = normalizeRepoRelPath(uri.fsPath); + const comparablePath = normalizeFsPathForComparison(p); // ignore outside repo (paranoia) - if (!norm(p).startsWith(norm(opts.repoRoot))) { + if (!comparablePath.startsWith(root)) { return true; } diff --git a/src/test/unit/adapters/vscode/repoWatchers.test.ts b/src/test/unit/adapters/vscode/repoWatchers.test.ts index 4c2697c..27f84e4 100644 --- a/src/test/unit/adapters/vscode/repoWatchers.test.ts +++ b/src/test/unit/adapters/vscode/repoWatchers.test.ts @@ -89,6 +89,47 @@ describe("createRepoWatchers", () => { afterEach(() => { vi.useRealTimers(); + vi.unstubAllGlobals(); + }); + + it.each(["fireCreate", "fireChange", "fireDelete"] as const)( + "refreshes for a Windows %s event with different drive casing", + (event) => { + vi.stubGlobal("process", { ...process, platform: "win32" }); + const triggerRefresh = vi.fn(); + createRepoWatchers({ + repoRoot: "C:/Users/Test/repo/", + gitDir: "C:/Users/Test/repo/.git", + triggerRefresh, + debounceMs: 50, + }); + + getBucket()[0][event]("c:\\Users\\Test\\repo\\src\\App.ts"); + vi.advanceTimersByTime(50); + expect(triggerRefresh).toHaveBeenCalledTimes(1); + }, + ); + + it.each([ + "D:\\repo\\App.ts", + "c:\\Repo\\App.ts", + "c:\\repo\\node_modules\\lib\\index.js", + "c:\\repo\\.git\\index", + "c:\\repo\\dist\\app.js", + "c:\\repo\\file.tmp", + ])("ignores excluded or outside Windows paths: %s", (fsPath) => { + vi.stubGlobal("process", { ...process, platform: "win32" }); + const triggerRefresh = vi.fn(); + createRepoWatchers({ + repoRoot: "C:/repo", + gitDir: "C:/repo/.git", + triggerRefresh, + debounceMs: 50, + }); + + getBucket()[0].fireChange(fsPath); + vi.advanceTimersByTime(50); + expect(triggerRefresh).not.toHaveBeenCalled(); }); it("creates exactly two watchers (worktree + gitdir)", () => { diff --git a/src/test/unit/registration/registerCommands.test.ts b/src/test/unit/registration/registerCommands.test.ts new file mode 100644 index 0000000..85a68e5 --- /dev/null +++ b/src/test/unit/registration/registerCommands.test.ts @@ -0,0 +1,70 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +const vscodeMock = vi.hoisted(() => { + class Uri { + constructor(public readonly fsPath: string) {} + static file(fsPath: string) { + return new Uri(fsPath); + } + } + + return { + Uri, + commands: { + registerCommand: vi.fn( + (_command: string, _handler: (arg: any) => Promise) => ({ + dispose: vi.fn(), + }), + ), + }, + window: { showErrorMessage: vi.fn() }, + }; +}); + +vi.mock("vscode", () => vscodeMock); + +import { registerCommands } from "../../../registration/registerCommands"; + +describe("single-file staging commands", () => { + beforeEach(() => { + vi.clearAllMocks(); + vi.stubGlobal("process", { ...process, platform: "win32" }); + }); + + afterEach(() => { + vi.unstubAllGlobals(); + }); + + it.each([ + ["gitWorklists.selectFile", "stagePaths"], + ["gitWorklists.unselectFile", "unstagePaths"], + ] as const)("%s handles tree nodes and URIs with different drive casing", async (command, operation) => { + const deps: any = { + context: { subscriptions: [] }, + repoRoot: "C:/Users/Test/repo", + stagePaths: { run: vi.fn(async () => {}) }, + unstagePaths: { run: vi.fn(async () => {}) }, + coordinator: { requestNow: vi.fn(async () => {}) }, + }; + registerCommands(deps); + const registration = vscodeMock.commands.registerCommand.mock.calls.find( + ([name]) => name === command, + ); + expect(registration).toBeDefined(); + const handler = registration![1]; + const uri = vscodeMock.Uri.file("c:\\Users\\Test\\repo\\src\\App.ts"); + + await handler({ resourceUri: uri }); + expect(deps[operation].run).toHaveBeenCalledWith(deps.repoRoot, ["src/App.ts"]); + expect(deps.coordinator.requestNow).toHaveBeenCalledTimes(1); + + await handler(uri); + expect(deps[operation].run).toHaveBeenCalledTimes(2); + expect(deps.coordinator.requestNow).toHaveBeenCalledTimes(2); + + await handler(vscodeMock.Uri.file("c:\\Users\\Test\\repo-other\\App.ts")); + expect(deps[operation].run).toHaveBeenCalledTimes(2); + expect(deps.coordinator.requestNow).toHaveBeenCalledTimes(2); + expect(vscodeMock.window.showErrorMessage).not.toHaveBeenCalled(); + }); +}); diff --git a/src/test/unit/utils/paths.test.ts b/src/test/unit/utils/paths.test.ts index 45d5b33..9f86c30 100644 --- a/src/test/unit/utils/paths.test.ts +++ b/src/test/unit/utils/paths.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { afterEach, describe, it, expect, vi } from "vitest"; import { normalizeRepoRelPath, toRepoRelPath } from "../../../utils/paths"; type UriLike = { fsPath: string }; @@ -14,6 +14,38 @@ describe("normalizeRepoRelPath", () => { }); describe("toRepoRelPath", () => { + afterEach(() => { + vi.unstubAllGlobals(); + }); + + it.each([ + ["C:/Users/Test/repo", "c:\\Users\\Test\\repo\\src\\App.ts"], + ["c:\\Users\\Test\\repo\\", "C:/Users/Test/repo/src/App.ts"], + ["C:/", "c:\\src\\App.ts"], + ])("handles Windows drive-letter casing: %s", (repoRoot, fsPath) => { + vi.stubGlobal("process", { ...process, platform: "win32" }); + expect(toRepoRelPath(repoRoot, { fsPath } as any)).toBe("src/App.ts"); + }); + + it.each([ + "c:\\repo", + "c:\\repo-other\\App.ts", + "D:\\repo\\App.ts", + "c:\\Repo\\App.ts", + ])("rejects Windows roots and paths outside the repository: %s", (fsPath) => { + vi.stubGlobal("process", { ...process, platform: "win32" }); + expect(toRepoRelPath("C:/repo", { fsPath } as any)).toBe(""); + }); + + it.each(["linux", "darwin"])( + "keeps comparisons case-sensitive on %s", + (platform) => { + vi.stubGlobal("process", { ...process, platform }); + expect(toRepoRelPath("C:/repo", { fsPath: "c:/repo/App.ts" } as any)).toBe(""); + expect(toRepoRelPath("/Repo", { fsPath: "/repo/App.ts" } as any)).toBe(""); + }, + ); + it("returns empty string when uri is exactly repoRoot", () => { const repoRoot = "/repo"; const uri: UriLike = { fsPath: "/repo" }; diff --git a/src/test/unit/views/worklistDecorationProvider.test.ts b/src/test/unit/views/worklistDecorationProvider.test.ts index f57bfb3..ebe81a3 100644 --- a/src/test/unit/views/worklistDecorationProvider.test.ts +++ b/src/test/unit/views/worklistDecorationProvider.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; const vscodeMock = vi.hoisted(() => { class ThemeColor { @@ -70,6 +70,28 @@ describe("WorklistDecorationProvider", () => { provider.setRepoRoot(repoRoot); }); + afterEach(() => { + vi.unstubAllGlobals(); + }); + + it.each([SystemChangelist.Default, SystemChangelist.Unversioned])( + "decorates a Windows file with different drive casing in %s", + async (id) => { + vi.stubGlobal("process", { ...process, platform: "win32" }); + provider.setRepoRoot("C:/Users/Test/repo"); + provider.updateSnapshot({ + state: state([{ id, name: "Changes", files: ["src/App.ts"] }]), + fileStageStates: new Map([["src/App.ts", "all"]]), + }); + + const dec = await provider.provideFileDecoration( + vscode.Uri.file("c:\\Users\\Test\\repo\\src\\App.ts"), + ); + expect(dec?.badge).toBe(id === SystemChangelist.Default ? "D" : "U"); + expect(dec?.tooltip).toContain("Staged"); + }, + ); + it("fires change when setRepoRoot is called", () => { const ee = (provider as any)._onDidChange; expect(ee.fire).toHaveBeenCalledWith(undefined); diff --git a/src/utils/paths.ts b/src/utils/paths.ts index 73a2028..5111529 100644 --- a/src/utils/paths.ts +++ b/src/utils/paths.ts @@ -4,13 +4,21 @@ export function normalizeRepoRelPath(p: string): string { return p.replace(/\\/g, "/"); } +export function normalizeFsPathForComparison(p: string): string { + const normalized = normalizeRepoRelPath(p); + return process.platform === "win32" + ? normalized.replace(/^[A-Z]:/, (drive) => drive.toLowerCase()) + : normalized; +} + export function toRepoRelPath(repoRoot: string, uri: vscode.Uri): string { - const root = repoRoot.replace(/\\/g, "/").replace(/\/+$/, ""); - const full = uri.fsPath.replace(/\\/g, "/"); - if (full === root) { + const root = normalizeFsPathForComparison(repoRoot).replace(/\/+$/, ""); + const full = normalizeRepoRelPath(uri.fsPath); + const comparableFull = normalizeFsPathForComparison(full); + if (comparableFull === root) { return ""; } - if (!full.startsWith(root + "/")) { + if (!comparableFull.startsWith(root + "/")) { return ""; } return full.slice(root.length + 1); diff --git a/src/views/worklistDecorationProvider.ts b/src/views/worklistDecorationProvider.ts index a946c4b..0e2f604 100644 --- a/src/views/worklistDecorationProvider.ts +++ b/src/views/worklistDecorationProvider.ts @@ -2,7 +2,7 @@ import * as vscode from "vscode"; import { FileStageState } from "../adapters/git/gitClient"; import { WorkspaceStateStore } from "../adapters/storage/workspaceStateStore"; import { SystemChangelist } from "../core/changelist/systemChangelist"; -import { normalizeRepoRelPath } from "../utils/paths"; +import { normalizeRepoRelPath, toRepoRelPath } from "../utils/paths"; type PersistedChangelist = { id: string; @@ -140,20 +140,6 @@ function decorationForList( ); } -function toRepoRelPath(repoRootFsPath: string, uri: vscode.Uri): string { - const root = normalizeRepoRelPath(repoRootFsPath).replace(/\/+$/, ""); - const full = normalizeRepoRelPath(uri.fsPath); - - if (full === root) { - return ""; - } - if (!full.startsWith(root + "/")) { - return ""; - } - - return full.slice(root.length + 1); -} - function badgeFromName(name: string): string { const trimmed = name.trim(); if (!trimmed) { From 6170edcc62ae639ee59d54a5efa973b85f34929e Mon Sep 17 00:00:00 2001 From: ozgen Date: Tue, 24 Nov 2026 16:45:50 +0100 Subject: [PATCH 2/3] fix: use valid icons for unstaged files and groups --- src/test/unit/views/changelistTreeProvider.test.ts | 4 ++-- src/views/changelistTreeProvider.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/unit/views/changelistTreeProvider.test.ts b/src/test/unit/views/changelistTreeProvider.test.ts index 3f37cd9..89ed3dc 100644 --- a/src/test/unit/views/changelistTreeProvider.test.ts +++ b/src/test/unit/views/changelistTreeProvider.test.ts @@ -124,7 +124,7 @@ describe("ChangelistTreeProvider (unit)", () => { expect((root[1] as any).contextValue).toBe("gitWorklists.group.system"); expect((root[2] as any).contextValue).toBe("gitWorklists.group.custom"); - expect(((root[0] as any).iconPath as any).id).toBe("square"); + expect(((root[0] as any).iconPath as any).id).toBe("primitive-square"); expect((root[0] as any).command).toBeUndefined(); }); @@ -262,7 +262,7 @@ describe("ChangelistTreeProvider (unit)", () => { const fc = files[2] as any; // c.txt — none expect(fc.stageState).toBe("none"); - expect((fc.iconPath as any).id).toBe("square"); + expect((fc.iconPath as any).id).toBe("primitive-square"); expect(fc.contextValue).toBe("gitWorklists.file.unstaged"); }); diff --git a/src/views/changelistTreeProvider.ts b/src/views/changelistTreeProvider.ts index 1f368af..0272931 100644 --- a/src/views/changelistTreeProvider.ts +++ b/src/views/changelistTreeProvider.ts @@ -241,7 +241,7 @@ function fileIcon(state: FileStageState): string { if (state === "partial") { return "remove"; } - return "square"; + return "primitive-square"; } function fileContextValue(state: FileStageState): string { @@ -269,7 +269,7 @@ function groupIcon(state: GroupStageState): string { case "all": return "check"; case "none": - return "square"; + return "primitive-square"; case "mixed": return "remove"; } From 14f9cef48506ef86a4e80bf124893bd6e4c7b848 Mon Sep 17 00:00:00 2001 From: ozgen Date: Tue, 24 Nov 2026 16:53:40 +0100 Subject: [PATCH 3/3] docs: update changelog for the new release --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 017df6a..213a145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,21 @@ No changes yet. --- +## [1.3.3] - 2026-11-24 + +### Fixed + +- Fixed single-file staging and unstaging on Windows when Git and VS Code use different drive-letter casing ([#69](https://github.com/ozgen/git-worklists/issues/69)). +- Fixed missing worklist file decorations on Windows caused by the same drive-letter mismatch. +- Fixed external file changes being ignored by the repository watcher on Windows when drive-letter casing differs. +- Restored the square icon for unstaged files and groups by using the valid `primitive-square` icon ID. + +### Maintenance + +- Added regression tests for Windows path handling in staging commands, file decorations, and repository watcher events. + +--- + ## [1.3.0] - 2026-07-31 ### Added