@@ -137,7 +137,7 @@ This updates the rust-version file to {upstream_sha}."#,
137
137
} ;
138
138
let num_roots_before = num_roots ( ) ?;
139
139
140
- let sha = get_current_head_sha ( ) ?;
140
+ let sha_pre_merge = get_current_head_sha ( ) ?;
141
141
142
142
// The filtered SHA of upstream
143
143
let incoming_ref = run_command ( [ "git" , "rev-parse" , "FETCH_HEAD" ] ) ?;
@@ -169,14 +169,26 @@ This merge was created using https://github.com/rust-lang/josh-sync.
169
169
] )
170
170
. context ( "FAILED to merge new commits, something went wrong" ) ?;
171
171
172
+ // Now detect if something has actually been pulled
172
173
let current_sha = get_current_head_sha ( ) ?;
173
- if current_sha == sha {
174
+
175
+ // This is the easy case, no merge was performed, so we bail
176
+ if current_sha == sha_pre_merge {
174
177
eprintln ! (
175
178
"No merge was performed, no changes to pull were found. Rolling back the preparation commit."
176
179
) ;
177
180
return Err ( RustcPullError :: NothingToPull ) ;
178
181
}
179
182
183
+ // But it can be more tricky - we can have only empty merge/rollup merge commits from
184
+ // rustc, so a merge was created, but the in-tree diff can still be empty.
185
+ // In that case we also bail.
186
+ // `git diff --exit-code` "succeeds" if the diff is empty.
187
+ if run_command ( & [ "git" , "diff" , "--exit-code" , & sha_pre_merge] ) . is_ok ( ) {
188
+ eprintln ! ( "Only empty changes were pulled. Rolling back the preparation commit." ) ;
189
+ return Err ( RustcPullError :: NothingToPull ) ;
190
+ }
191
+
180
192
git_reset. disarm ( ) ;
181
193
182
194
// Check that the number of roots did not change.
0 commit comments