mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-21 16:41:32 +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.
150 lines
4.2 KiB
Rust
150 lines
4.2 KiB
Rust
use super::*;
|
|
|
|
#[tokio::test]
|
|
async fn detect_upstream_commits() {
|
|
let Test {
|
|
repository,
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let branch1_id = controller
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
|
.await
|
|
.unwrap();
|
|
|
|
let oid1 = {
|
|
// create first commit
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
controller
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
|
.await
|
|
.unwrap()
|
|
};
|
|
|
|
let oid2 = {
|
|
// create second commit
|
|
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
|
controller
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
|
.await
|
|
.unwrap()
|
|
};
|
|
|
|
// push
|
|
controller
|
|
.push_virtual_branch(project, branch1_id, false, None)
|
|
.await
|
|
.unwrap();
|
|
|
|
let oid3 = {
|
|
// create third commit
|
|
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
|
controller
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
|
.await
|
|
.unwrap()
|
|
};
|
|
|
|
{
|
|
// should correctly detect pushed commits
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
|
assert_eq!(branches.len(), 1);
|
|
assert_eq!(branches[0].id, branch1_id);
|
|
assert_eq!(branches[0].commits.len(), 3);
|
|
assert_eq!(branches[0].commits[0].id, oid3);
|
|
assert!(!branches[0].commits[0].is_remote);
|
|
assert_eq!(branches[0].commits[1].id, oid2);
|
|
assert!(branches[0].commits[1].is_remote);
|
|
assert_eq!(branches[0].commits[2].id, oid1);
|
|
assert!(branches[0].commits[2].is_remote);
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn detect_integrated_commits() {
|
|
let Test {
|
|
repository,
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let branch1_id = controller
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
|
.await
|
|
.unwrap();
|
|
|
|
let oid1 = {
|
|
// create first commit
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
controller
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
|
.await
|
|
.unwrap()
|
|
};
|
|
|
|
let oid2 = {
|
|
// create second commit
|
|
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
|
controller
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
|
.await
|
|
.unwrap()
|
|
};
|
|
|
|
// push
|
|
controller
|
|
.push_virtual_branch(project, branch1_id, false, None)
|
|
.await
|
|
.unwrap();
|
|
|
|
{
|
|
// merge branch upstream
|
|
let branch = controller
|
|
.list_virtual_branches(project)
|
|
.await
|
|
.unwrap()
|
|
.0
|
|
.into_iter()
|
|
.find(|b| b.id == branch1_id)
|
|
.unwrap();
|
|
repository.merge(&branch.upstream.as_ref().unwrap().name);
|
|
repository.fetch();
|
|
}
|
|
|
|
let oid3 = {
|
|
// create third commit
|
|
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
|
controller
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
|
.await
|
|
.unwrap()
|
|
};
|
|
|
|
{
|
|
// should correctly detect pushed commits
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
|
assert_eq!(branches.len(), 1);
|
|
assert_eq!(branches[0].id, branch1_id);
|
|
assert_eq!(branches[0].commits.len(), 3);
|
|
assert_eq!(branches[0].commits[0].id, oid3);
|
|
assert!(!branches[0].commits[0].is_integrated);
|
|
assert_eq!(branches[0].commits[1].id, oid2);
|
|
assert!(branches[0].commits[1].is_integrated);
|
|
assert_eq!(branches[0].commits[2].id, oid1);
|
|
assert!(branches[0].commits[2].is_integrated);
|
|
}
|
|
}
|