2024-07-13 11:38:56 +03:00
|
|
|
use gitbutler_branch::BranchCreateRequest;
|
2024-04-29 16:03:01 +03:00
|
|
|
|
2024-07-28 21:48:13 +03:00
|
|
|
use super::*;
|
|
|
|
|
2024-07-28 21:36:55 +03:00
|
|
|
#[test]
|
|
|
|
fn insert_blank_commit_down() {
|
2024-04-29 16:03:01 +03:00
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-04-29 16:03:01 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch_id = controller
|
2024-07-13 11:38:56 +03:00
|
|
|
.create_virtual_branch(project, &BranchCreateRequest::default())
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
let _commit1_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
|
|
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
|
|
|
let commit2_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
|
|
|
let _commit3_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit three", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.insert_blank_commit(project, branch_id, commit2_id, 1)
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.list_virtual_branches(project)
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.into_iter()
|
|
|
|
.find(|b| b.id == branch_id)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(branch.commits.len(), 4);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1);
|
|
|
|
assert_eq!(branch.commits[1].files.len(), 2);
|
|
|
|
assert_eq!(branch.commits[2].files.len(), 0); // blank commit
|
|
|
|
|
|
|
|
let descriptions = branch
|
|
|
|
.commits
|
|
|
|
.iter()
|
|
|
|
.map(|c| c.description.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
descriptions,
|
|
|
|
vec!["commit three", "commit two", "", "commit one"]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-07-28 21:36:55 +03:00
|
|
|
#[test]
|
|
|
|
fn insert_blank_commit_up() {
|
2024-04-29 16:03:01 +03:00
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-04-29 16:03:01 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch_id = controller
|
2024-07-13 11:38:56 +03:00
|
|
|
.create_virtual_branch(project, &BranchCreateRequest::default())
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
let _commit1_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
|
|
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
|
|
|
let commit2_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
|
|
|
let _commit3_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit three", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.insert_blank_commit(project, branch_id, commit2_id, -1)
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.list_virtual_branches(project)
|
2024-04-29 16:03:01 +03:00
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.into_iter()
|
|
|
|
.find(|b| b.id == branch_id)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(branch.commits.len(), 4);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1);
|
|
|
|
assert_eq!(branch.commits[1].files.len(), 0); // blank commit
|
|
|
|
assert_eq!(branch.commits[2].files.len(), 2);
|
|
|
|
|
|
|
|
let descriptions = branch
|
|
|
|
.commits
|
|
|
|
.iter()
|
|
|
|
.map(|c| c.description.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
descriptions,
|
|
|
|
vec!["commit three", "", "commit two", "commit one"]
|
|
|
|
);
|
|
|
|
}
|