Skip to content

Commit

Permalink
fix: jest --watch fails with ambiguous argument
Browse files Browse the repository at this point in the history
  • Loading branch information
yokomotod committed Mar 6, 2021
1 parent fedafc3 commit 7e5ae5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
10 changes: 9 additions & 1 deletion e2e/__tests__/jestChangedFiles.test.ts
Expand Up @@ -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));

Expand Down Expand Up @@ -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, {});
Expand All @@ -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([]);

Expand Down
28 changes: 18 additions & 10 deletions packages/jest-changed-files/src/git.ts
Expand Up @@ -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,
Expand All @@ -53,33 +53,41 @@ 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,
),
]);
return [...committed, ...staged, ...unstaged];
}
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,
),
]);
Expand Down

0 comments on commit 7e5ae5b

Please sign in to comment.