From 807a64a34eb58022bf89b6fb4455e28b4281cb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=B8ller?= Date: Fri, 22 Feb 2019 21:33:02 +0100 Subject: [PATCH 1/2] fix(jest-changed-files): only return files from getChangedFilesFromRoots Previously, the function would return parts of commit messages as if they were files, if the commit message contained multiple paragraphs of text. --- e2e/__tests__/jestChangedFiles.test.js | 15 ++++++++++++--- packages/jest-changed-files/src/git.ts | 6 ++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/e2e/__tests__/jestChangedFiles.test.js b/e2e/__tests__/jestChangedFiles.test.js index d4efe1838964..9736299bb2ac 100644 --- a/e2e/__tests__/jestChangedFiles.test.js +++ b/e2e/__tests__/jestChangedFiles.test.js @@ -148,7 +148,11 @@ test('gets changed files for git', async () => { ).toEqual(['file1.txt', 'file2.txt', 'file3.txt']); run(`${GIT} add .`, DIR); - run(`${GIT} commit --no-gpg-sign -m "test"`, DIR); + + // Uses multiple `-m` to make the commit message have multiple + // paragraphs. This is done to ensure that `changedFiles` only + // returns files and not parts of commit messages. + run(`${GIT} commit --no-gpg-sign -m "test" -m "extra-line"`, DIR); ({changedFiles: files} = await getChangedFilesForRoots(roots, {})); expect(Array.from(files)).toEqual([]); @@ -266,8 +270,13 @@ test('gets changed files for hg', async () => { // skip this test and run it only locally. return; } + + // file1.txt is used to make a multi-line commit message + // with `hg commit -l file1.txt`. + // This is done to ensure that `changedFiles` only returns files + // and not parts of commit messages. writeFiles(DIR, { - 'file1.txt': 'file1', + 'file1.txt': 'file1\n\nextra-line', 'nested-dir/file2.txt': 'file2', 'nested-dir/second-nested-dir/file3.txt': 'file3', }); @@ -286,7 +295,7 @@ test('gets changed files for hg', async () => { ).toEqual(['file1.txt', 'file2.txt', 'file3.txt']); run(`${HG} add .`, DIR); - run(`${HG} commit -m "test"`, DIR); + run(`${HG} commit -l file1.txt`, 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 27124ef57c33..463ad88647da 100644 --- a/packages/jest-changed-files/src/git.ts +++ b/packages/jest-changed-files/src/git.ts @@ -35,7 +35,9 @@ const adapter: SCMAdapter = { if (options && options.lastCommit) { return findChangedFilesUsingCommand( - ['show', '--name-only', '--pretty=%b', 'HEAD'].concat(includePaths), + ['show', '--name-only', '--pretty=format:', 'HEAD'].concat( + includePaths, + ), cwd, ); } else if (changedSince) { @@ -43,7 +45,7 @@ const adapter: SCMAdapter = { [ 'log', '--name-only', - '--pretty=%b', + '--pretty=format:', 'HEAD', `^${changedSince}`, ].concat(includePaths), From 977d8bfcebbcaf07ec8789ce44e8ad8d873806c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=B8ller?= Date: Fri, 22 Feb 2019 21:45:23 +0100 Subject: [PATCH 2/2] docs: update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d6ca4619aa6..c6036bc6a614 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - `[jest-circus]` Fix bug with test.only ([#7888](https://github.com/facebook/jest/pull/7888)) - `[jest-transform]` Normalize config and remove unecessary checks, convert `TestUtils.js` to TypeScript ([#7801](https://github.com/facebook/jest/pull/7801)) - `[jest-worker]` Fix `jest-worker` when using pre-allocated jobs ([#7934](https://github.com/facebook/jest/pull/7934)) +- `[jest-changed-files]` Fix `getChangedFilesFromRoots` to not return parts of the commit messages as if they were files, when the commit messages contained multiple paragraphs ([#7961](https://github.com/facebook/jest/pull/7961)) ### Chore & Maintenance