2024-07-09 01:10:55 +03:00
|
|
|
use gitbutler_branch::ownership::BranchOwnershipClaims;
|
2024-07-09 14:19:49 +03:00
|
|
|
use gitbutler_commit::commit_ext::CommitExt;
|
2024-05-29 18:33:57 +03:00
|
|
|
|
2024-04-29 16:03:01 +03:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn move_file_down() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-04-29 16:03:01 +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-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
let commit1_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-05-15 16:21:19 +03:00
|
|
|
let commit1 = repository.find_commit(commit1_id).unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
|
|
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
|
|
|
let commit2_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-05-15 16:21:19 +03:00
|
|
|
let commit2 = repository.find_commit(commit2_id).unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
|
|
|
|
// amend another hunk
|
2024-07-09 01:10:55 +03:00
|
|
|
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.move_commit_file(project, branch_id, commit2_id, commit1_id, &to_amend)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2024-05-15 16:21:19 +03:00
|
|
|
// shas changed but change_id is the same
|
|
|
|
assert_eq!(&commit1.change_id(), &branch.commits[1].change_id);
|
2024-06-05 23:56:03 +03:00
|
|
|
assert_ne!(&commit1.id(), &branch.commits[1].id);
|
2024-05-15 16:21:19 +03:00
|
|
|
assert_eq!(&commit2.change_id(), &branch.commits[0].change_id);
|
2024-06-05 23:56:03 +03:00
|
|
|
assert_ne!(&commit2.id(), &branch.commits[0].id);
|
2024-05-15 16:21:19 +03:00
|
|
|
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1);
|
2024-04-29 16:03:01 +03:00
|
|
|
assert_eq!(branch.commits.len(), 2);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 1);
|
|
|
|
assert_eq!(branch.commits[1].files.len(), 2); // this now has both file changes
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn move_file_up() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-04-29 16:03:01 +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-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
|
|
|
let commit1_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();
|
|
|
|
|
|
|
|
// create commit
|
|
|
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
|
|
|
let commit2_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// amend another hunk
|
2024-07-09 01:10:55 +03:00
|
|
|
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
2024-04-29 16:03:01 +03:00
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.move_commit_file(project, branch_id, commit1_id, commit2_id, &to_amend)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
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(), 2);
|
|
|
|
assert_eq!(branch.commits[0].files.len(), 2); // this now has both file changes
|
|
|
|
assert_eq!(branch.commits[1].files.len(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This test is failing because the file is not being moved up to the correct commit
|
|
|
|
// This is out of scope for the first release, but should be fixed in the future
|
|
|
|
// where you can take overlapping hunks between commits and resolve a move between them
|
|
|
|
/*
|
|
|
|
#[tokio::test]
|
|
|
|
async fn move_file_up_overlapping_hunks() {
|
|
|
|
let Test {
|
|
|
|
repository,
|
|
|
|
project_id,
|
|
|
|
controller,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create bottom commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
let _commit1_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();
|
|
|
|
|
|
|
|
// create middle commit one
|
|
|
|
fs::write(repository.path().join("file2.txt"), "content2\ncontent2a\n").unwrap();
|
|
|
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
|
|
|
let commit2_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit two", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create middle commit two
|
|
|
|
fs::write(
|
|
|
|
repository.path().join("file2.txt"),
|
|
|
|
"content2\ncontent2a\ncontent2b\ncontent2c\ncontent2d",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
|
|
|
let commit3_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit three", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// create top commit
|
|
|
|
fs::write(repository.path().join("file5.txt"), "content5").unwrap();
|
|
|
|
let _commit4_id = controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch_id, "commit four", None, false)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// move one line from middle commit two up to middle commit one
|
|
|
|
let to_amend: branch::BranchOwnershipClaims = "file2.txt:1-6".parse().unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.move_commit_file(project, branch_id, commit2_id, commit3_id, &to_amend)
|
2024-04-29 16:03:01 +03:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
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(), 4);
|
|
|
|
//
|
|
|
|
}
|
|
|
|
*/
|