diff --git a/CHANGELOG.md b/CHANGELOG.md index b3d034ce2a98..f68770b6bd4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- `[jest-changed-files]` Use '--' to separate paths from revisions ([#11160](https://github.com/facebook/jest/pull/11160)) - `[jest-circus]` [**BREAKING**] Fail tests when multiple `done()` calls are made ([#10624](https://github.com/facebook/jest/pull/10624)) - `[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)) - `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874)) diff --git a/e2e/__tests__/jestChangedFiles.test.ts b/e2e/__tests__/jestChangedFiles.test.ts index 46cf856616f2..d928557d138d 100644 --- a/e2e/__tests__/jestChangedFiles.test.ts +++ b/e2e/__tests__/jestChangedFiles.test.ts @@ -44,6 +44,10 @@ function gitInit(dir: string) { run(initCommand, dir); } +function gitCreateBranch(branchName: string, dir: string) { + run(`git branch ${branchName}`, dir); +} + beforeEach(() => cleanup(DIR)); afterEach(() => cleanup(DIR)); @@ -171,9 +175,11 @@ test('gets changed files for git', async () => { gitInit(DIR); const roots = [ - '', + // same first root name with existing branch name makes pitfall that + // causes "ambiguous argument" git error. 'nested-dir', 'nested-dir/second-nested-dir', + '', ].map(filename => path.resolve(DIR, filename)); let {changedFiles: files} = await getChangedFilesForRoots(roots, {}); @@ -190,6 +196,8 @@ test('gets changed files for git', async () => { // returns files and not parts of commit messages. run(`${GIT} commit --no-gpg-sign -m "test" -m "extra-line"`, DIR); + gitCreateBranch('nested-dir', DIR); + ({changedFiles: files} = await getChangedFilesForRoots(roots, {})); expect(Array.from(files)).toEqual([]); diff --git a/packages/jest-changed-files/src/git.ts b/packages/jest-changed-files/src/git.ts index 6ea2233aa582..88d98910c373 100644 --- a/packages/jest-changed-files/src/git.ts +++ b/packages/jest-changed-files/src/git.ts @@ -44,7 +44,7 @@ const adapter: SCMAdapter = { if (options && options.lastCommit) { return findChangedFilesUsingCommand( - ['show', '--name-only', '--pretty=format:', 'HEAD'].concat( + ['show', '--name-only', '--pretty=format:', 'HEAD', '--'].concat( includePaths, ), cwd, @@ -53,19 +53,23 @@ const adapter: SCMAdapter = { if (changedSince) { const [committed, staged, unstaged] = await Promise.all([ findChangedFilesUsingCommand( - ['diff', '--name-only', `${changedSince}...HEAD`].concat( + ['diff', '--name-only', `${changedSince}...HEAD`, '--'].concat( includePaths, ), cwd, ), findChangedFilesUsingCommand( - ['diff', '--cached', '--name-only'].concat(includePaths), + ['diff', '--cached', '--name-only', '--'].concat(includePaths), cwd, ), findChangedFilesUsingCommand( - ['ls-files', '--other', '--modified', '--exclude-standard'].concat( - includePaths, - ), + [ + 'ls-files', + '--other', + '--modified', + '--exclude-standard', + '--', + ].concat(includePaths), cwd, ), ]); @@ -73,13 +77,17 @@ const adapter: SCMAdapter = { } const [staged, unstaged] = await Promise.all([ findChangedFilesUsingCommand( - ['diff', '--cached', '--name-only'].concat(includePaths), + ['diff', '--cached', '--name-only', '--'].concat(includePaths), cwd, ), findChangedFilesUsingCommand( - ['ls-files', '--other', '--modified', '--exclude-standard'].concat( - includePaths, - ), + [ + 'ls-files', + '--other', + '--modified', + '--exclude-standard', + '--', + ].concat(includePaths), cwd, ), ]);