From 9a52f35c65c2bb91ec67e8da6e8d73d91a07e305 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 10 Jul 2026 14:46:14 +0800 Subject: [PATCH] feat: add cwd option to staged command --- packages/rstack/src/staged.ts | 3 +++ packages/rstack/test/cli/staged/index.test.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/rstack/src/staged.ts b/packages/rstack/src/staged.ts index 88f1e21..16d785b 100644 --- a/packages/rstack/src/staged.ts +++ b/packages/rstack/src/staged.ts @@ -11,6 +11,7 @@ Runs lint-staged with tasks from define.staged in rstack.config. Options: --allow-empty Allow empty commits when tasks revert all staged changes -p, --concurrent The number of tasks to run concurrently, or false for serial + --cwd Working directory to run all tasks in --no-stash Disable the backup stash. Implies "--no-revert". -q, --quiet Disable lint-staged's own console output -r, --relative Pass relative filepaths to tasks @@ -24,6 +25,7 @@ export async function runStagedCLI(args: string[]): Promise { 'allow-empty': { type: 'boolean' }, allowEmpty: { type: 'boolean' }, concurrent: { type: 'string', short: 'p' }, + cwd: { type: 'string' }, help: { type: 'boolean', short: 'h' }, 'no-stash': { type: 'boolean' }, quiet: { type: 'boolean', short: 'q' }, @@ -55,6 +57,7 @@ export async function runStagedCLI(args: string[]): Promise { allowEmpty: values['allow-empty'] ?? values.allowEmpty ?? false, concurrent: values.concurrent === undefined ? true : JSON.parse(values.concurrent), config: stagedConfig, + cwd: values.cwd, quiet: values.quiet ?? false, relative: values.relative ?? false, stash: !values['no-stash'], diff --git a/packages/rstack/test/cli/staged/index.test.ts b/packages/rstack/test/cli/staged/index.test.ts index 71303c4..8e1bb06 100644 --- a/packages/rstack/test/cli/staged/index.test.ts +++ b/packages/rstack/test/cli/staged/index.test.ts @@ -69,6 +69,7 @@ test('should display the staged help message', ({ execCli, expect }) => { expect(output).toContain('Usage:\n $ rs staged [options]'); expect(output).toContain('Runs lint-staged with tasks from define.staged in rstack.config.'); expect(output).toContain('--allow-empty'); + expect(output).toContain('--cwd '); expect(output).toContain('--no-stash'); expect(output).toContain('-q, --quiet'); expect(output).toContain('-r, --relative'); @@ -133,3 +134,14 @@ for (const option of ['--relative', '-r']) { }); }); } + +test('should run staged tasks in the specified cwd', async ({ execCli, expect }) => { + await withGitFixture((cwd) => { + const configPath = path.join(cwd, 'rstack.config.ts'); + const output = execCli( + `--config ${JSON.stringify(configPath)} staged --allow-empty --cwd ${JSON.stringify(cwd)} --relative --verbose`, + { cwd: path.dirname(cwd) }, + ); + expect(output).toContain('staged file: file.txt'); + }); +});