mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-01 14:04:57 +03:00
use simpler virtual branch handle fetch in tests (and fix strange uncaught compilation error)
This commit is contained in:
parent
da62926a30
commit
dce8ead62f
@ -461,7 +461,7 @@ mod tests {
|
||||
// create gb_dir folder
|
||||
std::fs::create_dir_all(project.gb_dir()).unwrap();
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project.gb_dir());
|
||||
let vb_state = project.virtual_branches();
|
||||
|
||||
let target_sha = initial_commit.to_string();
|
||||
let default_target = crate::virtual_branches::target::Target {
|
||||
|
@ -13,7 +13,7 @@ fn parse_invalid() {
|
||||
|
||||
#[test]
|
||||
fn parse_with_hash() {
|
||||
let hash = Hunk::hash("hash".as_ref());
|
||||
let hash = Hunk::hash("hash");
|
||||
assert_eq!(
|
||||
format!("2-3-{hash:x}").parse::<Hunk>().unwrap(),
|
||||
Hunk::new(2, 3, Some(hash), None).unwrap()
|
||||
@ -43,15 +43,15 @@ fn to_string_no_hash() {
|
||||
|
||||
#[test]
|
||||
fn hash_diff_no_diff_header_is_normal_hash() {
|
||||
let actual = Hunk::hash_diff("a".as_ref());
|
||||
let expected = Hunk::hash("a".as_ref());
|
||||
let actual = Hunk::hash_diff("a");
|
||||
let expected = Hunk::hash("a");
|
||||
assert_eq!(actual, expected)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hash_diff_empty_is_fine() {
|
||||
let actual = Hunk::hash_diff("".as_ref());
|
||||
let expected = Hunk::hash("".as_ref());
|
||||
let actual = Hunk::hash_diff("");
|
||||
let expected = Hunk::hash("");
|
||||
assert_eq!(
|
||||
actual, expected,
|
||||
"The special hash is the same as a normal one in case of empty input.\
|
||||
@ -61,8 +61,8 @@ fn hash_diff_empty_is_fine() {
|
||||
|
||||
#[test]
|
||||
fn hash_diff_content_hash() {
|
||||
let a_hash = Hunk::hash_diff("@@x\na".into());
|
||||
let b_hash = Hunk::hash_diff("@@y\na".into());
|
||||
let a_hash = Hunk::hash_diff("@@x\na");
|
||||
let b_hash = Hunk::hash_diff("@@y\na");
|
||||
assert_eq!(
|
||||
a_hash, b_hash,
|
||||
"it skips the first line which is assumed to be a diff-header.\
|
||||
@ -72,8 +72,8 @@ fn hash_diff_content_hash() {
|
||||
|
||||
#[test]
|
||||
fn eq() {
|
||||
let a_hash = Hunk::hash("a".as_ref());
|
||||
let b_hash = Hunk::hash("b".as_ref());
|
||||
let a_hash = Hunk::hash("a");
|
||||
let b_hash = Hunk::hash("b");
|
||||
assert_ne!(a_hash, b_hash);
|
||||
for (a, b, expected) in vec![
|
||||
(
|
||||
|
@ -16,14 +16,14 @@ fn reconcile_ownership_simple() {
|
||||
Hunk {
|
||||
start: 1,
|
||||
end: 3,
|
||||
hash: Some(Hunk::hash("1,3".as_ref())),
|
||||
hash: Some(Hunk::hash("1,3")),
|
||||
timestamp_ms: None,
|
||||
locked_to: vec![],
|
||||
},
|
||||
Hunk {
|
||||
start: 4,
|
||||
end: 6,
|
||||
hash: Some(Hunk::hash("4,6".as_ref())),
|
||||
hash: Some(Hunk::hash("4,6")),
|
||||
timestamp_ms: None,
|
||||
locked_to: vec![],
|
||||
},
|
||||
@ -41,7 +41,7 @@ fn reconcile_ownership_simple() {
|
||||
hunks: vec![Hunk {
|
||||
start: 7,
|
||||
end: 9,
|
||||
hash: Some(Hunk::hash("7,9".as_ref())),
|
||||
hash: Some(Hunk::hash("7,9")),
|
||||
timestamp_ms: None,
|
||||
locked_to: vec![],
|
||||
}],
|
||||
@ -57,14 +57,14 @@ fn reconcile_ownership_simple() {
|
||||
Hunk {
|
||||
start: 4,
|
||||
end: 6,
|
||||
hash: Some(Hunk::hash("4,6".as_ref())),
|
||||
hash: Some(Hunk::hash("4,6")),
|
||||
timestamp_ms: None,
|
||||
locked_to: vec![],
|
||||
},
|
||||
Hunk {
|
||||
start: 7,
|
||||
end: 9,
|
||||
hash: Some(Hunk::hash("9,7".as_ref())),
|
||||
hash: Some(Hunk::hash("9,7")),
|
||||
timestamp_ms: None,
|
||||
locked_to: vec![],
|
||||
},
|
||||
@ -83,7 +83,7 @@ fn reconcile_ownership_simple() {
|
||||
hunks: vec![Hunk {
|
||||
start: 1,
|
||||
end: 3,
|
||||
hash: Some(Hunk::hash("1,3".as_ref())),
|
||||
hash: Some(Hunk::hash("1,3")),
|
||||
timestamp_ms: None,
|
||||
locked_to: vec![],
|
||||
},],
|
||||
@ -100,14 +100,14 @@ fn reconcile_ownership_simple() {
|
||||
Hunk {
|
||||
start: 4,
|
||||
end: 6,
|
||||
hash: Some(Hunk::hash("4,6".as_ref())),
|
||||
hash: Some(Hunk::hash("4,6")),
|
||||
timestamp_ms: None,
|
||||
locked_to: vec![],
|
||||
},
|
||||
Hunk {
|
||||
start: 7,
|
||||
end: 9,
|
||||
hash: Some(Hunk::hash("9,7".as_ref())),
|
||||
hash: Some(Hunk::hash("9,7")),
|
||||
timestamp_ms: None,
|
||||
locked_to: vec![],
|
||||
},
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use anyhow::Result;
|
||||
use gitbutler_core::virtual_branches::{self, VirtualBranchesHandle};
|
||||
use gitbutler_core::virtual_branches;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use gitbutler_testsupport::{Case, Suite};
|
||||
@ -72,7 +72,7 @@ fn empty_iterator() -> Result<()> {
|
||||
let suite = Suite::default();
|
||||
let Case { project, .. } = &suite.new_case();
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project.gb_dir());
|
||||
let vb_state = project.virtual_branches();
|
||||
let iter = vb_state.list_branches()?;
|
||||
|
||||
assert_eq!(iter.len(), 0);
|
||||
@ -85,7 +85,7 @@ fn iterate_all() -> Result<()> {
|
||||
let suite = Suite::default();
|
||||
let Case { project, .. } = &suite.new_case();
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project.gb_dir());
|
||||
let vb_state = project.virtual_branches();
|
||||
vb_state.set_default_target(new_test_target())?;
|
||||
let branch_1 = new_test_branch();
|
||||
vb_state.set_branch(branch_1.clone())?;
|
||||
|
@ -22,7 +22,7 @@ use gitbutler_core::{
|
||||
errors::CommitError,
|
||||
integration::verify_branch,
|
||||
is_remote_branch_mergeable, is_virtual_branch_mergeable, list_remote_branches,
|
||||
merge_virtual_branch_upstream, unapply_ownership, update_branch, VirtualBranchesHandle,
|
||||
merge_virtual_branch_upstream, unapply_ownership, update_branch,
|
||||
},
|
||||
};
|
||||
use pretty_assertions::assert_eq;
|
||||
@ -280,7 +280,7 @@ fn create_branch_with_ownership() -> Result<()> {
|
||||
|
||||
virtual_branches::get_status_by_branch(project_repository, None).expect("failed to get status");
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project_repository.project().gb_dir());
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
let branch0 = vb_state.get_branch(&branch0.id).unwrap();
|
||||
|
||||
let branch1 = create_virtual_branch(
|
||||
@ -330,7 +330,7 @@ fn create_branch_in_the_middle() -> Result<()> {
|
||||
)
|
||||
.expect("failed to create virtual branch");
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project_repository.project().gb_dir());
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
let mut branches = vb_state.list_branches().expect("failed to read branches");
|
||||
branches.sort_by_key(|b| b.order);
|
||||
assert_eq!(branches.len(), 3);
|
||||
@ -353,7 +353,7 @@ fn create_branch_no_arguments() -> Result<()> {
|
||||
create_virtual_branch(project_repository, &BranchCreateRequest::default())
|
||||
.expect("failed to create virtual branch");
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project_repository.project().gb_dir());
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
let branches = vb_state.list_branches().expect("failed to read branches");
|
||||
assert_eq!(branches.len(), 1);
|
||||
assert_eq!(branches[0].name, "Virtual branch");
|
||||
@ -520,7 +520,7 @@ fn move_hunks_multiple_sources() -> Result<()> {
|
||||
"line0\nline1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10\nline11\nline12\nline13\n",
|
||||
)?;
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project.gb_dir());
|
||||
let vb_state = project.virtual_branches();
|
||||
let mut branch2 = vb_state.get_branch(&branch2_id)?;
|
||||
branch2.ownership = BranchOwnershipClaims {
|
||||
claims: vec!["test.txt:1-5".parse()?],
|
||||
@ -783,7 +783,7 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
|
||||
)?;
|
||||
|
||||
set_test_target(project_repository)?;
|
||||
let vb_state = VirtualBranchesHandle::new(&project.gb_dir());
|
||||
let vb_state = project.virtual_branches();
|
||||
vb_state.set_default_target(virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "origin".to_string(),
|
||||
@ -900,7 +900,7 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
|
||||
)?;
|
||||
|
||||
set_test_target(project_repository)?;
|
||||
let vb_state = VirtualBranchesHandle::new(&project.gb_dir());
|
||||
let vb_state = project.virtual_branches();
|
||||
vb_state.set_default_target(virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "origin".to_string(),
|
||||
@ -1303,7 +1303,7 @@ fn detect_mergeable_branch() -> Result<()> {
|
||||
"line1\nline2\nline3\nline4\nbranch4\n",
|
||||
)?;
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project.gb_dir());
|
||||
let vb_state = project.virtual_branches();
|
||||
|
||||
let mut branch4 = vb_state.get_branch(&branch4_id)?;
|
||||
branch4.ownership = BranchOwnershipClaims {
|
||||
@ -1364,7 +1364,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
||||
(PathBuf::from("test3.txt"), "file3\n"),
|
||||
]));
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project_repository.project().gb_dir());
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
|
||||
let base_commit = project_repository
|
||||
.git_repository
|
||||
|
@ -9,7 +9,7 @@ use gitbutler_core::projects::ProjectId;
|
||||
use gitbutler_core::{
|
||||
deltas::{self, operations::Operation},
|
||||
reader, sessions,
|
||||
virtual_branches::{self, branch, VirtualBranchesHandle},
|
||||
virtual_branches::{self, branch},
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
@ -57,6 +57,7 @@ fn new_test_target() -> virtual_branches::target::Target {
|
||||
)
|
||||
.parse()
|
||||
.unwrap(),
|
||||
push_remote_name: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -659,7 +660,7 @@ fn should_persist_branches_targets_state_between_sessions() -> Result<()> {
|
||||
..
|
||||
} = &fixture.new_case_with_files(HashMap::from([(PathBuf::from("test.txt"), "hello world")]));
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project.gb_dir());
|
||||
let vb_state = project.virtual_branches();
|
||||
let default_target = new_test_target();
|
||||
|
||||
vb_state.set_default_target(default_target.clone())?;
|
||||
@ -675,7 +676,7 @@ fn should_persist_branches_targets_state_between_sessions() -> Result<()> {
|
||||
std::fs::write(project.path.join("test.txt"), "hello world!").unwrap();
|
||||
listener.calculate_delta("test.txt", project.id)?;
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project_repository.project().gb_dir());
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
|
||||
let branches = vb_state.list_branches().unwrap();
|
||||
assert_eq!(branches.len(), 2);
|
||||
@ -703,7 +704,7 @@ fn should_restore_branches_targets_state_from_head_session() -> Result<()> {
|
||||
let Case { project, .. } =
|
||||
&fixture.new_case_with_files(HashMap::from([(PathBuf::from("test.txt"), "hello world")]));
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(&project.gb_dir());
|
||||
let vb_state = project.virtual_branches();
|
||||
|
||||
let default_target = new_test_target();
|
||||
vb_state.set_default_target(default_target.clone())?;
|
||||
|
Loading…
Reference in New Issue
Block a user