remove duplicated tests

This commit is contained in:
Nikita Galaiko 2023-10-12 15:14:02 +02:00 committed by GitButler
parent 93d8128301
commit 878c23c229
6 changed files with 14 additions and 233 deletions

View File

@ -37,7 +37,7 @@ pub async fn commit_virtual_branch(
branch: &str,
message: &str,
ownership: Option<Ownership>,
) -> Result<(), Error> {
) -> Result<git::Oid, Error> {
handle
.state::<Controller>()
.create_commit(project_id, branch, message, ownership.as_ref())

View File

@ -88,7 +88,7 @@ impl Controller {
branch: &str,
message: &str,
ownership: Option<&Ownership>,
) -> Result<(), Error> {
) -> Result<git::Oid, Error> {
self.with_lock(project_id, || {
self.with_verify_branch(project_id, |gb_repository, project_repository, user| {
let signing_key = if project_repository
@ -116,8 +116,7 @@ impl Controller {
.map_err(|error| match error {
super::CommitError::Conflicted => Error::Conflicting,
super::CommitError::Other(error) => Error::Other(error),
})?;
Ok(())
})
})
})
.await

View File

@ -1403,151 +1403,6 @@ fn test_merge_vbranch_upstream_clean() -> Result<()> {
Ok(())
}
#[test]
fn test_merge_vbranch_upstream_conflict() -> Result<()> {
let Case {
project_repository,
project,
gb_repository,
..
} = Suite::default().new_case();
// create a commit and set the target
let file_path = std::path::Path::new("test.txt");
std::fs::write(
std::path::Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\n",
)?;
test_utils::commit_all(&project_repository.git_repository);
let target_oid = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
std::fs::write(
std::path::Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\nupstream\n",
)?;
// add a commit to the target branch it's pointing to so there is something "upstream"
test_utils::commit_all(&project_repository.git_repository);
let last_push = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
// coworker adds some work
std::fs::write(
std::path::Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\nupstream\ncoworker work\n",
)?;
test_utils::commit_all(&project_repository.git_repository);
let coworker_work = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
//update repo ref refs/remotes/origin/master to up_target oid
project_repository.git_repository.reference(
"refs/remotes/origin/master",
coworker_work,
true,
"update target",
)?;
// revert to our file
std::fs::write(
std::path::Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\nupstream\n",
)?;
set_test_target(&gb_repository, &project_repository)?;
target::Writer::new(&gb_repository).write_default(&target::Target {
branch: "refs/remotes/origin/master".parse().unwrap(),
remote_url: "origin".to_string(),
sha: target_oid,
})?;
// add some uncommitted work
std::fs::write(
std::path::Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\nupstream\nother side\n",
)?;
let remote_branch: git::RemoteBranchName = "refs/remotes/origin/master".parse().unwrap();
let branch_writer = branch::Writer::new(&gb_repository);
let mut branch = create_virtual_branch(&gb_repository, &BranchCreateRequest::default())
.expect("failed to create virtual branch");
branch.upstream = Some(remote_branch.clone());
branch.head = last_push;
branch_writer
.write(&branch)
.context("failed to write target branch after push")?;
// create the branch
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
let branch1 = &branches[0];
assert_eq!(branch1.files.len(), 1);
assert_eq!(branch1.commits.len(), 1);
assert_eq!(branch1.upstream_commits.len(), 1);
merge_virtual_branch_upstream(&gb_repository, &project_repository, &branch1.id, None, None)?;
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
let branch1 = &branches[0];
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path))?;
assert_eq!(
"line1\nline2\nline3\nline4\nupstream\n<<<<<<< ours\nother side\n=======\ncoworker work\n>>>>>>> theirs\n",
String::from_utf8(contents)?
);
assert_eq!(branch1.files.len(), 1);
assert_eq!(branch1.commits.len(), 1);
assert!(branch1.conflicted);
// fix the conflict
std::fs::write(
std::path::Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\nupstream\nother side\ncoworker work\n",
)?;
// make gb see the conflict resolution
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
assert!(branches[0].conflicted);
// commit the merge resolution
commit(
&gb_repository,
&project_repository,
&branch1.id,
"fix merge conflict",
None,
None,
None,
)?;
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
let branch1 = &branches[0];
assert!(!branch1.conflicted);
assert_eq!(branch1.files.len(), 0);
assert_eq!(branch1.commits.len(), 3);
// make sure the last commit was a merge commit (2 parents)
let last_id = &branch1.commits[0].id;
let last_commit = project_repository.git_repository.find_commit(*last_id)?;
assert_eq!(last_commit.parent_count(), 2);
Ok(())
}
#[test]
fn test_update_target_with_conflicts_in_vbranches() -> Result<()> {
let Case {
@ -3767,73 +3622,6 @@ fn test_apply_out_of_date_conflicting_vbranch() -> Result<()> {
Ok(())
}
#[test]
fn test_apply_conflicting_vbranch() -> Result<()> {
let Case {
project_repository,
project,
gb_repository,
..
} = Suite::default().new_case_with_files(HashMap::from([
(
path::PathBuf::from("test.txt"),
"line1\nline2\nline3\nline4\n",
),
(path::PathBuf::from("test2.txt"), "file2\n"),
]));
set_test_target(&gb_repository, &project_repository)?;
// write new unapplied virtual branch with other changes
std::fs::write(
std::path::Path::new(&project.path).join("test.txt"),
"line1\nline2\nline3\nline4\nconflict\n",
)?;
std::fs::write(
std::path::Path::new(&project.path).join("test2.txt"),
"file2\nbranch\n",
)?;
test_utils::commit_all(&project_repository.git_repository);
let branch_commit = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
let branch_commit_obj = project_repository
.git_repository
.find_commit(branch_commit)?;
let mut branch = create_virtual_branch(&gb_repository, &BranchCreateRequest::default())
.expect("failed to create virtual branch");
branch.head = branch_commit;
branch.tree = branch_commit_obj.tree()?.id();
branch.applied = false;
let branch_id = &branch.id.clone();
let branch_writer = branch::Writer::new(&gb_repository);
branch_writer.write(&branch::Branch {
name: "Our Awesome Branch".to_string(),
ownership: Ownership {
files: vec!["test.txt:1-5".parse()?, "test2.txt:1-2".parse()?],
},
..branch
})?;
// update wd
std::fs::write(
std::path::Path::new(&project.path).join("test.txt"),
"line1\nline2\nline3\nline4\nworking\n",
)?;
// apply branch which is now out of date and conflicting, which fails
let result = apply_branch(&gb_repository, &project_repository, branch_id, None, None);
assert!(result.is_err());
Ok(())
}
#[test]
fn test_verify_branch_commits_to_integration() -> Result<()> {
let Case {

View File

@ -1889,7 +1889,7 @@ pub fn commit(
ownership: Option<&branch::Ownership>,
signing_key: Option<&keys::PrivateKey>,
user: Option<&users::User>,
) -> Result<(), CommitError> {
) -> Result<git::Oid, CommitError> {
let default_target = gb_repository
.default_target()
.context("failed to get default target")?
@ -2005,7 +2005,7 @@ pub fn commit(
super::integration::update_gitbutler_integration(gb_repository, project_repository)
.context("failed to update gitbutler integration")?;
Ok(())
Ok(commit_oid)
}
pub fn name_to_branch(name: &str) -> String {

View File

@ -8,7 +8,6 @@ pub fn temp_dir() -> std::path::PathBuf {
pub struct TestProject {
local_repository: git::Repository,
remote_repository: git::Repository,
}
impl Default for TestProject {
@ -51,10 +50,7 @@ impl Default for TestProject {
.expect("failed to push");
}
Self {
local_repository,
remote_repository,
}
Self { local_repository }
}
}
@ -63,13 +59,6 @@ impl TestProject {
self.local_repository.workdir().unwrap()
}
pub fn fetch(&self) {
let mut origin = self.local_repository.find_remote("origin").unwrap();
origin
.fetch(&["+refs/heads/*:refs/remotes/origin/*"], None)
.unwrap();
}
pub fn push(&self) {
let mut origin = self.local_repository.find_remote("origin").unwrap();
origin
@ -84,6 +73,10 @@ impl TestProject {
.unwrap();
}
pub fn find_commit(&self, oid: git::Oid) -> Result<git::Commit, git::Error> {
self.local_repository.find_commit(oid)
}
pub fn commit_all(&self, message: &str) -> git::Oid {
let mut index = self.local_repository.index().expect("failed to get index");
index

View File

@ -126,8 +126,6 @@ mod conflicts {
}
mod remote {
use futures::TryFutureExt;
use super::*;
#[tokio::test]
@ -211,11 +209,14 @@ mod conflicts {
{
// fixing the conflict removes conflicted mark
fs::write(repository.path().join("file.txt"), "resolved").unwrap();
controller
let commit_oid = controller
.create_commit(&project_id, &branch1_id, "resolution", None)
.await
.unwrap();
let commit = repository.find_commit(commit_oid).unwrap();
assert_eq!(commit.parent_count(), 2);
let branches = controller.list_virtual_branches(&project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id);