2024-03-29 12:04:26 +03:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn head() {
|
|
|
|
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();
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit three", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
let commit_four_oid = {
|
|
|
|
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit four", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.squash(project, branch_id, commit_four_oid)
|
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();
|
|
|
|
|
|
|
|
let descriptions = branch
|
|
|
|
.commits
|
|
|
|
.iter()
|
|
|
|
.map(|c| c.description.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert_eq!(
|
|
|
|
descriptions,
|
|
|
|
vec!["commit three\ncommit four", "commit two", "commit one"]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn middle() {
|
|
|
|
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();
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
let commit_two_oid = {
|
|
|
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit three", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit four", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.squash(project, branch_id, commit_two_oid)
|
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();
|
|
|
|
|
|
|
|
let descriptions = branch
|
|
|
|
.commits
|
|
|
|
.iter()
|
|
|
|
.map(|c| c.description.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert_eq!(
|
|
|
|
descriptions,
|
|
|
|
vec!["commit four", "commit three", "commit one\ncommit two"]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
let commit_two_oid = {
|
|
|
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit three", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit four", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.squash(project, branch_id, commit_two_oid)
|
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();
|
|
|
|
|
|
|
|
let descriptions = branch
|
|
|
|
.commits
|
|
|
|
.iter()
|
|
|
|
.map(|c| c.description.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert_eq!(
|
|
|
|
descriptions,
|
|
|
|
vec!["commit four", "commit three", "commit one\ncommit two"]
|
|
|
|
);
|
|
|
|
assert!(branch.requires_force);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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();
|
|
|
|
|
|
|
|
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()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-03-29 12:04:26 +03:00
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
let commit_two_oid = {
|
|
|
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit three", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit four", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
2024-05-31 11:03:22 +03:00
|
|
|
assert_eq!(
|
2024-03-29 12:04:26 +03:00
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.squash(project, branch_id, commit_two_oid)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
2024-03-31 22:52:56 +03:00
|
|
|
.unwrap_err()
|
2024-05-31 11:03:22 +03:00
|
|
|
.to_string(),
|
|
|
|
"force push not allowed"
|
|
|
|
);
|
2024-03-29 12:04:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
2024-05-31 11:03:22 +03:00
|
|
|
async fn root_forbidden() {
|
2024-03-29 12:04:26 +03:00
|
|
|
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();
|
|
|
|
|
|
|
|
let commit_one_oid = {
|
|
|
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit one", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
2024-05-31 11:03:22 +03:00
|
|
|
assert_eq!(
|
2024-03-29 12:04:26 +03:00
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.squash(project, branch_id, commit_one_oid)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
2024-03-31 22:52:56 +03:00
|
|
|
.unwrap_err()
|
2024-05-31 11:03:22 +03:00
|
|
|
.to_string(),
|
|
|
|
"can not squash root commit"
|
|
|
|
);
|
2024-03-29 12:04:26 +03:00
|
|
|
}
|