Skip to content

Commit 8a9b713

Browse files
committed
Improve hg revset used by jest-changed-files
The old revset is `ancestor(.^, min(branch(.) and not min(branch(default)), max(public()))`. It can select public commits unintentionally in some cases. In the following two examples, commit A would be selected by the old code path as the "from revision". The new revset would select commit C instead, which is better because the developer won't want to test commits in the `B::C` range. Example 1 - Multiple named branches: E default (named branch), public : | D stable (named branch), draft (only commit the developer cases about) | | | C stable (named branch), public | : | | | B stable (named branch), public |/ A Example 2 - Multiple heads in the "default" named branch: E default (named branch), public, has a bigger revision number than C. : | D default (named branch), draft (only commit the developer cases about) | | | C default (named branch), public | : | | | B default (named branch), public |/ A Explanation of the `min(!public() & ::.)^` revset: With modern Mercurial, `!public()` is the way to select local commits that do not exist on other developer's repos. `& ::.` limits commits to only the current "feature branch" (branch in terms of the commit DAG, not hg named branches). `min` selects the first commit in the non-public feature branch, and `^` selects its immediate parent. Note: it's `!public() & ::.` instead of `::. & !public()` intentionally, because the former has a fast path [1]. [1]: See https://www.mercurial-scm.org/repo/hg/rev/c6c8a52e28c9077580dd2f0552eb2bd6d5e0d13c
1 parent 9ba62ad commit 8a9b713

File tree

1 file changed

+1
-12
lines changed
  • packages/jest-changed-files/src

1 file changed

+1
-12
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@ import {Path, Options, SCMAdapter} from './types';
1313

1414
const env = {...process.env, HGPLAIN: '1'};
1515

16-
const ANCESTORS = [
17-
// Parent commit to this one.
18-
'.^',
19-
20-
// The first commit of my branch, only if we are not on the default branch.
21-
'min(branch(.)) and not min(branch(default))',
22-
23-
// Latest public commit.
24-
'max(public())',
25-
];
26-
2716
const adapter: SCMAdapter = {
2817
findChangedFiles: async (
2918
cwd: string,
@@ -33,7 +22,7 @@ const adapter: SCMAdapter = {
3322

3423
const args = ['status', '-amnu'];
3524
if (options && options.withAncestor) {
36-
args.push('--rev', `ancestor(${ANCESTORS.join(', ')})`);
25+
args.push('--rev', `min(!public() & ::.)^`);
3726
} else if (options && options.changedSince) {
3827
args.push('--rev', `ancestor(., ${options.changedSince})`);
3928
} else if (options && options.lastCommit === true) {

0 commit comments

Comments
 (0)