From fc8411b5fa93450e487f4af4232f7bacff677f0d 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 | 46 +++++++++++++++++++++++++++++++++++++++++ src/core/config.ts | 3 ++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 77e35e0d..7571bcb8 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,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 f1e28080..5fa2eecb 100644 --- a/src/core/config.test.ts +++ b/src/core/config.test.ts @@ -161,6 +161,52 @@ describe("config resolution", () => { expect(fallbackResolved.input.options.excludeUntracked).toBe(false); }); + test("resolves watch from config unless CLI explicitly enables it", () => { + const cases: Array<{ + config: string; + cliOptions: Partial; + expected: boolean; + }> = [ + { + config: "watch = true\n", + cliOptions: {}, + expected: true, + }, + { + config: "watch = false\n", + cliOptions: {}, + expected: false, + }, + { + config: "", + cliOptions: {}, + expected: false, + }, + { + config: "watch = false\n", + cliOptions: { watch: true }, + expected: true, + }, + ]; + + for (const entry of cases) { + const home = createTempDir("hunk-config-home-"); + mkdirSync(join(home, ".config", "hunk"), { recursive: true }); + writeFileSync(join(home, ".config", "hunk", "config.toml"), entry.config); + + const resolved = resolveConfiguredCliInput( + { + kind: "vcs", + staged: false, + options: entry.cliOptions, + }, + { cwd: createTempDir("hunk-config-cwd-"), env: { HOME: home } }, + ); + + expect(resolved.input.options.watch).toBe(entry.expected); + } + }); + test("defaults to git VCS mode and accepts jj 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 21f12fd3..ae19f0b1 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -58,6 +58,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), @@ -186,7 +187,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,