2024-07-13 11:38:56 +03:00
|
|
|
use gitbutler_branch::BranchCreateRequest;
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-07-28 21:48:13 +03:00
|
|
|
use super::*;
|
|
|
|
|
2024-07-28 21:36:55 +03:00
|
|
|
#[test]
|
|
|
|
fn detect_upstream_commits() {
|
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
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch1_id = controller
|
2024-07-13 11:38:56 +03:00
|
|
|
.create_virtual_branch(project, &BranchCreateRequest::default())
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let oid1 = {
|
|
|
|
// create first commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
let oid2 = {
|
|
|
|
// create second commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
// push
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.push_virtual_branch(project, branch1_id, false, None)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let oid3 = {
|
|
|
|
// create third commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// should correctly detect pushed commits
|
2024-07-28 21:36:55 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(branches.len(), 1);
|
|
|
|
assert_eq!(branches[0].id, branch1_id);
|
|
|
|
assert_eq!(branches[0].commits.len(), 3);
|
|
|
|
assert_eq!(branches[0].commits[0].id, oid3);
|
|
|
|
assert!(!branches[0].commits[0].is_remote);
|
|
|
|
assert_eq!(branches[0].commits[1].id, oid2);
|
|
|
|
assert!(branches[0].commits[1].is_remote);
|
|
|
|
assert_eq!(branches[0].commits[2].id, oid1);
|
|
|
|
assert!(branches[0].commits[2].is_remote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-28 21:36:55 +03:00
|
|
|
#[test]
|
|
|
|
fn detect_integrated_commits() {
|
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
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch1_id = controller
|
2024-07-13 11:38:56 +03:00
|
|
|
.create_virtual_branch(project, &BranchCreateRequest::default())
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let oid1 = {
|
|
|
|
// create first commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
let oid2 = {
|
|
|
|
// create second commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
// push
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.push_virtual_branch(project, branch1_id, false, None)
|
2024-03-29 12:04:26 +03:00
|
|
|
.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
|
|
|
.unwrap()
|
|
|
|
.0
|
|
|
|
.into_iter()
|
|
|
|
.find(|b| b.id == branch1_id)
|
|
|
|
.unwrap();
|
|
|
|
repository.merge(&branch.upstream.as_ref().unwrap().name);
|
|
|
|
repository.fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
let oid3 = {
|
|
|
|
// create third commit
|
|
|
|
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
|
|
|
controller
|
2024-07-04 16:26:10 +03:00
|
|
|
.create_commit(project, branch1_id, "commit", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
// should correctly detect pushed commits
|
2024-07-28 21:36:55 +03:00
|
|
|
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(branches.len(), 1);
|
|
|
|
assert_eq!(branches[0].id, branch1_id);
|
|
|
|
assert_eq!(branches[0].commits.len(), 3);
|
|
|
|
assert_eq!(branches[0].commits[0].id, oid3);
|
|
|
|
assert!(!branches[0].commits[0].is_integrated);
|
|
|
|
assert_eq!(branches[0].commits[1].id, oid2);
|
|
|
|
assert!(branches[0].commits[1].is_integrated);
|
|
|
|
assert_eq!(branches[0].commits[2].id, oid1);
|
|
|
|
assert!(branches[0].commits[2].is_integrated);
|
|
|
|
}
|
|
|
|
}
|