@@ -384,7 +384,7 @@ pub fn squash_index(env: &Environment) -> Result<(), PerformError> {
384
384
println ! ( "Squashing the index into a single commit." ) ;
385
385
386
386
let now = Utc :: now ( ) . format ( "%Y-%m-%d" ) ;
387
- let original_head = repo. head_oid ( ) ?;
387
+ let original_head = repo. head_oid ( ) ?. to_string ( ) ;
388
388
let msg = format ! ( "Collapse index into one commit\n \n \
389
389
390
390
Previous HEAD was {}, now on the `snapshot-{}` branch\n \n \
@@ -394,9 +394,6 @@ pub fn squash_index(env: &Environment) -> Result<(), PerformError> {
394
394
[online]: https://internals.rust-lang.org/t/cargos-crate-index-upcoming-squash-into-one-commit/8440\n \
395
395
[this issue]: https://github.com/rust-lang/crates-io-cargo-teams/issues/47", original_head, now) ;
396
396
397
- // Create a snapshot branch of current `HEAD`.
398
- repo. push ( & format ! ( "HEAD:refs/heads/snapshot-{}" , now) ) ?;
399
-
400
397
repo. squash_to_single_commit ( & msg) ?;
401
398
402
399
// Shell out to git because libgit2 does not currently support push leases
@@ -431,9 +428,15 @@ pub fn squash_index(env: &Environment) -> Result<(), PerformError> {
431
428
)
432
429
. args ( & [
433
430
"push" ,
431
+ // Both updates should succeed or fail together
432
+ "--atomic" ,
434
433
"origin" ,
435
- "HEAD:refs/heads/ master" ,
434
+ // Overwrite master, but only if it server matches the expected value
436
435
& format ! ( "--force-with-lease=refs/heads/master:{}" , original_head) ,
436
+ // The new squashed commit is pushed to master
437
+ "HEAD:refs/heads/master" ,
438
+ // The previous value of HEAD is pushed to a snapshot branch
439
+ & format ! ( "{}:refs/heads/snapshot-{}" , original_head, now) ,
437
440
] )
438
441
. output ( ) ?;
439
442
0 commit comments