@@ -114,8 +114,21 @@ void main() {
114
114
return run (executable, args);
115
115
}
116
116
117
+ /// Sets up and fetches a [remote] (such as `upstream` or `origin` ) for [testRoot.root] .
118
+ ///
119
+ /// The remote points at itself (`testRoot.root.path` ) for ease of testing.
120
+ void setupRemote ({required String remote, String ? rootPath}) {
121
+ run ('git' , < String > [
122
+ 'remote' ,
123
+ 'add' ,
124
+ remote,
125
+ rootPath ?? testRoot.root.path,
126
+ ], workingPath: rootPath);
127
+ run ('git' , < String > ['fetch' , remote], workingPath: rootPath);
128
+ }
129
+
117
130
/// Initializes a blank git repo in [testRoot.root] .
118
- void initGitRepoWithBlankInitialCommit ({String ? workingPath}) {
131
+ void initGitRepoWithBlankInitialCommit ({String ? workingPath, String remote = 'upstream' }) {
119
132
run ('git' , < String > ['init' , '--initial-branch' , 'master' ], workingPath: workingPath);
120
133
// autocrlf is very important for tests to work on windows.
121
134
run ('git' , 'config --local core.autocrlf true' .split (' ' ), workingPath: workingPath);
@@ -133,6 +146,8 @@ void main() {
133
146
'-m' ,
134
147
'Initial commit' ,
135
148
], workingPath: workingPath);
149
+
150
+ setupRemote (remote: remote, rootPath: workingPath);
136
151
}
137
152
138
153
void writeFileAndCommit (File file, String contents) {
@@ -141,11 +156,58 @@ void main() {
141
156
run ('git' , < String > ['commit' , '--all' , '-m' , 'changed ${file .basename } to $contents ' ]);
142
157
}
143
158
159
+ void gitSwitchBranch (String branch, {bool create = true }) {
160
+ run ('git' , < String > ['switch' , if (create) '-c' , branch]);
161
+ }
162
+
144
163
test ('generates a hash' , () async {
145
164
initGitRepoWithBlankInitialCommit ();
146
165
expect (runContentAwareHash (), processStdout ('3bbeb6a394378478683ece4f8e8663c42f8dc814' ));
147
166
});
148
167
168
+ test ('generates a hash for origin' , () {
169
+ initGitRepoWithBlankInitialCommit (remote: 'origin' );
170
+ expect (runContentAwareHash (), processStdout ('3bbeb6a394378478683ece4f8e8663c42f8dc814' ));
171
+ });
172
+
173
+ group ('ignores local engine for' , () {
174
+ test ('upstream' , () {
175
+ initGitRepoWithBlankInitialCommit ();
176
+ gitSwitchBranch ('engineTest' );
177
+ testRoot.deps.writeAsStringSync ('deps changed' );
178
+ expect (
179
+ runContentAwareHash (),
180
+ processStdout ('3bbeb6a394378478683ece4f8e8663c42f8dc814' ),
181
+ reason: 'content hash from master for non-committed file' ,
182
+ );
183
+
184
+ writeFileAndCommit (testRoot.deps, 'deps changed' );
185
+ expect (
186
+ runContentAwareHash (),
187
+ processStdout ('3bbeb6a394378478683ece4f8e8663c42f8dc814' ),
188
+ reason: 'content hash from master for committed file' ,
189
+ );
190
+ });
191
+
192
+ test ('origin' , () {
193
+ initGitRepoWithBlankInitialCommit (remote: 'origin' );
194
+ gitSwitchBranch ('engineTest' );
195
+ testRoot.deps.writeAsStringSync ('deps changed' );
196
+ expect (
197
+ runContentAwareHash (),
198
+ processStdout ('3bbeb6a394378478683ece4f8e8663c42f8dc814' ),
199
+ reason: 'content hash from master for non-committed file' ,
200
+ );
201
+
202
+ writeFileAndCommit (testRoot.deps, 'deps changed' );
203
+ expect (
204
+ runContentAwareHash (),
205
+ processStdout ('3bbeb6a394378478683ece4f8e8663c42f8dc814' ),
206
+ reason: 'content hash from master for committed file' ,
207
+ );
208
+ });
209
+ });
210
+
149
211
group ('generates a different hash when' , () {
150
212
setUp (() {
151
213
initGitRepoWithBlankInitialCommit ();
0 commit comments