2024-10-08 16:44:59 +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 undo_commit_simple() {
|
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
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
2024-09-06 15:12:14 +03:00
|
|
|
let _commit3_id =
|
|
|
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
|
|
|
.unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::undo_commit(project, branch_id, commit2_id).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();
|
|
|
|
|
|
|
|
// should be two uncommitted files now (file2.txt and file3.txt)
|
|
|
|
assert_eq!(branch.files.len(), 2);
|
|
|
|
assert_eq!(branch.commits.len(), 2);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1);
|
|
|
|
assert_eq!(branch.commits[1].files.len(), 1);
|
|
|
|
|
|
|
|
let descriptions = branch
|
|
|
|
.commits
|
|
|
|
.iter()
|
|
|
|
.map(|c| c.description.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
assert_eq!(descriptions, vec!["commit three", "commit one"]);
|
|
|
|
}
|