Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.2] - 2026-11-22

### Changed
Expand Down
11 changes: 8 additions & 3 deletions src/adapters/vscode/repoWatchers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import * as vscode from "vscode";
import {
normalizeFsPathForComparison,
normalizeRepoRelPath,
} from "../../utils/paths";

export type RepoWatchers = {
dispose(): void;
Expand Down Expand Up @@ -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;
}

Expand Down
41 changes: 41 additions & 0 deletions src/test/unit/adapters/vscode/repoWatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)", () => {
Expand Down
70 changes: 70 additions & 0 deletions src/test/unit/registration/registerCommands.test.ts
Original file line number Diff line number Diff line change
@@ -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<void>) => ({
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();
});
});
34 changes: 33 additions & 1 deletion src/test/unit/utils/paths.test.ts
Original file line number Diff line number Diff line change
@@ -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 };
Expand All @@ -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" };
Expand Down
4 changes: 2 additions & 2 deletions src/test/unit/views/changelistTreeProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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");
});

Expand Down
24 changes: 23 additions & 1 deletion src/test/unit/views/worklistDecorationProvider.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 12 additions & 4 deletions src/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/views/changelistTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function fileIcon(state: FileStageState): string {
if (state === "partial") {
return "remove";
}
return "square";
return "primitive-square";
}

function fileContextValue(state: FileStageState): string {
Expand Down Expand Up @@ -269,7 +269,7 @@ function groupIcon(state: GroupStageState): string {
case "all":
return "check";
case "none":
return "square";
return "primitive-square";
case "mixed":
return "remove";
}
Expand Down
16 changes: 1 addition & 15 deletions src/views/worklistDecorationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Loading