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
5 changes: 5 additions & 0 deletions .changeset/seven-pans-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hunkdiff": patch
---

Fix global config discovery on Windows when `HOME` is unavailable.
23 changes: 23 additions & 0 deletions src/core/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,29 @@ describe("config resolution", () => {
expect(overridden.input.options.transparentBackground).toBe(false);
});

test("loads global config from USERPROFILE when HOME is unavailable", () => {
const profile = createTempDir("hunk-config-profile-");
mkdirSync(join(profile, ".config", "hunk"), { recursive: true });
writeFileSync(
join(profile, ".config", "hunk", "config.toml"),
"transparent_background = true\n",
);

const configured = resolveConfiguredCliInput(
{
kind: "vcs",
staged: false,
options: {},
},
{
cwd: createTempDir("hunk-config-cwd-"),
env: { USERPROFILE: profile },
},
);

expect(configured.input.options.transparentBackground).toBe(true);
});

test("defaults unspecified themes to github-dark-default, including piped pager-style patch input", () => {
const home = createTempDir("hunk-config-home-");
const cwd = createTempDir("hunk-config-cwd-");
Expand Down
11 changes: 11 additions & 0 deletions src/core/paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ describe("paths", () => {
expect(resolveHunkStatePath(env)).toBe(join("/tmp", "home", ".config", "hunk", "state.json"));
});

test("falls back to USERPROFILE when HOME is unavailable", () => {
const env = { USERPROFILE: join("/tmp", "windows-profile") } as NodeJS.ProcessEnv;

expect(resolveGlobalConfigPath(env)).toBe(
join("/tmp", "windows-profile", ".config", "hunk", "config.toml"),
);
expect(resolveHunkStatePath(env)).toBe(
join("/tmp", "windows-profile", ".config", "hunk", "state.json"),
);
});

test("locates the bundled Hunk review skill from source", () => {
const resolvedPath = resolveBundledHunkReviewSkillPath([import.meta.dir]);

Expand Down
5 changes: 3 additions & 2 deletions src/core/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export function resolveUserConfigDir(env: NodeJS.ProcessEnv = process.env) {
return env.XDG_CONFIG_HOME;
}

if (env.HOME) {
return join(env.HOME, ".config");
const home = env.HOME || env.USERPROFILE;
if (home) {
return join(home, ".config");
}

return undefined;
Expand Down