From d41ccd74a8736246e5d78ee7786bcf76ebb53bd1 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 24 Nov 2022 10:42:20 -0800 Subject: [PATCH] git: add test for exporting refs that fail This adds a test for attempting to export both a branch called `main` and one called `main/sub` (#493), as well as for exporting a branch with an empty string as name (reported directly to me by @lkorinth). --- lib/tests/test_git.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/tests/test_git.rs b/lib/tests/test_git.rs index 59ab9bfc2f..d1259fbd75 100644 --- a/lib/tests/test_git.rs +++ b/lib/tests/test_git.rs @@ -699,6 +699,42 @@ fn test_export_conflicts() { ); } +#[test] +fn test_export_partial_failure() { + // Check that we skip branches that fail to export + let test_data = GitRepoData::create(); + let git_repo = test_data.git_repo; + let mut tx = test_data + .repo + .start_transaction(&test_data.settings, "test"); + let mut_repo = tx.mut_repo(); + let commit_a = + create_random_commit(&test_data.settings, &test_data.repo).write_to_repo(mut_repo); + let target = RefTarget::Normal(commit_a.id().clone()); + // Empty string is disallowed by Git + mut_repo.set_local_branch("".to_string(), target.clone()); + mut_repo.set_local_branch("main".to_string(), target.clone()); + // `main/sub` will conflict with `main` in Git, at least when using loose ref + // storage + mut_repo.set_local_branch("main/sub".to_string(), target); + // TODO: this should succeed + assert!(git::export_refs(mut_repo, &git_repo).is_err()); + + // The `main` branch should have succeeded but the other should have failed + assert!(git_repo.find_reference("refs/heads/").is_err()); + assert!(git_repo.find_reference("refs/heads/main").is_err()); + assert!(git_repo.find_reference("refs/heads/main/sub").is_err()); + + // Now remove the `main` branch and make sure that the `main/sub` gets exported + // even though it didn't change + // TODO: this should succeed + mut_repo.remove_local_branch("main"); + assert!(git::export_refs(mut_repo, &git_repo).is_err()); + assert!(git_repo.find_reference("refs/heads/").is_err()); + assert!(git_repo.find_reference("refs/heads/main").is_err()); + assert!(git_repo.find_reference("refs/heads/main/sub").is_err()); +} + #[test] fn test_init() { let settings = testutils::user_settings();