Skip to content

Commit b0aec36

Browse files
author
Stephan Dilly
committed
actually commit the temp files for flaky/failing unittest (#535)
* actually commit the temp files (#534) * make check for commit id more explicit * fix last assert checking against wrong id
1 parent ac2f652 commit b0aec36

File tree

1 file changed

+65
-54
lines changed

1 file changed

+65
-54
lines changed

Diff for: asyncgit/src/sync/remotes.rs

+65-54
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,12 @@ fn remote_callbacks<'a>(
260260
#[cfg(test)]
261261
mod tests {
262262
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};
264269
use tempfile::TempDir;
265270

266271
#[test]
@@ -315,13 +320,6 @@ mod tests {
315320

316321
#[test]
317322
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-
325323
// This test mimics the scenario of 2 people having 2
326324
// local branches and both modifying the same file then
327325
// both pushing, sequentially
@@ -349,7 +347,7 @@ mod tests {
349347
File::create(tmp_repo_file_path).unwrap();
350348
writeln!(tmp_repo_file, "TempSomething").unwrap();
351349

352-
commit(
350+
sync::commit(
353351
tmp_repo_dir.path().to_str().unwrap(),
354352
"repo_1_commit",
355353
)
@@ -371,7 +369,7 @@ mod tests {
371369
File::create(tmp_other_repo_file_path).unwrap();
372370
writeln!(tmp_other_repo_file, "TempElse").unwrap();
373371

374-
commit(
372+
sync::commit(
375373
tmp_other_repo_dir.path().to_str().unwrap(),
376374
"repo_2_commit",
377375
)
@@ -409,16 +407,7 @@ mod tests {
409407
}
410408

411409
#[test]
412-
#[ignore]
413410
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-
422411
// This test mimics the scenario of 2 people having 2
423412
// local branches and both modifying the same file then
424413
// both pushing, sequentially
@@ -446,14 +435,32 @@ mod tests {
446435
File::create(tmp_repo_file_path).unwrap();
447436
writeln!(tmp_repo_file, "TempSomething").unwrap();
448437

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(
450445
tmp_repo_dir.path().to_str().unwrap(),
451446
"repo_1_commit",
452447
)
453448
.unwrap();
454449

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+
455461
let mut repo_commit_ids = Vec::<CommitId>::new();
456462
LogWalker::new(&repo).read(&mut repo_commit_ids, 1).unwrap();
463+
assert_eq!(repo_commit_ids.contains(&repo_1_commit), true);
457464

458465
push(
459466
tmp_repo_dir.path().to_str().unwrap(),
@@ -465,29 +472,40 @@ mod tests {
465472
)
466473
.unwrap();
467474

468-
let upstream_parent = upstream
469-
.find_commit((repo_commit_ids[0]).into())
470-
.unwrap()
471-
.parents()
472-
.next()
473-
.unwrap()
474-
.id();
475-
476475
let tmp_other_repo_file_path =
477476
tmp_other_repo_dir.path().join("temp_file.txt");
478477
let mut tmp_other_repo_file =
479478
File::create(tmp_other_repo_file_path).unwrap();
480479
writeln!(tmp_other_repo_file, "TempElse").unwrap();
481480

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(
483488
tmp_other_repo_dir.path().to_str().unwrap(),
484489
"repo_2_commit",
485490
)
486491
.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+
487501
let mut other_repo_commit_ids = Vec::<CommitId>::new();
488502
LogWalker::new(&other_repo)
489503
.read(&mut other_repo_commit_ids, 1)
490504
.unwrap();
505+
assert_eq!(
506+
other_repo_commit_ids.contains(&repo_2_commit),
507+
true
508+
);
491509

492510
// Attempt a normal push,
493511
// should fail as branches diverged
@@ -508,42 +526,35 @@ mod tests {
508526
// a normal push would not rewrite history
509527
let mut commit_ids = Vec::<CommitId>::new();
510528
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);
512530

513531
// Attempt force push,
514532
// 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();
527543

528544
commit_ids.clear();
529545
LogWalker::new(&upstream).read(&mut commit_ids, 1).unwrap();
530-
531546
// 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);
536548

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())
540553
.unwrap()
541554
.parents()
542555
.next()
543556
.unwrap()
544-
.id()
545-
== upstream_parent,
546-
true
547-
);
557+
.id();
558+
assert_eq!(new_upstream_parent, repo_2_parent,);
548559
}
549560
}

0 commit comments

Comments
 (0)