2024-03-29 12:04:26 +03:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn success() {
|
|
|
|
let Test {
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
mod error {
|
2024-07-09 02:14:28 +03:00
|
|
|
use gitbutler_reference::RemoteRefname;
|
|
|
|
|
2024-03-29 12:04:26 +03:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn missing() {
|
|
|
|
let Test {
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
2024-05-30 18:07:52 +03:00
|
|
|
assert_eq!(
|
2024-03-29 12:04:26 +03:00
|
|
|
controller
|
|
|
|
.set_base_branch(
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-07-09 02:14:28 +03:00
|
|
|
&RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(),
|
2024-03-29 12:04:26 +03:00
|
|
|
)
|
|
|
|
.await
|
2024-03-31 22:52:56 +03:00
|
|
|
.unwrap_err()
|
2024-05-30 18:07:52 +03:00
|
|
|
.to_string(),
|
|
|
|
"remote branch 'refs/remotes/origin/missing' not found"
|
|
|
|
);
|
2024-03-29 12:04:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod go_back_to_integration {
|
|
|
|
use super::*;
|
2024-07-13 11:38:56 +03:00
|
|
|
use gitbutler_branch::BranchCreateRequest;
|
|
|
|
use pretty_assertions::assert_eq;
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn should_preserve_applied_vbranches() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
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
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let vbranch_id = controller
|
2024-07-13 11:38:56 +03:00
|
|
|
.create_virtual_branch(project, &BranchCreateRequest::default())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
std::fs::write(repository.path().join("another file.txt"), "content").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, vbranch_id, "one", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(branches.len(), 1);
|
|
|
|
|
|
|
|
repository.checkout_commit(oid_one);
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
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,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
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
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert!(branches.is_empty());
|
|
|
|
|
|
|
|
repository.checkout_commit(oid_one);
|
|
|
|
std::fs::write(repository.path().join("file.txt"), "tree").unwrap();
|
|
|
|
|
|
|
|
assert!(matches!(
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
2024-03-31 22:52:56 +03:00
|
|
|
.unwrap_err()
|
|
|
|
.downcast_ref(),
|
2024-05-31 16:46:04 +03:00
|
|
|
Some(Marker::ProjectConflict)
|
2024-03-29 12:04:26 +03:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn from_target_branch_with_uncommited() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
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
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert!(branches.is_empty());
|
|
|
|
|
|
|
|
repository.checkout_commit(oid_one);
|
|
|
|
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
|
|
|
|
|
|
|
|
assert!(matches!(
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
2024-03-31 22:52:56 +03:00
|
|
|
.unwrap_err()
|
|
|
|
.downcast_ref(),
|
2024-05-31 16:46:04 +03:00
|
|
|
Some(Marker::ProjectConflict)
|
2024-03-29 12:04:26 +03:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn from_target_branch_with_commit() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
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
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
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
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(branches.len(), 0);
|
|
|
|
assert_eq!(base_two, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn from_target_branch_without_any_changes() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
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
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert!(branches.is_empty());
|
|
|
|
|
|
|
|
repository.checkout_commit(oid_one);
|
|
|
|
|
|
|
|
let base_two = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(branches.len(), 0);
|
|
|
|
assert_eq!(base_two, base);
|
|
|
|
}
|
|
|
|
}
|