mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-23 01:22:12 +03:00
7d078de52f
We want to move towards having each functional domain in a separate crate. The main benefit of that for our project is that this will enforce a unidirectional dependency graph (i.e. no cycles). Starting off with virutal_branches - a lot of the implementation is still in core (i.e. virtual.rs), that will be moved in a separate PR. Furthermore, the virtual branches controller (as well as virtual.rs) contain functions not directly related to branches (e.g. commit reordering etc). That will be furthe separate in a crate.
124 lines
3.3 KiB
Rust
124 lines
3.3 KiB
Rust
use super::*;
|
|
|
|
#[tokio::test]
|
|
async fn reorder_commit_down() {
|
|
let Test {
|
|
repository,
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let branch_id = controller
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
|
.await
|
|
.unwrap();
|
|
|
|
// create commit
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
let _commit1_id = controller
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
|
.await
|
|
.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
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
|
.await
|
|
.unwrap();
|
|
|
|
controller
|
|
.reorder_commit(project, branch_id, commit2_id, 1)
|
|
.await
|
|
.unwrap();
|
|
|
|
let branch = controller
|
|
.list_virtual_branches(project)
|
|
.await
|
|
.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"]);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn reorder_commit_up() {
|
|
let Test {
|
|
repository,
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let branch_id = controller
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
|
.await
|
|
.unwrap();
|
|
|
|
// create commit
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
let commit1_id = controller
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
|
.await
|
|
.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
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
|
.await
|
|
.unwrap();
|
|
|
|
controller
|
|
.reorder_commit(project, branch_id, commit1_id, -1)
|
|
.await
|
|
.unwrap();
|
|
|
|
let branch = controller
|
|
.list_virtual_branches(project)
|
|
.await
|
|
.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"]);
|
|
}
|