Skip to content

Commit 9587beb

Browse files
committed
fix: jest --watch fails with ambiguous argument
1 parent fedafc3 commit 9587beb

3 files changed

Lines changed: 28 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Features
44

5+
- `[jest-changed-files]` Use '--' to separate paths from revisions ([#11160](https://github.com/facebook/jest/pull/11160))
56
- `[jest-circus]` [**BREAKING**] Fail tests when multiple `done()` calls are made ([#10624](https://github.com/facebook/jest/pull/10624))
67
- `[jest-circus, jest-jasmine2]` [**BREAKING**] Fail the test instead of just warning when describe returns a value ([#10947](https://github.com/facebook/jest/pull/10947))
78
- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874))

e2e/__tests__/jestChangedFiles.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ function gitInit(dir: string) {
4444
run(initCommand, dir);
4545
}
4646

47+
function gitCreateBranch(branchName: string, dir: string) {
48+
run(`git branch ${branchName}`, dir);
49+
}
50+
4751
beforeEach(() => cleanup(DIR));
4852
afterEach(() => cleanup(DIR));
4953

@@ -171,9 +175,11 @@ test('gets changed files for git', async () => {
171175
gitInit(DIR);
172176

173177
const roots = [
174-
'',
178+
// same first root name with existing branch name makes pitfall that
179+
// causes "ambiguous argument" git error.
175180
'nested-dir',
176181
'nested-dir/second-nested-dir',
182+
'',
177183
].map(filename => path.resolve(DIR, filename));
178184

179185
let {changedFiles: files} = await getChangedFilesForRoots(roots, {});
@@ -190,6 +196,8 @@ test('gets changed files for git', async () => {
190196
// returns files and not parts of commit messages.
191197
run(`${GIT} commit --no-gpg-sign -m "test" -m "extra-line"`, DIR);
192198

199+
gitCreateBranch('nested-dir', DIR);
200+
193201
({changedFiles: files} = await getChangedFilesForRoots(roots, {}));
194202
expect(Array.from(files)).toEqual([]);
195203

packages/jest-changed-files/src/git.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const adapter: SCMAdapter = {
4444

4545
if (options && options.lastCommit) {
4646
return findChangedFilesUsingCommand(
47-
['show', '--name-only', '--pretty=format:', 'HEAD'].concat(
47+
['show', '--name-only', '--pretty=format:', 'HEAD', '--'].concat(
4848
includePaths,
4949
),
5050
cwd,
@@ -53,33 +53,41 @@ const adapter: SCMAdapter = {
5353
if (changedSince) {
5454
const [committed, staged, unstaged] = await Promise.all([
5555
findChangedFilesUsingCommand(
56-
['diff', '--name-only', `${changedSince}...HEAD`].concat(
56+
['diff', '--name-only', `${changedSince}...HEAD`, '--'].concat(
5757
includePaths,
5858
),
5959
cwd,
6060
),
6161
findChangedFilesUsingCommand(
62-
['diff', '--cached', '--name-only'].concat(includePaths),
62+
['diff', '--cached', '--name-only', '--'].concat(includePaths),
6363
cwd,
6464
),
6565
findChangedFilesUsingCommand(
66-
['ls-files', '--other', '--modified', '--exclude-standard'].concat(
67-
includePaths,
68-
),
66+
[
67+
'ls-files',
68+
'--other',
69+
'--modified',
70+
'--exclude-standard',
71+
'--',
72+
].concat(includePaths),
6973
cwd,
7074
),
7175
]);
7276
return [...committed, ...staged, ...unstaged];
7377
}
7478
const [staged, unstaged] = await Promise.all([
7579
findChangedFilesUsingCommand(
76-
['diff', '--cached', '--name-only'].concat(includePaths),
80+
['diff', '--cached', '--name-only', '--'].concat(includePaths),
7781
cwd,
7882
),
7983
findChangedFilesUsingCommand(
80-
['ls-files', '--other', '--modified', '--exclude-standard'].concat(
81-
includePaths,
82-
),
84+
[
85+
'ls-files',
86+
'--other',
87+
'--modified',
88+
'--exclude-standard',
89+
'--',
90+
].concat(includePaths),
8391
cwd,
8492
),
8593
]);

0 commit comments

Comments
 (0)