2024-03-31 00:25:36 +03:00
|
|
|
use std::fs;
|
2024-03-30 21:41:45 +03:00
|
|
|
|
2024-07-09 01:10:55 +03:00
|
|
|
use gitbutler_branch::{branch::BranchCreateRequest, ownership::BranchOwnershipClaims};
|
2024-03-31 00:27:56 +03:00
|
|
|
|
2024-07-07 14:32:35 +03:00
|
|
|
use super::Test;
|
2024-03-31 00:27:56 +03:00
|
|
|
|
2024-03-29 12:04:26 +03:00
|
|
|
#[tokio::test]
|
|
|
|
async fn should_unapply_with_commits() {
|
|
|
|
let Test {
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
repository,
|
|
|
|
..
|
|
|
|
} = &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();
|
|
|
|
|
|
|
|
let branch_id = controller
|
2024-07-09 01:10:55 +03:00
|
|
|
.create_virtual_branch(project, &BranchCreateRequest::default())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
fs::write(
|
|
|
|
repository.path().join("file.txt"),
|
|
|
|
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "test", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// change in the committed hunks leads to hunk locking
|
|
|
|
fs::write(
|
|
|
|
repository.path().join("file.txt"),
|
|
|
|
"_\n2\n3\n4\n5\n6\n7\n8\n9\n_\n",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
controller
|
|
|
|
.unapply_ownership(
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
&"file.txt:1-5,7-11"
|
|
|
|
.parse::<BranchOwnershipClaims>()
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
.await
|
2024-04-19 21:53:10 +03:00
|
|
|
.unwrap_or_else(|err| panic!("{err:?}"));
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
let branch = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.list_virtual_branches(project)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.into_iter()
|
|
|
|
.find(|b| b.id == branch_id)
|
|
|
|
.unwrap();
|
|
|
|
assert!(branch.files.is_empty());
|
|
|
|
}
|