2024-03-29 12:04:26 +03:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
mod applied_branch {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn conflicts_with_uncommitted_work() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file.txt"), "second").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01 17:13:52 +03:00
|
|
|
{
|
2024-03-29 12:04:26 +03:00
|
|
|
// make a branch that conflicts with the remote branch, but doesn't know about it yet
|
2024-07-01 17:13:52 +03:00
|
|
|
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.txt"), "conflict").unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
}
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-07-01 17:13:52 +03:00
|
|
|
let unapplied_branch = {
|
2024-03-29 12:04:26 +03:00
|
|
|
// fetch remote
|
2024-07-04 16:26:10 +03:00
|
|
|
let unapplied_branches = controller.update_base_branch(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(unapplied_branches.len(), 1);
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-04-16 16:22:00 +03:00
|
|
|
// should stash conflicting branch
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(branches.len(), 0);
|
|
|
|
|
|
|
|
git::Refname::from_str(unapplied_branches[0].as_str()).unwrap()
|
|
|
|
};
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
// applying the branch should produce conflict markers
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch_from_branch(project, &unapplied_branch)
|
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!(branches[0].conflicted);
|
|
|
|
assert!(branches[0].base_current);
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
|
|
|
assert_eq!(
|
|
|
|
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
|
|
|
"<<<<<<< ours\nconflict\n=======\nsecond\n>>>>>>> theirs\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn commited_conflict_not_pushed() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file.txt"), "second").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01 17:13:52 +03:00
|
|
|
{
|
2024-03-29 12:04:26 +03:00
|
|
|
// make a branch with a commit that conflicts with upstream, and work that fixes
|
|
|
|
// that conflict
|
|
|
|
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.txt"), "conflict").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "conflicting commit", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
}
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-07-01 17:13:52 +03:00
|
|
|
let unapplied_branch = {
|
2024-03-29 12:04:26 +03:00
|
|
|
// when fetching remote
|
2024-07-04 16:26:10 +03:00
|
|
|
let unapplied_branches = controller.update_base_branch(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(unapplied_branches.len(), 1);
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// should stash the branch.
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(branches.len(), 0);
|
|
|
|
|
|
|
|
git::Refname::from_str(unapplied_branches[0].as_str()).unwrap()
|
|
|
|
};
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
// applying the branch should produce conflict markers
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch_from_branch(project, &unapplied_branch)
|
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!(branches[0].conflicted);
|
|
|
|
assert!(branches[0].base_current);
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(branches[0].commits.len(), 2);
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(
|
|
|
|
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
|
|
|
"<<<<<<< ours\nconflict\n=======\nsecond\n>>>>>>> theirs\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn commited_conflict_pushed() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file.txt"), "second").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01 17:13:52 +03:00
|
|
|
{
|
2024-03-29 12:04:26 +03:00
|
|
|
// make a branch with a commit that conflicts with upstream, and work that fixes
|
|
|
|
// that conflict
|
|
|
|
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.txt"), "conflict").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "conflicting commit", 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();
|
2024-07-01 17:13:52 +03:00
|
|
|
}
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-07-01 17:13:52 +03:00
|
|
|
let unapplied_branch = {
|
2024-03-29 12:04:26 +03:00
|
|
|
// when fetching remote
|
2024-07-04 16:26:10 +03:00
|
|
|
let unapplied_branches = controller.update_base_branch(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(unapplied_branches.len(), 1);
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// should stash the branch.
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(branches.len(), 0);
|
|
|
|
|
|
|
|
git::Refname::from_str(unapplied_branches[0].as_str()).unwrap()
|
|
|
|
};
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
// applying the branch should produce conflict markers
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch_from_branch(project, &unapplied_branch)
|
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!(branches[0].conflicted);
|
|
|
|
assert!(branches[0].base_current);
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(branches[0].commits.len(), 2);
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(
|
|
|
|
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
|
|
|
"<<<<<<< ours\nconflict\n=======\nsecond\n>>>>>>> theirs\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn commited_conflict_not_pushed_fixed_with_more_work() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file.txt"), "second").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01 17:13:52 +03:00
|
|
|
{
|
2024-03-29 12:04:26 +03:00
|
|
|
// make a branch with a commit that conflicts with upstream, and work that fixes
|
|
|
|
// that conflict
|
|
|
|
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.txt"), "conflict").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "conflicting commit", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
fs::write(repository.path().join("file.txt"), "fix conflict").unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
}
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-07-01 17:13:52 +03:00
|
|
|
let unapplied_branch = {
|
2024-03-29 12:04:26 +03:00
|
|
|
// when fetching remote
|
2024-07-04 16:26:10 +03:00
|
|
|
let unapplied_branches = controller.update_base_branch(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(unapplied_branches.len(), 1);
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// should rebase upstream, and leave uncommited file as is
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(branches.len(), 0);
|
|
|
|
|
|
|
|
git::Refname::from_str(unapplied_branches[0].as_str()).unwrap()
|
|
|
|
};
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
// applying the branch should produce conflict markers
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch_from_branch(project, &unapplied_branch)
|
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!(branches[0].conflicted);
|
|
|
|
assert!(branches[0].base_current);
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(branches[0].commits.len(), 2);
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(
|
|
|
|
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
|
|
|
"<<<<<<< ours\nfix conflict\n=======\nsecond\n>>>>>>> theirs\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn commited_conflict_pushed_fixed_with_more_work() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file.txt"), "second").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01 17:13:52 +03:00
|
|
|
{
|
2024-03-29 12:04:26 +03:00
|
|
|
// make a branch with a commit that conflicts with upstream, and work that fixes
|
|
|
|
// that conflict
|
|
|
|
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.txt"), "conflict").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "conflicting commit", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
fs::write(repository.path().join("file.txt"), "fix conflict").unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
}
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-07-01 17:13:52 +03:00
|
|
|
let unapplied_branch = {
|
2024-03-29 12:04:26 +03:00
|
|
|
// when fetching remote
|
2024-07-04 16:26:10 +03:00
|
|
|
let unapplied_branches = controller.update_base_branch(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(unapplied_branches.len(), 1);
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// should merge upstream, and leave uncommited file as is.
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(branches.len(), 0);
|
|
|
|
|
|
|
|
git::Refname::from_str(unapplied_branches[0].as_str()).unwrap()
|
|
|
|
};
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
// applying the branch should produce conflict markers
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch_from_branch(project, &unapplied_branch)
|
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!(branches[0].conflicted);
|
|
|
|
assert!(branches[0].base_current);
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(branches[0].commits.len(), 2);
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(
|
|
|
|
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
|
|
|
"<<<<<<< ours\nfix conflict\n=======\nsecond\n>>>>>>> theirs\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod no_conflicts_pushed {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn force_push_ok() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
project_id,
|
|
|
|
controller,
|
|
|
|
projects,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file.txt"), "second").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
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("file2.txt"), "no conflict").unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "no conflicts", 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();
|
|
|
|
|
|
|
|
fs::write(repository.path().join("file2.txt"), "still no conflict").unwrap();
|
|
|
|
|
|
|
|
branch_id
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// fetch remote
|
2024-07-04 16:26:10 +03:00
|
|
|
controller.update_base_branch(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// rebases branch, since the branch is pushed and force pushing is
|
|
|
|
// allowed
|
|
|
|
|
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, branch_id);
|
|
|
|
assert!(branches[0].active);
|
|
|
|
assert!(branches[0].requires_force);
|
|
|
|
assert!(branches[0].base_current);
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
|
|
|
assert_eq!(branches[0].commits.len(), 1);
|
|
|
|
assert!(!branches[0].commits[0].is_remote);
|
|
|
|
assert!(!branches[0].commits[0].is_integrated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn force_push_not_ok() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file.txt"), "second").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
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("file2.txt"), "no conflict").unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "no conflicts", 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();
|
|
|
|
|
|
|
|
fs::write(repository.path().join("file2.txt"), "still no conflict").unwrap();
|
|
|
|
|
|
|
|
branch_id
|
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
{
|
|
|
|
// fetch remote
|
2024-07-04 16:26:10 +03:00
|
|
|
controller.update_base_branch(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// creates a merge commit, since the branch is pushed
|
|
|
|
|
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, branch_id);
|
|
|
|
assert!(branches[0].active);
|
|
|
|
assert!(!branches[0].requires_force);
|
|
|
|
assert!(branches[0].base_current);
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
|
|
|
assert_eq!(branches[0].commits.len(), 2);
|
|
|
|
assert!(!branches[0].commits[0].is_remote);
|
|
|
|
assert!(!branches[0].commits[0].is_integrated);
|
|
|
|
assert!(branches[0].commits[1].is_remote);
|
|
|
|
assert!(!branches[0].commits[1].is_integrated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn no_conflicts() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file.txt"), "second").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
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("file2.txt"), "no conflict").unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "no conflicts", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
fs::write(repository.path().join("file2.txt"), "still no conflict").unwrap();
|
|
|
|
|
|
|
|
branch_id
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// fetch remote
|
2024-07-04 16:26:10 +03:00
|
|
|
controller.update_base_branch(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// just rebases branch
|
|
|
|
|
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, branch_id);
|
|
|
|
assert!(branches[0].active);
|
|
|
|
assert!(branches[0].base_current);
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
|
|
|
assert_eq!(branches[0].commits.len(), 1);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
|
|
|
"second"
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
std::fs::read_to_string(repository.path().join("file2.txt")).unwrap(),
|
|
|
|
"still no conflict"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn integrated_commit_plus_work() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
repository.commit_all("first");
|
|
|
|
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 branch_id = {
|
|
|
|
// make a branch that conflicts with the remote branch, but doesn't know about it yet
|
|
|
|
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.txt"), "second").unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "second", 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();
|
|
|
|
|
|
|
|
{
|
|
|
|
// merge branch upstream
|
|
|
|
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();
|
|
|
|
repository.merge(&branch.upstream.as_ref().unwrap().name);
|
|
|
|
repository.fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
// more local work in the same branch
|
|
|
|
fs::write(repository.path().join("file2.txt"), "other").unwrap();
|
|
|
|
|
|
|
|
branch_id
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// fetch remote
|
2024-07-04 16:26:10 +03:00
|
|
|
controller.update_base_branch(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// should remove integrated commit, but leave non integrated work as is
|
|
|
|
|
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, branch_id);
|
|
|
|
assert!(branches[0].active);
|
|
|
|
assert!(branches[0].base_current);
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
|
|
|
assert_eq!(branches[0].commits.len(), 0);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
|
|
|
"second"
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
std::fs::read_to_string(repository.path().join("file2.txt")).unwrap(),
|
|
|
|
"other"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn integrated_with_locked_conflicting_hunks() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(
|
|
|
|
repository.path().join("file.txt"),
|
|
|
|
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(
|
|
|
|
repository.path().join("file.txt"),
|
|
|
|
"1\n2\n3\n4\n5\n6\n17\n8\n9\n10\n11\n12\n",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// branch has no conflict
|
|
|
|
let branch_id = {
|
|
|
|
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.txt"),
|
|
|
|
"1\n2\n3\n4\n5\n6\n7\n8\n19\n10\n11\n12\n",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "fourth", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
branch_id
|
|
|
|
};
|
|
|
|
|
|
|
|
// push the branch
|
|
|
|
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();
|
|
|
|
|
2024-04-16 16:22:00 +03:00
|
|
|
// another locked conflicting hunk
|
2024-03-29 12:04:26 +03:00
|
|
|
fs::write(
|
|
|
|
repository.path().join("file.txt"),
|
|
|
|
"1\n2\n3\n4\n5\n6\n77\n8\n19\n10\n11\n12\n",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
{
|
|
|
|
// merge branch remotely
|
2024-07-04 16:26:10 +03:00
|
|
|
let branch = controller.list_virtual_branches(project).await.unwrap().0[0].clone();
|
2024-03-29 12:04:26 +03:00
|
|
|
repository.merge(&branch.upstream.as_ref().unwrap().name);
|
|
|
|
}
|
|
|
|
|
|
|
|
repository.fetch();
|
|
|
|
|
2024-07-01 17:13:52 +03:00
|
|
|
let unapplied_refname = {
|
2024-07-04 16:26:10 +03:00
|
|
|
let unapplied_refnames = controller.update_base_branch(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(unapplied_refnames.len(), 1);
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// removes integrated commit, leaves non commited work as is
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-07-01 17:13:52 +03:00
|
|
|
assert_eq!(branches.len(), 0);
|
|
|
|
assert_eq!(
|
|
|
|
fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
|
|
|
"1\n2\n3\n4\n5\n6\n17\n8\n19\n10\n11\n12\n"
|
|
|
|
);
|
|
|
|
|
|
|
|
unapplied_refnames[0].clone()
|
|
|
|
};
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
controller
|
2024-07-01 17:13:52 +03:00
|
|
|
.create_virtual_branch_from_branch(
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-07-01 17:13:52 +03:00
|
|
|
&git::Refname::from_str(unapplied_refname.as_str()).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!(branches[0].active);
|
|
|
|
assert!(branches[0].conflicted);
|
|
|
|
assert!(branches[0].base_current);
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
|
|
|
assert_eq!(branches[0].files[0].hunks.len(), 1);
|
2024-04-23 12:07:20 +03:00
|
|
|
assert_eq!(
|
|
|
|
branches[0].files[0].hunks[0].diff,
|
|
|
|
"@@ -4,7 +4,11 @@\n 4\n 5\n 6\n-7\n+<<<<<<< ours\n+77\n+=======\n+17\n+>>>>>>> theirs\n 8\n 19\n 10\n"
|
|
|
|
);
|
2024-03-29 12:04:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn integrated_with_locked_hunks() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
project_id,
|
|
|
|
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 = {
|
|
|
|
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.txt"), "first").unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "first", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
branch_id
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// another non-locked hunk
|
|
|
|
fs::write(repository.path().join("file.txt"), "first\nsecond").unwrap();
|
|
|
|
|
|
|
|
{
|
|
|
|
// push and merge branch remotely
|
2024-07-04 16:26:10 +03:00
|
|
|
let branch = controller.list_virtual_branches(project).await.unwrap().0[0].clone();
|
2024-03-29 12:04:26 +03:00
|
|
|
repository.merge(&branch.upstream.as_ref().unwrap().name);
|
|
|
|
}
|
|
|
|
|
|
|
|
repository.fetch();
|
|
|
|
|
|
|
|
{
|
2024-07-04 16:26:10 +03:00
|
|
|
controller.update_base_branch(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// removes integrated commit, leaves non commited work as is
|
|
|
|
|
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, branch_id);
|
|
|
|
assert!(branches[0].active);
|
|
|
|
assert!(branches[0].commits.is_empty());
|
|
|
|
assert!(branches[0].upstream.is_none());
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn integrated_with_non_locked_hunks() {
|
|
|
|
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 = {
|
|
|
|
// make a branch that conflicts with the remote branch, but doesn't know about it yet
|
|
|
|
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.txt"), "first").unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "first", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
branch_id
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// another non-locked hunk
|
|
|
|
fs::write(repository.path().join("another_file.txt"), "first").unwrap();
|
|
|
|
|
|
|
|
{
|
|
|
|
// push and merge branch remotely
|
2024-07-04 16:26:10 +03:00
|
|
|
let branch = controller.list_virtual_branches(project).await.unwrap().0[0].clone();
|
2024-03-29 12:04:26 +03:00
|
|
|
repository.merge(&branch.upstream.as_ref().unwrap().name);
|
|
|
|
}
|
|
|
|
|
|
|
|
repository.fetch();
|
|
|
|
|
|
|
|
{
|
2024-07-04 16:26:10 +03:00
|
|
|
controller.update_base_branch(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// removes integrated commit, leaves non commited work as is
|
|
|
|
|
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, branch_id);
|
|
|
|
assert!(branches[0].active);
|
|
|
|
assert!(branches[0].commits.is_empty());
|
|
|
|
assert!(branches[0].upstream.is_none());
|
|
|
|
assert_eq!(branches[0].files.len(), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn all_integrated() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file.txt"), "second").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
{
|
|
|
|
// make a branch that conflicts with the remote branch, but doesn't know about it yet
|
|
|
|
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.txt"), "second").unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "second", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// fetch remote
|
2024-07-04 16:26:10 +03:00
|
|
|
controller.update_base_branch(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// just removes integrated branch
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn integrate_work_while_being_behind() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-03-29 12:04:26 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
// make sure we have an undiscovered commit in the remote branch
|
|
|
|
{
|
|
|
|
fs::write(repository.path().join("file.txt"), "first").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file.txt"), "second").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
{
|
|
|
|
// open pr
|
|
|
|
fs::write(repository.path().join("file2.txt"), "new file").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "second", 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// merge pr
|
2024-07-04 16:26:10 +03:00
|
|
|
let branch = controller.list_virtual_branches(project).await.unwrap().0[0].clone();
|
2024-03-29 12:04:26 +03:00
|
|
|
repository.merge(&branch.upstream.as_ref().unwrap().name);
|
|
|
|
repository.fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// fetch remote
|
2024-07-04 16:26:10 +03:00
|
|
|
controller.update_base_branch(project).await.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
// just removes integrated branch
|
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);
|
|
|
|
}
|
|
|
|
}
|
2024-05-02 18:27:24 +03:00
|
|
|
|
|
|
|
// Ensure integrated branch is dropped and that a commit on another
|
|
|
|
// branch does not lead to the introduction of gost/phantom diffs.
|
|
|
|
#[tokio::test]
|
|
|
|
async fn should_not_get_confused_by_commits_in_other_branches() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-05-02 18:27:24 +03:00
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
fs::write(repository.path().join("file-1.txt"), "one").unwrap();
|
|
|
|
let first_commit_oid = repository.commit_all("first");
|
|
|
|
fs::write(repository.path().join("file-2.txt"), "two").unwrap();
|
|
|
|
repository.commit_all("second");
|
|
|
|
repository.push();
|
|
|
|
repository.reset_hard(Some(first_commit_oid));
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-05-02 18:27:24 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch_1_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
2024-05-02 18:27:24 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
fs::write(repository.path().join("file-3.txt"), "three").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_1_id, "third", None, false)
|
2024-05-02 18:27:24 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch_2_id = controller
|
|
|
|
.create_virtual_branch(
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-05-02 18:27:24 +03:00
|
|
|
&branch::BranchCreateRequest {
|
|
|
|
selected_for_changes: Some(true),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
fs::write(repository.path().join("file-4.txt"), "four").unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_2_id, "fourth", None, false)
|
2024-05-02 18:27:24 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.push_virtual_branch(project, branch_2_id, false, None)
|
2024-05-02 18:27:24 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2024-07-04 16:26:10 +03:00
|
|
|
let branch = controller.list_virtual_branches(project).await.unwrap().0[1].clone();
|
2024-05-02 18:27:24 +03:00
|
|
|
|
|
|
|
repository.merge(&branch.upstream.as_ref().unwrap().name);
|
|
|
|
repository.fetch();
|
|
|
|
|
|
|
|
// TODO(mg): Figure out why test fails without listing first.
|
2024-07-04 16:26:10 +03:00
|
|
|
controller.list_virtual_branches(project).await.unwrap();
|
|
|
|
controller.update_base_branch(project).await.unwrap();
|
2024-05-02 18:27:24 +03:00
|
|
|
|
|
|
|
// Verify we have only the first branch left, and that no files
|
|
|
|
// are present.
|
2024-07-04 16:26:10 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).await.unwrap();
|
2024-05-02 18:27:24 +03:00
|
|
|
assert_eq!(branches.len(), 1);
|
|
|
|
assert_eq!(branches[0].files.len(), 0);
|
|
|
|
}
|
2024-03-29 12:04:26 +03:00
|
|
|
}
|