Skip to content

Commit 850087b

Browse files
[tool] Remove use of FETCH_HEAD (#10357)
Changes the default branch used to find merge bases from `FETCH_HEAD` to `main`. We were arranging for it to be `main` in CI, and locally it was an unpredictable value, so just hard-coding to `main` is likely to give better behavior locally with no change to CI behavior. Fixes flutter/flutter#176738
1 parent 835eb31 commit 850087b

File tree

5 files changed

+6
-5
lines changed

5 files changed

+6
-5
lines changed

.ci/scripts/prepare_tool.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
# found in the LICENSE file.
55
set -e
66

7-
# To set FETCH_HEAD for "git merge-base" to work
7+
# Ensure that 'main' is present for diffing.
88
git fetch origin main
9+
git branch main origin/main
910

1011
cd script/tool
1112
dart pub get

script/tool/lib/src/common/git_version_finder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class GitVersionFinder {
1515
: assert(baseSha == null || baseBranch == null,
1616
'At most one of baseSha and baseBranch can be provided'),
1717
_baseSha = baseSha,
18-
_baseBranch = baseBranch ?? 'FETCH_HEAD';
18+
_baseBranch = baseBranch ?? 'main';
1919

2020
/// The top level directory of the git repo.
2121
///

script/tool/lib/src/common/package_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ abstract class PackageCommand extends Command<void> {
129129
argParser.addOption(_baseBranchArg,
130130
help: 'The base branch whose merge base is used as the base SHA if '
131131
'--$_baseShaArg is not provided. \n'
132-
'If not specified, FETCH_HEAD is used as the base branch.');
132+
'If not specified, "main" is used as the base branch.');
133133
argParser.addFlag(_logTimingArg,
134134
help: 'Logs timing information.\n\n'
135135
'Currently only logs per-package timing for multi-package commands, '

script/tool/test/common/git_version_finder_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ file2/file2.cc
6666
final GitVersionFinder finder = GitVersionFinder(gitDir);
6767
await finder.getChangedFiles();
6868
verify(gitDir.runCommand(
69-
<String>['merge-base', '--fork-point', 'FETCH_HEAD', 'HEAD'],
69+
<String>['merge-base', '--fork-point', 'main', 'HEAD'],
7070
throwOnError: false));
7171
verify(gitDir.runCommand(
7272
<String>['diff', '--name-only', mergeBaseResponse, 'HEAD']));

script/tool/test/version_check_command_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void main() {
150150
gitProcessRunner.recordedCalls,
151151
containsAllInOrder(const <ProcessCall>[
152152
ProcessCall('git-merge-base',
153-
<String>['--fork-point', 'FETCH_HEAD', 'HEAD'], null),
153+
<String>['--fork-point', 'main', 'HEAD'], null),
154154
ProcessCall('git-show',
155155
<String>['abc123:packages/plugin/pubspec.yaml'], null),
156156
]));

0 commit comments

Comments
 (0)