Skip to content

Commit b1d1f89

Browse files
committed
fixes
1 parent d1c4fba commit b1d1f89

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"type": "patch",
5+
"comment": "Refactor internals for getting changed packages",
6+
"packageName": "beachball",
7+
"email": "elcraig@microsoft.com",
8+
"dependentChangeType": "patch"
9+
}
10+
]
11+
}

packages/beachball/src/changefile/getChangedPackages.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ import { readJson } from '../object/readJson';
99
import { bulletedList } from '../logging/bulletedList';
1010
import { getAllChangedPackages } from './getAllChangedPackages';
1111
import { getIncludedLoggers, isPackageIncluded } from './isPackageIncluded';
12-
import { ensureSharedHistory, hasCommonCommit } from '../git/ensureSharedHistory';
12+
import { ensureSharedHistory } from '../git/ensureSharedHistory';
1313

1414
/**
1515
* Gets all the changed packages which **do not already have a change file** and are in scope.
16+
* This is only used by the `change` and `check` commands, not the bump/publish process.
1617
*
17-
* Exceptions:
18+
* Special cases:
1819
* - If `options.package` is provided, use that as-is (skipping all git operations).
1920
* - If `options.all` is true, gets all the packages in scope regardless of whether they've changed
20-
* (skipping git diff of files), filtered by packages that already have change files.
21+
* (skipping git diff of files), omitting packages that already have change files.
22+
*
23+
* Usually (without `options.package`) this has the side effect of calling `ensureSharedHistory` to
24+
* verify that enough git history is available to check for changes between `HEAD` and
25+
* `options.branch` (only an issue for shallow clones), and deepens the history if needed.
26+
* Unless `options.fetch` is `false`, it will also fetch from the remote.
2127
*/
2228
export function getChangedPackages(
2329
options: BeachballOptions,
@@ -33,10 +39,10 @@ export function getChangedPackages(
3339

3440
console.log(`Checking for changes against "${options.branch}"`);
3541

36-
// We should fetch shared history even with --all for accurate change file checks later
37-
if (!hasCommonCommit(branch, options.path)) {
38-
ensureSharedHistory(options);
39-
}
42+
// Ensure the current branch and target branch have a common shared commit. This has the side
43+
// effect of fetching from the remote (unless disabled), which should be done even if there's
44+
// already shared history (and even with --all) for accurate added change file checks later.
45+
ensureSharedHistory(options);
4046

4147
let changedPackages: string[];
4248

packages/beachball/src/git/ensureSharedHistory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,6 @@ function isShallowRepository(cwd: string): boolean {
197197
}
198198

199199
/** Returns whether `branch` and HEAD have a common commit anywhere in their history */
200-
export function hasCommonCommit(branch: string, cwd: string): boolean {
200+
function hasCommonCommit(branch: string, cwd: string): boolean {
201201
return git(['merge-base', branch, 'HEAD'], { cwd }).success;
202202
}

0 commit comments

Comments
 (0)