@@ -53,7 +53,6 @@ void main() {
53
53
}
54
54
55
55
io.ProcessResult run (String executable, List <String > args) {
56
- print ('Running "$executable ${args .join (" " )}' );
57
56
final io.ProcessResult result = io.Process .runSync (
58
57
executable,
59
58
args,
@@ -76,7 +75,9 @@ void main() {
76
75
setUpAll (() async {
77
76
if (usePowershellOnPosix) {
78
77
final io.ProcessResult result = io.Process .runSync ('pwsh' , < String > ['--version' ]);
79
- print ('Using Powershell (${result .stdout }) on POSIX for local debugging and testing' );
78
+ print (
79
+ 'Using Powershell (${(result .stdout as String ).trim ()}) on POSIX for local debugging and testing' ,
80
+ );
80
81
}
81
82
});
82
83
@@ -104,7 +105,7 @@ void main() {
104
105
105
106
if (const LocalPlatform ().isWindows || usePowershellOnPosix) {
106
107
// Copy a minimal set of environment variables needed to run the update_engine_version script in PowerShell.
107
- const List <String > powerShellVariables = < String > ['SystemRoot ' , 'Path ' , 'PATHEXT' ];
108
+ const List <String > powerShellVariables = < String > ['SYSTEMROOT ' , 'PATH ' , 'PATHEXT' ];
108
109
for (final String key in powerShellVariables) {
109
110
final String ? value = io.Platform .environment[key];
110
111
if (value != null ) {
@@ -143,7 +144,12 @@ void main() {
143
144
executable = testRoot.binInternalLastEngineCommit.path;
144
145
args = < String > [];
145
146
}
146
- return run (executable, args).stdout as String ;
147
+ return (run (executable, args).stdout as String ).trim ();
148
+ }
149
+
150
+ /// Gets the latest commit on the current branch.
151
+ String getLastCommit () {
152
+ return (run ('git' , < String > ['rev-parse' , 'HEAD' ]).stdout as String ).trim ();
147
153
}
148
154
149
155
void writeCommit (Iterable <String > files) {
@@ -157,7 +163,12 @@ void main() {
157
163
run ('git' , < String > ['commit' , '-m' , 'Wrote ${files .length } files' ]);
158
164
}
159
165
166
+ void changeBranch ({required String newBranchName}) {
167
+ run ('git' , < String > ['checkout' , '-b' , newBranchName]);
168
+ }
169
+
160
170
test ('returns the last engine commit' , () {
171
+ changeBranch (newBranchName: 'flutter-1.2.3-candidate.0' );
161
172
writeCommit (< String > ['DEPS' , 'engine/README.md' ]);
162
173
163
174
final String lastEngine = getLastEngineCommit ();
@@ -168,6 +179,7 @@ void main() {
168
179
});
169
180
170
181
test ('considers DEPS an engine change' , () {
182
+ changeBranch (newBranchName: 'flutter-1.2.3-candidate.0' );
171
183
writeCommit (< String > ['DEPS' , 'engine/README.md' ]);
172
184
173
185
final String lastEngineA = getLastEngineCommit ();
@@ -177,6 +189,40 @@ void main() {
177
189
final String lastEngineB = getLastEngineCommit ();
178
190
expect (lastEngineB, allOf (isNotEmpty, isNot (equals (lastEngineA))));
179
191
});
192
+
193
+ test ('if there have been no engine changes, uses the first commit since the branch point' , () {
194
+ final String initialStartingCommit = getLastCommit ();
195
+
196
+ // Make an engine change *before* the branch.
197
+ writeCommit (< String > ['engine/README.md' ]);
198
+ final String engineCommitPreBranch = getLastCommit ();
199
+ changeBranch (newBranchName: 'flutter-1.2.3-candidate.0' );
200
+
201
+ // Make a non-engine change, but no engine changes, after branching.
202
+ writeCommit (< String > ['bin/internal/release-candidate-branch.version' ]);
203
+ final String initialBranchCommit = getLastCommit ();
204
+
205
+ // Write another commit to make sure we don't always use the latest.
206
+ writeCommit (< String > ['CHANGELOG.md' ]);
207
+ final String latestCommitIgnore = getLastCommit ();
208
+
209
+ // Get the engine commit, which should fallback to HEAD~2 (in this case).
210
+ final String lastCommitToEngine = getLastEngineCommit ();
211
+ expect (
212
+ lastCommitToEngine,
213
+ initialBranchCommit,
214
+ reason:
215
+ 'The git history for this simulation looks like this:\n '
216
+ 'master (intial commit) | $initialStartingCommit \n '
217
+ 'master (touches engine) | $engineCommitPreBranch \n '
218
+ 'flutter-1.2.3-candidate.0 | $initialBranchCommit \n '
219
+ 'flutter-1.2.3-candidate.0 | $latestCommitIgnore \n '
220
+ '\n '
221
+ 'We expected our script to select HEAD~2, $initialBranchCommit , but '
222
+ 'instead it selected $lastCommitToEngine , which is incorrect. See '
223
+ 'the table above to help debug.' ,
224
+ );
225
+ });
180
226
}
181
227
182
228
extension on File {
0 commit comments