2024-03-29 12:04:26 +03:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn forcepush_allowed() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
|
|
|
project_id,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
projects,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
projects
|
|
|
|
.update(&projects::UpdateRequest {
|
|
|
|
id: *project_id,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
projects
|
|
|
|
.update(&projects::UpdateRequest {
|
|
|
|
id: *project_id,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-04-29 16:03:01 +03:00
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
let commit_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.push_virtual_branch(project, branch_id, false, None)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
{
|
|
|
|
// amend another hunk
|
|
|
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
|
|
|
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.amend(project, branch_id, commit_id, &to_amend)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
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.requires_force);
|
|
|
|
assert_eq!(branch.commits.len(), 1);
|
|
|
|
assert_eq!(branch.files.len(), 0);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn forcepush_forbidden() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
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();
|
|
|
|
|
2024-06-26 11:23:31 +03:00
|
|
|
let branch_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-06-26 11:23:31 +03:00
|
|
|
controller
|
|
|
|
.update_virtual_branch(
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-06-26 11:23:31 +03:00
|
|
|
branch::BranchUpdateRequest {
|
|
|
|
id: branch_id,
|
|
|
|
allow_rebasing: Some(false),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-04-29 16:03:01 +03:00
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
let commit_oid = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.push_virtual_branch(project, branch_id, false, None)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
|
|
|
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
2024-05-31 10:39:29 +03:00
|
|
|
assert_eq!(
|
2024-03-29 12:04:26 +03:00
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.amend(project, branch_id, commit_oid, &to_amend)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
2024-03-31 22:52:56 +03:00
|
|
|
.unwrap_err()
|
2024-05-31 10:39:29 +03:00
|
|
|
.to_string(),
|
|
|
|
"force-push is not allowed"
|
|
|
|
);
|
2024-03-29 12:04:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn non_locked_hunk() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
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();
|
|
|
|
|
|
|
|
let branch_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-04-29 16:03:01 +03:00
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
let commit_oid = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-04-29 16:03:01 +03:00
|
|
|
let branch = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.list_virtual_branches(project)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.into_iter()
|
|
|
|
.find(|b| b.id == branch_id)
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(branch.commits.len(), 1);
|
|
|
|
assert_eq!(branch.files.len(), 0);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1);
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
// amend another hunk
|
|
|
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
|
|
|
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.amend(project, branch_id, commit_oid, &to_amend)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
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_eq!(branch.commits.len(), 1);
|
|
|
|
assert_eq!(branch.files.len(), 0);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn locked_hunk() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
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();
|
|
|
|
|
|
|
|
let branch_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-04-29 16:03:01 +03:00
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
let commit_oid = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-04-29 16:03:01 +03:00
|
|
|
let branch = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.list_virtual_branches(project)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.into_iter()
|
|
|
|
.find(|b| b.id == branch_id)
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(branch.commits.len(), 1);
|
|
|
|
assert_eq!(branch.files.len(), 0);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1);
|
|
|
|
assert_eq!(
|
|
|
|
branch.commits[0].files[0].hunks[0].diff,
|
|
|
|
"@@ -0,0 +1 @@\n+content\n\\ No newline at end of file\n"
|
|
|
|
);
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
// amend another hunk
|
|
|
|
fs::write(repository.path().join("file.txt"), "more content").unwrap();
|
|
|
|
let to_amend: branch::BranchOwnershipClaims = "file.txt:1-2".parse().unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.amend(project, branch_id, commit_oid, &to_amend)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
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_eq!(branch.commits.len(), 1);
|
|
|
|
assert_eq!(branch.files.len(), 0);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1);
|
|
|
|
assert_eq!(
|
|
|
|
branch.commits[0].files[0].hunks[0].diff,
|
|
|
|
"@@ -0,0 +1 @@\n+more content\n\\ No newline at end of file\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn non_existing_ownership() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
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();
|
|
|
|
|
|
|
|
let branch_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-04-29 16:03:01 +03:00
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
let commit_oid = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-04-29 16:03:01 +03:00
|
|
|
let branch = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.list_virtual_branches(project)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.into_iter()
|
|
|
|
.find(|b| b.id == branch_id)
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(branch.commits.len(), 1);
|
|
|
|
assert_eq!(branch.files.len(), 0);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1);
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
// amend non existing hunk
|
|
|
|
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
2024-05-31 10:39:29 +03:00
|
|
|
assert_eq!(
|
2024-03-29 12:04:26 +03:00
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.amend(project, branch_id, commit_oid, &to_amend)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
2024-03-31 22:52:56 +03:00
|
|
|
.unwrap_err()
|
2024-05-31 10:39:29 +03:00
|
|
|
.to_string(),
|
|
|
|
"target ownership not found"
|
|
|
|
);
|
2024-03-29 12:04:26 +03:00
|
|
|
}
|
|
|
|
}
|