mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-22 09:01:45 +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.
238 lines
7.0 KiB
Rust
238 lines
7.0 KiB
Rust
use super::*;
|
|
|
|
#[tokio::test]
|
|
async fn success() {
|
|
let Test {
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
}
|
|
|
|
mod error {
|
|
use super::*;
|
|
|
|
#[tokio::test]
|
|
async fn missing() {
|
|
let Test {
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
assert_eq!(
|
|
controller
|
|
.set_base_branch(
|
|
project,
|
|
&git::RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(),
|
|
)
|
|
.await
|
|
.unwrap_err()
|
|
.to_string(),
|
|
"remote branch 'refs/remotes/origin/missing' not found"
|
|
);
|
|
}
|
|
}
|
|
|
|
mod go_back_to_integration {
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use super::*;
|
|
|
|
#[tokio::test]
|
|
async fn should_preserve_applied_vbranches() {
|
|
let Test {
|
|
repository,
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
std::fs::write(repository.path().join("file.txt"), "one").unwrap();
|
|
let oid_one = repository.commit_all("one");
|
|
std::fs::write(repository.path().join("file.txt"), "two").unwrap();
|
|
repository.commit_all("two");
|
|
repository.push();
|
|
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let vbranch_id = controller
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
|
.await
|
|
.unwrap();
|
|
|
|
std::fs::write(repository.path().join("another file.txt"), "content").unwrap();
|
|
controller
|
|
.create_commit(project, vbranch_id, "one", None, false)
|
|
.await
|
|
.unwrap();
|
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
|
assert_eq!(branches.len(), 1);
|
|
|
|
repository.checkout_commit(oid_one);
|
|
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
|
assert_eq!(branches.len(), 1);
|
|
assert_eq!(branches[0].id, vbranch_id);
|
|
assert!(branches[0].active);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn from_target_branch_index_conflicts() {
|
|
let Test {
|
|
repository,
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
std::fs::write(repository.path().join("file.txt"), "one").unwrap();
|
|
let oid_one = repository.commit_all("one");
|
|
std::fs::write(repository.path().join("file.txt"), "two").unwrap();
|
|
repository.commit_all("two");
|
|
repository.push();
|
|
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
|
assert!(branches.is_empty());
|
|
|
|
repository.checkout_commit(oid_one);
|
|
std::fs::write(repository.path().join("file.txt"), "tree").unwrap();
|
|
|
|
assert!(matches!(
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap_err()
|
|
.downcast_ref(),
|
|
Some(Marker::ProjectConflict)
|
|
));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn from_target_branch_with_uncommited() {
|
|
let Test {
|
|
repository,
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
std::fs::write(repository.path().join("file.txt"), "one").unwrap();
|
|
let oid_one = repository.commit_all("one");
|
|
std::fs::write(repository.path().join("file.txt"), "two").unwrap();
|
|
repository.commit_all("two");
|
|
repository.push();
|
|
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
|
assert!(branches.is_empty());
|
|
|
|
repository.checkout_commit(oid_one);
|
|
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
|
|
|
|
assert!(matches!(
|
|
controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap_err()
|
|
.downcast_ref(),
|
|
Some(Marker::ProjectConflict)
|
|
));
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn from_target_branch_with_commit() {
|
|
let Test {
|
|
repository,
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
std::fs::write(repository.path().join("file.txt"), "one").unwrap();
|
|
let oid_one = repository.commit_all("one");
|
|
std::fs::write(repository.path().join("file.txt"), "two").unwrap();
|
|
repository.commit_all("two");
|
|
repository.push();
|
|
|
|
let base = controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
|
assert!(branches.is_empty());
|
|
|
|
repository.checkout_commit(oid_one);
|
|
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
|
|
repository.commit_all("three");
|
|
|
|
let base_two = controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
|
assert_eq!(branches.len(), 0);
|
|
assert_eq!(base_two, base);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn from_target_branch_without_any_changes() {
|
|
let Test {
|
|
repository,
|
|
project,
|
|
controller,
|
|
..
|
|
} = &Test::default();
|
|
|
|
std::fs::write(repository.path().join("file.txt"), "one").unwrap();
|
|
let oid_one = repository.commit_all("one");
|
|
std::fs::write(repository.path().join("file.txt"), "two").unwrap();
|
|
repository.commit_all("two");
|
|
repository.push();
|
|
|
|
let base = controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
|
assert!(branches.is_empty());
|
|
|
|
repository.checkout_commit(oid_one);
|
|
|
|
let base_two = controller
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
.await
|
|
.unwrap();
|
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
|
assert_eq!(branches.len(), 0);
|
|
assert_eq!(base_two, base);
|
|
}
|
|
}
|