@@ -260,7 +260,12 @@ fn remote_callbacks<'a>(
260
260
#[ cfg( test) ]
261
261
mod tests {
262
262
use super :: * ;
263
- use crate :: sync:: tests:: debug_cmd_print;
263
+ use crate :: sync:: {
264
+ self ,
265
+ tests:: { debug_cmd_print, repo_init, repo_init_bare} ,
266
+ LogWalker ,
267
+ } ;
268
+ use std:: { fs:: File , io:: Write , path:: Path } ;
264
269
use tempfile:: TempDir ;
265
270
266
271
#[ test]
@@ -315,13 +320,6 @@ mod tests {
315
320
316
321
#[ test]
317
322
fn test_force_push ( ) {
318
- use super :: push;
319
- use std:: fs:: File ;
320
- use std:: io:: Write ;
321
-
322
- use crate :: sync:: commit:: commit;
323
- use crate :: sync:: tests:: { repo_init, repo_init_bare} ;
324
-
325
323
// This test mimics the scenario of 2 people having 2
326
324
// local branches and both modifying the same file then
327
325
// both pushing, sequentially
@@ -349,7 +347,7 @@ mod tests {
349
347
File :: create ( tmp_repo_file_path) . unwrap ( ) ;
350
348
writeln ! ( tmp_repo_file, "TempSomething" ) . unwrap ( ) ;
351
349
352
- commit (
350
+ sync :: commit (
353
351
tmp_repo_dir. path ( ) . to_str ( ) . unwrap ( ) ,
354
352
"repo_1_commit" ,
355
353
)
@@ -371,7 +369,7 @@ mod tests {
371
369
File :: create ( tmp_other_repo_file_path) . unwrap ( ) ;
372
370
writeln ! ( tmp_other_repo_file, "TempElse" ) . unwrap ( ) ;
373
371
374
- commit (
372
+ sync :: commit (
375
373
tmp_other_repo_dir. path ( ) . to_str ( ) . unwrap ( ) ,
376
374
"repo_2_commit" ,
377
375
)
@@ -409,16 +407,7 @@ mod tests {
409
407
}
410
408
411
409
#[ test]
412
- #[ ignore]
413
410
fn test_force_push_rewrites_history ( ) {
414
- use super :: push;
415
- use std:: fs:: File ;
416
- use std:: io:: Write ;
417
-
418
- use crate :: sync:: commit:: commit;
419
- use crate :: sync:: tests:: { repo_init, repo_init_bare} ;
420
- use crate :: sync:: LogWalker ;
421
-
422
411
// This test mimics the scenario of 2 people having 2
423
412
// local branches and both modifying the same file then
424
413
// both pushing, sequentially
@@ -446,14 +435,32 @@ mod tests {
446
435
File :: create ( tmp_repo_file_path) . unwrap ( ) ;
447
436
writeln ! ( tmp_repo_file, "TempSomething" ) . unwrap ( ) ;
448
437
449
- commit (
438
+ sync:: stage_add_file (
439
+ tmp_repo_dir. path ( ) . to_str ( ) . unwrap ( ) ,
440
+ Path :: new ( "temp_file.txt" ) ,
441
+ )
442
+ . unwrap ( ) ;
443
+
444
+ let repo_1_commit = sync:: commit (
450
445
tmp_repo_dir. path ( ) . to_str ( ) . unwrap ( ) ,
451
446
"repo_1_commit" ,
452
447
)
453
448
. unwrap ( ) ;
454
449
450
+ //NOTE: make sure the commit actually contains that file
451
+ assert_eq ! (
452
+ sync:: get_commit_files(
453
+ tmp_repo_dir. path( ) . to_str( ) . unwrap( ) ,
454
+ repo_1_commit
455
+ )
456
+ . unwrap( ) [ 0 ]
457
+ . path,
458
+ String :: from( "temp_file.txt" )
459
+ ) ;
460
+
455
461
let mut repo_commit_ids = Vec :: < CommitId > :: new ( ) ;
456
462
LogWalker :: new ( & repo) . read ( & mut repo_commit_ids, 1 ) . unwrap ( ) ;
463
+ assert_eq ! ( repo_commit_ids. contains( & repo_1_commit) , true ) ;
457
464
458
465
push (
459
466
tmp_repo_dir. path ( ) . to_str ( ) . unwrap ( ) ,
@@ -465,29 +472,40 @@ mod tests {
465
472
)
466
473
. unwrap ( ) ;
467
474
468
- let upstream_parent = upstream
469
- . find_commit ( ( repo_commit_ids[ 0 ] ) . into ( ) )
470
- . unwrap ( )
471
- . parents ( )
472
- . next ( )
473
- . unwrap ( )
474
- . id ( ) ;
475
-
476
475
let tmp_other_repo_file_path =
477
476
tmp_other_repo_dir. path ( ) . join ( "temp_file.txt" ) ;
478
477
let mut tmp_other_repo_file =
479
478
File :: create ( tmp_other_repo_file_path) . unwrap ( ) ;
480
479
writeln ! ( tmp_other_repo_file, "TempElse" ) . unwrap ( ) ;
481
480
482
- commit (
481
+ sync:: stage_add_file (
482
+ tmp_other_repo_dir. path ( ) . to_str ( ) . unwrap ( ) ,
483
+ Path :: new ( "temp_file.txt" ) ,
484
+ )
485
+ . unwrap ( ) ;
486
+
487
+ let repo_2_commit = sync:: commit (
483
488
tmp_other_repo_dir. path ( ) . to_str ( ) . unwrap ( ) ,
484
489
"repo_2_commit" ,
485
490
)
486
491
. unwrap ( ) ;
492
+
493
+ let repo_2_parent = other_repo
494
+ . find_commit ( repo_2_commit. into ( ) )
495
+ . unwrap ( )
496
+ . parents ( )
497
+ . next ( )
498
+ . unwrap ( )
499
+ . id ( ) ;
500
+
487
501
let mut other_repo_commit_ids = Vec :: < CommitId > :: new ( ) ;
488
502
LogWalker :: new ( & other_repo)
489
503
. read ( & mut other_repo_commit_ids, 1 )
490
504
. unwrap ( ) ;
505
+ assert_eq ! (
506
+ other_repo_commit_ids. contains( & repo_2_commit) ,
507
+ true
508
+ ) ;
491
509
492
510
// Attempt a normal push,
493
511
// should fail as branches diverged
@@ -508,42 +526,35 @@ mod tests {
508
526
// a normal push would not rewrite history
509
527
let mut commit_ids = Vec :: < CommitId > :: new ( ) ;
510
528
LogWalker :: new ( & upstream) . read ( & mut commit_ids, 1 ) . unwrap ( ) ;
511
- assert_eq ! ( commit_ids. contains( & repo_commit_ids [ 0 ] ) , true ) ;
529
+ assert_eq ! ( commit_ids. contains( & repo_1_commit ) , true ) ;
512
530
513
531
// Attempt force push,
514
532
// should work as it forces the push through
515
- assert_eq ! (
516
- push(
517
- tmp_other_repo_dir. path( ) . to_str( ) . unwrap( ) ,
518
- "origin" ,
519
- "master" ,
520
- true ,
521
- None ,
522
- None ,
523
- )
524
- . is_err( ) ,
525
- false
526
- ) ;
533
+
534
+ push (
535
+ tmp_other_repo_dir. path ( ) . to_str ( ) . unwrap ( ) ,
536
+ "origin" ,
537
+ "master" ,
538
+ true ,
539
+ None ,
540
+ None ,
541
+ )
542
+ . unwrap ( ) ;
527
543
528
544
commit_ids. clear ( ) ;
529
545
LogWalker :: new ( & upstream) . read ( & mut commit_ids, 1 ) . unwrap ( ) ;
530
-
531
546
// Check that only the other repo commit is now in upstream
532
- assert_eq ! (
533
- commit_ids. contains( & other_repo_commit_ids[ 0 ] ) ,
534
- true
535
- ) ;
547
+ assert_eq ! ( commit_ids. contains( & repo_2_commit) , true ) ;
536
548
537
- assert_eq ! (
538
- upstream
539
- . find_commit( ( commit_ids[ 0 ] ) . into( ) )
549
+ let new_upstream_parent =
550
+ Repository :: init_bare ( tmp_upstream_dir. path ( ) )
551
+ . unwrap ( )
552
+ . find_commit ( repo_2_commit. into ( ) )
540
553
. unwrap ( )
541
554
. parents ( )
542
555
. next ( )
543
556
. unwrap ( )
544
- . id( )
545
- == upstream_parent,
546
- true
547
- ) ;
557
+ . id ( ) ;
558
+ assert_eq ! ( new_upstream_parent, repo_2_parent, ) ;
548
559
}
549
560
}
0 commit comments