@@ -137,7 +137,7 @@ This updates the rust-version file to {upstream_sha}."#,
137137 } ;
138138 let num_roots_before = num_roots ( ) ?;
139139
140- let sha = get_current_head_sha ( ) ?;
140+ let sha_pre_merge = get_current_head_sha ( ) ?;
141141
142142 // The filtered SHA of upstream
143143 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.
169169 ] )
170170 . context ( "FAILED to merge new commits, something went wrong" ) ?;
171171
172+ // Now detect if something has actually been pulled
172173 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 {
174177 eprintln ! (
175178 "No merge was performed, no changes to pull were found. Rolling back the preparation commit."
176179 ) ;
177180 return Err ( RustcPullError :: NothingToPull ) ;
178181 }
179182
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+
180192 git_reset. disarm ( ) ;
181193
182194 // Check that the number of roots did not change.
0 commit comments