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 reorder_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
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::set_base_branch(
|
|
|
|
project,
|
|
|
|
&"refs/remotes/origin/master".parse().unwrap(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let branch_id =
|
|
|
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
|
|
|
.unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
2024-09-06 15:12:14 +03:00
|
|
|
let _commit1_id =
|
|
|
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
|
|
|
.unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
|
|
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
2024-09-06 15:12:14 +03:00
|
|
|
let commit2_id =
|
|
|
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
|
|
|
.unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::reorder_commit(project, branch_id, commit2_id, 1).unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let branch = gitbutler_branch_actions::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(), 2);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1); // this now has the 2 file changes
|
|
|
|
assert_eq!(branch.commits[1].files.len(), 2); // and this has the single file change
|
|
|
|
|
|
|
|
let descriptions = branch
|
|
|
|
.commits
|
|
|
|
.iter()
|
|
|
|
.map(|c| c.description.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
assert_eq!(descriptions, vec!["commit one", "commit two"]);
|
|
|
|
}
|
|
|
|
|
2024-07-28 21:36:55 +03:00
|
|
|
#[test]
|
|
|
|
fn reorder_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
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::set_base_branch(
|
|
|
|
project,
|
|
|
|
&"refs/remotes/origin/master".parse().unwrap(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let branch_id =
|
|
|
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
|
|
|
.unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
2024-09-06 15:12:14 +03:00
|
|
|
let commit1_id =
|
|
|
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
|
|
|
.unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
|
|
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
2024-09-06 15:12:14 +03:00
|
|
|
let _commit2_id =
|
|
|
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
|
|
|
.unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::reorder_commit(project, branch_id, commit1_id, -1).unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let branch = gitbutler_branch_actions::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(), 2);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1); // this now has the 2 file changes
|
|
|
|
assert_eq!(branch.commits[1].files.len(), 2); // and this has the single file change
|
|
|
|
|
|
|
|
let descriptions = branch
|
|
|
|
.commits
|
|
|
|
.iter()
|
|
|
|
.map(|c| c.description.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
assert_eq!(descriptions, vec!["commit one", "commit two"]);
|
|
|
|
}
|