Skip to content

Commit 9a52f35

Browse files
committed
feat: add cwd option to staged command
1 parent 26328ea commit 9a52f35

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

packages/rstack/src/staged.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Runs lint-staged with tasks from define.staged in rstack.config.
1111
Options:
1212
--allow-empty Allow empty commits when tasks revert all staged changes
1313
-p, --concurrent <number|boolean> The number of tasks to run concurrently, or false for serial
14+
--cwd <path> Working directory to run all tasks in
1415
--no-stash Disable the backup stash. Implies "--no-revert".
1516
-q, --quiet Disable lint-staged's own console output
1617
-r, --relative Pass relative filepaths to tasks
@@ -24,6 +25,7 @@ export async function runStagedCLI(args: string[]): Promise<void> {
2425
'allow-empty': { type: 'boolean' },
2526
allowEmpty: { type: 'boolean' },
2627
concurrent: { type: 'string', short: 'p' },
28+
cwd: { type: 'string' },
2729
help: { type: 'boolean', short: 'h' },
2830
'no-stash': { type: 'boolean' },
2931
quiet: { type: 'boolean', short: 'q' },
@@ -55,6 +57,7 @@ export async function runStagedCLI(args: string[]): Promise<void> {
5557
allowEmpty: values['allow-empty'] ?? values.allowEmpty ?? false,
5658
concurrent: values.concurrent === undefined ? true : JSON.parse(values.concurrent),
5759
config: stagedConfig,
60+
cwd: values.cwd,
5861
quiet: values.quiet ?? false,
5962
relative: values.relative ?? false,
6063
stash: !values['no-stash'],

packages/rstack/test/cli/staged/index.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ test('should display the staged help message', ({ execCli, expect }) => {
6969
expect(output).toContain('Usage:\n $ rs staged [options]');
7070
expect(output).toContain('Runs lint-staged with tasks from define.staged in rstack.config.');
7171
expect(output).toContain('--allow-empty');
72+
expect(output).toContain('--cwd <path>');
7273
expect(output).toContain('--no-stash');
7374
expect(output).toContain('-q, --quiet');
7475
expect(output).toContain('-r, --relative');
@@ -133,3 +134,14 @@ for (const option of ['--relative', '-r']) {
133134
});
134135
});
135136
}
137+
138+
test('should run staged tasks in the specified cwd', async ({ execCli, expect }) => {
139+
await withGitFixture((cwd) => {
140+
const configPath = path.join(cwd, 'rstack.config.ts');
141+
const output = execCli(
142+
`--config ${JSON.stringify(configPath)} staged --allow-empty --cwd ${JSON.stringify(cwd)} --relative --verbose`,
143+
{ cwd: path.dirname(cwd) },
144+
);
145+
expect(output).toContain('staged file: file.txt');
146+
});
147+
});

0 commit comments

Comments
 (0)