Skip to content

Commit 88d6b72

Browse files
jumoelSimenB
authored andcommitted
fix(jest-changed-files): only return files from getChangedFilesFromRoots (#7961)
1 parent 65b9535 commit 88d6b72

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- `[jest-circus]` Fix bug with test.only ([#7888](https://github.com/facebook/jest/pull/7888))
2121
- `[jest-transform]` Normalize config and remove unecessary checks, convert `TestUtils.js` to TypeScript ([#7801](https://github.com/facebook/jest/pull/7801))
2222
- `[jest-worker]` Fix `jest-worker` when using pre-allocated jobs ([#7934](https://github.com/facebook/jest/pull/7934))
23+
- `[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))
2324

2425
### Chore & Maintenance
2526

e2e/__tests__/jestChangedFiles.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ test('gets changed files for git', async () => {
148148
).toEqual(['file1.txt', 'file2.txt', 'file3.txt']);
149149

150150
run(`${GIT} add .`, DIR);
151-
run(`${GIT} commit --no-gpg-sign -m "test"`, DIR);
151+
152+
// Uses multiple `-m` to make the commit message have multiple
153+
// paragraphs. This is done to ensure that `changedFiles` only
154+
// returns files and not parts of commit messages.
155+
run(`${GIT} commit --no-gpg-sign -m "test" -m "extra-line"`, DIR);
152156

153157
({changedFiles: files} = await getChangedFilesForRoots(roots, {}));
154158
expect(Array.from(files)).toEqual([]);
@@ -266,8 +270,13 @@ test('gets changed files for hg', async () => {
266270
// skip this test and run it only locally.
267271
return;
268272
}
273+
274+
// file1.txt is used to make a multi-line commit message
275+
// with `hg commit -l file1.txt`.
276+
// This is done to ensure that `changedFiles` only returns files
277+
// and not parts of commit messages.
269278
writeFiles(DIR, {
270-
'file1.txt': 'file1',
279+
'file1.txt': 'file1\n\nextra-line',
271280
'nested-dir/file2.txt': 'file2',
272281
'nested-dir/second-nested-dir/file3.txt': 'file3',
273282
});
@@ -286,7 +295,7 @@ test('gets changed files for hg', async () => {
286295
).toEqual(['file1.txt', 'file2.txt', 'file3.txt']);
287296

288297
run(`${HG} add .`, DIR);
289-
run(`${HG} commit -m "test"`, DIR);
298+
run(`${HG} commit -l file1.txt`, DIR);
290299

291300
({changedFiles: files} = await getChangedFilesForRoots(roots, {}));
292301
expect(Array.from(files)).toEqual([]);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ const adapter: SCMAdapter = {
3535

3636
if (options && options.lastCommit) {
3737
return findChangedFilesUsingCommand(
38-
['show', '--name-only', '--pretty=%b', 'HEAD'].concat(includePaths),
38+
['show', '--name-only', '--pretty=format:', 'HEAD'].concat(
39+
includePaths,
40+
),
3941
cwd,
4042
);
4143
} else if (changedSince) {
4244
const committed = await findChangedFilesUsingCommand(
4345
[
4446
'log',
4547
'--name-only',
46-
'--pretty=%b',
48+
'--pretty=format:',
4749
'HEAD',
4850
`^${changedSince}`,
4951
].concat(includePaths),

0 commit comments

Comments
 (0)