2024-03-29 12:04:26 +03:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
mod create_virtual_branch {
|
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 simple() {
|
2024-03-29 12:04:26 +03:00
|
|
|
let Test {
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-09-06 15:12:14 +03:00
|
|
|
|
2024-03-29 12:04:26 +03:00
|
|
|
repository,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::set_base_branch(
|
|
|
|
project,
|
|
|
|
&"refs/remotes/origin/master".parse().unwrap(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let branch_id = gitbutler_branch_actions::create_virtual_branch(
|
|
|
|
project,
|
|
|
|
&BranchCreateRequest::default(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(branches.len(), 1);
|
|
|
|
assert_eq!(branches[0].id, branch_id);
|
|
|
|
assert_eq!(branches[0].name, "Virtual branch");
|
|
|
|
|
|
|
|
let refnames = repository
|
|
|
|
.references()
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|reference| reference.name().map(|name| name.to_string()))
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert!(refnames.contains(&"refs/gitbutler/Virtual-branch".to_string()));
|
|
|
|
}
|
|
|
|
|
2024-07-28 21:36:55 +03:00
|
|
|
#[test]
|
|
|
|
fn duplicate_name() {
|
2024-03-29 12:04:26 +03:00
|
|
|
let Test {
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-09-06 15:12:14 +03:00
|
|
|
|
2024-03-29 12:04:26 +03:00
|
|
|
repository,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::set_base_branch(
|
|
|
|
project,
|
|
|
|
&"refs/remotes/origin/master".parse().unwrap(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
|
|
|
project,
|
|
|
|
&BranchCreateRequest {
|
|
|
|
name: Some("name".to_string()),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch2_id = gitbutler_branch_actions::create_virtual_branch(
|
|
|
|
project,
|
|
|
|
&BranchCreateRequest {
|
|
|
|
name: Some("name".to_string()),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(branches.len(), 2);
|
|
|
|
assert_eq!(branches[0].id, branch1_id);
|
|
|
|
assert_eq!(branches[0].name, "name");
|
|
|
|
assert_eq!(branches[1].id, branch2_id);
|
|
|
|
assert_eq!(branches[1].name, "name 1");
|
|
|
|
|
|
|
|
let refnames = repository
|
|
|
|
.references()
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|reference| reference.name().map(|name| name.to_string()))
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert!(refnames.contains(&"refs/gitbutler/name".to_string()));
|
|
|
|
assert!(refnames.contains(&"refs/gitbutler/name-1".to_string()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod update_virtual_branch {
|
2024-07-13 11:38:56 +03:00
|
|
|
use gitbutler_branch::{BranchCreateRequest, BranchUpdateRequest};
|
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 simple() {
|
2024-03-29 12:04:26 +03:00
|
|
|
let Test {
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-09-06 15:12:14 +03:00
|
|
|
|
2024-03-29 12:04:26 +03:00
|
|
|
repository,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::set_base_branch(
|
|
|
|
project,
|
|
|
|
&"refs/remotes/origin/master".parse().unwrap(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let branch_id = gitbutler_branch_actions::create_virtual_branch(
|
|
|
|
project,
|
|
|
|
&BranchCreateRequest {
|
|
|
|
name: Some("name".to_string()),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
gitbutler_branch_actions::update_virtual_branch(
|
|
|
|
project,
|
|
|
|
BranchUpdateRequest {
|
|
|
|
id: branch_id,
|
|
|
|
name: Some("new name".to_string()),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(branches.len(), 1);
|
|
|
|
assert_eq!(branches[0].id, branch_id);
|
|
|
|
assert_eq!(branches[0].name, "new name");
|
|
|
|
|
|
|
|
let refnames = repository
|
|
|
|
.references()
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|reference| reference.name().map(|name| name.to_string()))
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert!(!refnames.contains(&"refs/gitbutler/name".to_string()));
|
|
|
|
assert!(refnames.contains(&"refs/gitbutler/new-name".to_string()));
|
|
|
|
}
|
|
|
|
|
2024-07-28 21:36:55 +03:00
|
|
|
#[test]
|
|
|
|
fn duplicate_name() {
|
2024-03-29 12:04:26 +03:00
|
|
|
let Test {
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-09-06 15:12:14 +03:00
|
|
|
|
2024-03-29 12:04:26 +03:00
|
|
|
repository,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::set_base_branch(
|
|
|
|
project,
|
|
|
|
&"refs/remotes/origin/master".parse().unwrap(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
|
|
|
project,
|
|
|
|
&BranchCreateRequest {
|
|
|
|
name: Some("name".to_string()),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch2_id = gitbutler_branch_actions::create_virtual_branch(
|
|
|
|
project,
|
|
|
|
&BranchCreateRequest {
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::update_virtual_branch(
|
|
|
|
project,
|
|
|
|
BranchUpdateRequest {
|
|
|
|
id: branch2_id,
|
|
|
|
name: Some("name".to_string()),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(branches.len(), 2);
|
|
|
|
assert_eq!(branches[0].id, branch1_id);
|
|
|
|
assert_eq!(branches[0].name, "name");
|
|
|
|
assert_eq!(branches[1].id, branch2_id);
|
|
|
|
assert_eq!(branches[1].name, "name 1");
|
|
|
|
|
|
|
|
let refnames = repository
|
|
|
|
.references()
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|reference| reference.name().map(|name| name.to_string()))
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert!(refnames.contains(&"refs/gitbutler/name".to_string()));
|
|
|
|
assert!(refnames.contains(&"refs/gitbutler/name-1".to_string()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod push_virtual_branch {
|
2024-07-13 11:38:56 +03:00
|
|
|
use gitbutler_branch::{BranchCreateRequest, BranchUpdateRequest};
|
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 simple() {
|
2024-03-29 12:04:26 +03:00
|
|
|
let Test {
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-09-06 15:12:14 +03:00
|
|
|
|
2024-03-29 12:04:26 +03:00
|
|
|
repository,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::set_base_branch(
|
|
|
|
project,
|
|
|
|
&"refs/remotes/origin/master".parse().unwrap(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
|
|
|
project,
|
|
|
|
&BranchCreateRequest {
|
|
|
|
name: Some("name".to_string()),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::create_commit(project, branch1_id, "test", None, false).unwrap();
|
|
|
|
gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None).unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let (branches, _) = gitbutler_branch_actions::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].name, "name");
|
|
|
|
assert_eq!(
|
|
|
|
branches[0].upstream.as_ref().unwrap().name.to_string(),
|
|
|
|
"refs/remotes/origin/name"
|
|
|
|
);
|
|
|
|
|
|
|
|
let refnames = repository
|
|
|
|
.references()
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|reference| reference.name().map(|name| name.to_string()))
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert!(refnames.contains(&branches[0].upstream.clone().unwrap().name.to_string()));
|
|
|
|
}
|
|
|
|
|
2024-07-28 21:36:55 +03:00
|
|
|
#[test]
|
|
|
|
fn duplicate_names() {
|
2024-03-29 12:04:26 +03:00
|
|
|
let Test {
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-09-06 15:12:14 +03:00
|
|
|
|
2024-03-29 12:04:26 +03:00
|
|
|
repository,
|
|
|
|
..
|
|
|
|
} = &Test::default();
|
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::set_base_branch(
|
|
|
|
project,
|
|
|
|
&"refs/remotes/origin/master".parse().unwrap(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
|
|
|
|
let branch1_id = {
|
|
|
|
// create and push branch with some work
|
2024-09-06 15:12:14 +03:00
|
|
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
|
|
|
project,
|
|
|
|
&BranchCreateRequest {
|
|
|
|
name: Some("name".to_string()),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::create_commit(project, branch1_id, "test", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap();
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap();
|
|
|
|
branch1_id
|
|
|
|
};
|
|
|
|
|
|
|
|
// rename first branch
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::update_virtual_branch(
|
|
|
|
project,
|
|
|
|
BranchUpdateRequest {
|
|
|
|
id: branch1_id,
|
|
|
|
name: Some("updated name".to_string()),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let branch2_id = {
|
|
|
|
// create another branch with first branch's old name and push it
|
|
|
|
let branch2_id = gitbutler_branch_actions::create_virtual_branch(
|
2024-07-04 16:26:10 +03:00
|
|
|
project,
|
2024-09-06 15:12:14 +03:00
|
|
|
&BranchCreateRequest {
|
|
|
|
name: Some("name".to_string()),
|
2024-03-29 12:04:26 +03:00
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
fs::write(repository.path().join("file.txt"), "updated content").unwrap();
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::create_commit(project, branch2_id, "test", None, false)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap();
|
2024-09-06 15:12:14 +03:00
|
|
|
gitbutler_branch_actions::push_virtual_branch(project, branch2_id, false, None)
|
2024-03-29 12:04:26 +03:00
|
|
|
.unwrap();
|
|
|
|
branch2_id
|
|
|
|
};
|
|
|
|
|
2024-09-06 15:12:14 +03:00
|
|
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
2024-03-29 12:04:26 +03:00
|
|
|
assert_eq!(branches.len(), 2);
|
|
|
|
// first branch is pushing to old ref remotely
|
|
|
|
assert_eq!(branches[0].id, branch1_id);
|
|
|
|
assert_eq!(branches[0].name, "updated name");
|
|
|
|
assert_eq!(
|
|
|
|
branches[0].upstream.as_ref().unwrap().name,
|
|
|
|
"refs/remotes/origin/name".parse().unwrap()
|
|
|
|
);
|
|
|
|
// new branch is pushing to new ref remotely
|
|
|
|
assert_eq!(branches[1].id, branch2_id);
|
|
|
|
assert_eq!(branches[1].name, "name");
|
|
|
|
assert_eq!(
|
|
|
|
branches[1].upstream.as_ref().unwrap().name,
|
|
|
|
"refs/remotes/origin/name-1".parse().unwrap()
|
|
|
|
);
|
|
|
|
|
|
|
|
let refnames = repository
|
|
|
|
.references()
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|reference| reference.name().map(|name| name.to_string()))
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert!(refnames.contains(&branches[0].upstream.clone().unwrap().name.to_string()));
|
|
|
|
assert!(refnames.contains(&branches[1].upstream.clone().unwrap().name.to_string()));
|
|
|
|
}
|
|
|
|
}
|