From 23c807f75df56e66fa3857233a327ab1577e3fd9 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Sun, 10 May 2026 15:59:35 -0700 Subject: [PATCH] feat(config): support watch key in TOML config --- README.md | 1 + src/core/config.test.ts | 53 +++++++++++++++++++++++++++++++++++++++++ src/core/config.ts | 3 ++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8923ce54..b363e456 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/core/config.test.ts b/src/core/config.test.ts index 7ccb1f62..b409d828 100644 --- a/src/core/config.test.ts +++ b/src/core/config.test.ts @@ -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; + 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 }); diff --git a/src/core/config.ts b/src/core/config.ts index 2c6ecd6d..67aa0322 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -59,6 +59,7 @@ function readConfigPreferences(source: Record): 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), @@ -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,