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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Example:
theme = "graphite" # graphite, midnight, paper, ember
mode = "auto" # auto, split, stack
vcs = "git" # git, jj
watch = false
exclude_untracked = false
line_numbers = true
wrap_lines = false
Expand Down
53 changes: 53 additions & 0 deletions src/core/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,59 @@ describe("config resolution", () => {
expect(fallbackResolved.input.options.excludeUntracked).toBe(false);
});

test.each([
{
name: "enables watch from config",
config: "watch = true\n",
cliOptions: {},
expected: true,
},
{
name: "disables watch from config",
config: "watch = false\n",
cliOptions: {},
expected: false,
},
{
name: "defaults watch to false",
config: "",
cliOptions: {},
expected: false,
},
{
name: "lets CLI enable watch over config",
config: "watch = false\n",
cliOptions: { watch: true },
expected: true,
},
{
name: "lets CLI disable watch over config",
config: "watch = true\n",
cliOptions: { watch: false },
expected: false,
},
] satisfies Array<{
name: string;
config: string;
cliOptions: Partial<CliInput["options"]>;
expected: boolean;
}>)("resolves watch: $name", ({ config, cliOptions, expected }) => {
const home = createTempDir("hunk-config-home-");
mkdirSync(join(home, ".config", "hunk"), { recursive: true });
writeFileSync(join(home, ".config", "hunk", "config.toml"), config);

const resolved = resolveConfiguredCliInput(
{
kind: "vcs",
staged: false,
options: cliOptions,
},
{ cwd: createTempDir("hunk-config-cwd-"), env: { HOME: home } },
);

expect(resolved.input.options.watch).toBe(expected);
});

test("defaults to git VCS mode and accepts registered VCS modes from config", () => {
const home = createTempDir("hunk-config-home-");
mkdirSync(join(home, ".config", "hunk"), { recursive: true });
Expand Down
3 changes: 2 additions & 1 deletion src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function readConfigPreferences(source: Record<string, unknown>): CommonOptions {
mode: normalizeLayoutMode(source.mode),
vcs: normalizeVcsMode(source.vcs),
theme: normalizeString(source.theme),
watch: normalizeBoolean(source.watch),
excludeUntracked: normalizeBoolean(source.exclude_untracked),
lineNumbers: normalizeBoolean(source.line_numbers),
wrapLines: normalizeBoolean(source.wrap_lines),
Expand Down Expand Up @@ -165,7 +166,7 @@ export function resolveConfiguredCliInput(
...resolvedOptions,
agentContext: input.options.agentContext,
pager: input.options.pager ?? false,
watch: input.options.watch ?? false,
watch: input.options.watch ?? resolvedOptions.watch ?? false,
excludeUntracked: resolvedOptions.excludeUntracked ?? false,
vcs: resolvedOptions.vcs ?? "git",
mode: resolvedOptions.mode ?? DEFAULT_VIEW_PREFERENCES.mode,
Expand Down
Loading