mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-24 01:51:57 +03:00
refactor: move VirtualBranchesHandle construction out of branch reader/writer
When the migration is complete there will be no branch/target reader/writer. For now, inject the handle
This commit is contained in:
parent
c85c1e9758
commit
de181f2107
@ -17,10 +17,10 @@ use crate::windows::MetadataShim;
|
||||
use crate::{
|
||||
deltas, fs, git, project_repository,
|
||||
projects::{self, ProjectId},
|
||||
reader, sessions,
|
||||
sessions::SessionId,
|
||||
reader,
|
||||
sessions::{self, SessionId},
|
||||
users,
|
||||
virtual_branches::{self, target},
|
||||
virtual_branches::{self, target, VirtualBranchesHandle},
|
||||
};
|
||||
|
||||
pub struct Repository {
|
||||
@ -264,8 +264,11 @@ impl Repository {
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let src_target_reader = virtual_branches::target::Reader::new(&last_session_reader);
|
||||
let dst_target_writer = virtual_branches::target::Writer::new(self, self.project.gb_dir())
|
||||
.context("failed to open target writer for current session")?;
|
||||
let dst_target_writer = virtual_branches::target::Writer::new(
|
||||
self,
|
||||
VirtualBranchesHandle::new(&self.project.gb_dir()),
|
||||
)
|
||||
.context("failed to open target writer for current session")?;
|
||||
|
||||
// copy default target
|
||||
let default_target = match src_target_reader.read_default() {
|
||||
@ -294,8 +297,11 @@ impl Repository {
|
||||
.with_context(|| format!("{}: failed to write target", branch.id))?;
|
||||
}
|
||||
|
||||
let dst_branch_writer = virtual_branches::branch::Writer::new(self, self.project.gb_dir())
|
||||
.context("failed to open branch writer for current session")?;
|
||||
let dst_branch_writer = virtual_branches::branch::Writer::new(
|
||||
self,
|
||||
VirtualBranchesHandle::new(&self.project.gb_dir()),
|
||||
)
|
||||
.context("failed to open branch writer for current session")?;
|
||||
|
||||
// copy branches that we don't already have
|
||||
for branch in &branches {
|
||||
|
@ -27,3 +27,4 @@ mod remote;
|
||||
pub use remote::*;
|
||||
|
||||
mod state;
|
||||
pub use state::VirtualBranchesHandle;
|
||||
|
@ -6,7 +6,7 @@ use serde::Serialize;
|
||||
use super::{
|
||||
branch, errors,
|
||||
integration::{update_gitbutler_integration, GITBUTLER_INTEGRATION_REFERENCE},
|
||||
target, BranchId, RemoteCommit,
|
||||
target, BranchId, RemoteCommit, VirtualBranchesHandle,
|
||||
};
|
||||
use crate::{
|
||||
gb_repository,
|
||||
@ -188,8 +188,11 @@ pub fn set_base_branch(
|
||||
sha: target_commit_oid,
|
||||
};
|
||||
|
||||
let target_writer = target::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create target writer")?;
|
||||
let target_writer = target::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create target writer")?;
|
||||
target_writer.write_default(&target)?;
|
||||
|
||||
let head_name: git::Refname = current_head
|
||||
@ -276,9 +279,11 @@ pub fn set_base_branch(
|
||||
selected_for_changes: None,
|
||||
};
|
||||
|
||||
let branch_writer =
|
||||
branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create branch writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create branch writer")?;
|
||||
branch_writer.write(&mut branch)?;
|
||||
}
|
||||
}
|
||||
@ -379,8 +384,11 @@ pub fn update_base_branch(
|
||||
target.sha
|
||||
))?;
|
||||
|
||||
let branch_writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create branch writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create branch writer")?;
|
||||
|
||||
let use_context = project_repository
|
||||
.project()
|
||||
@ -598,8 +606,11 @@ pub fn update_base_branch(
|
||||
)?;
|
||||
|
||||
// write new target oid
|
||||
let target_writer = target::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create target writer")?;
|
||||
let target_writer = target::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create target writer")?;
|
||||
target_writer.write_default(&target::Target {
|
||||
sha: new_target_commit.id(),
|
||||
..target
|
||||
|
@ -1,5 +1,3 @@
|
||||
use std::path;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use super::Branch;
|
||||
@ -13,13 +11,12 @@ pub struct BranchWriter<'writer> {
|
||||
}
|
||||
|
||||
impl<'writer> BranchWriter<'writer> {
|
||||
pub fn new<P: AsRef<path::Path>>(
|
||||
pub fn new(
|
||||
repository: &'writer gb_repository::Repository,
|
||||
path: P,
|
||||
state_handle: VirtualBranchesHandle,
|
||||
) -> Result<Self, std::io::Error> {
|
||||
let reader = reader::Reader::open(repository.root())?;
|
||||
let writer = writer::DirWriter::open(repository.root())?;
|
||||
let state_handle = VirtualBranchesHandle::new(path.as_ref());
|
||||
Ok(Self {
|
||||
repository,
|
||||
writer,
|
||||
|
@ -3,7 +3,7 @@ use std::io::{Read, Write};
|
||||
use anyhow::{Context, Result};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use super::errors;
|
||||
use super::{errors, VirtualBranchesHandle};
|
||||
use crate::{
|
||||
gb_repository,
|
||||
git::{self},
|
||||
@ -262,8 +262,11 @@ fn verify_head_is_clean(
|
||||
.context("failed to create virtual branch")?;
|
||||
|
||||
// rebasing the extra commits onto the new branch
|
||||
let writer = super::branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let writer = super::branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
extra_commits.reverse();
|
||||
let mut head = new_branch.head;
|
||||
for commit in extra_commits {
|
||||
|
@ -1,5 +1,3 @@
|
||||
use std::path;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use super::Target;
|
||||
@ -17,13 +15,12 @@ pub struct TargetWriter<'writer> {
|
||||
}
|
||||
|
||||
impl<'writer> TargetWriter<'writer> {
|
||||
pub fn new<P: AsRef<path::Path>>(
|
||||
pub fn new(
|
||||
repository: &'writer gb_repository::Repository,
|
||||
path: P,
|
||||
state_handle: VirtualBranchesHandle,
|
||||
) -> Result<Self, std::io::Error> {
|
||||
let reader = reader::Reader::open(&repository.root())?;
|
||||
let writer = writer::DirWriter::open(repository.root())?;
|
||||
let state_handle = VirtualBranchesHandle::new(path.as_ref());
|
||||
Ok(Self {
|
||||
repository,
|
||||
writer,
|
||||
|
@ -19,6 +19,7 @@ use super::{
|
||||
self, Branch, BranchCreateRequest, BranchId, BranchOwnershipClaims, Hunk, OwnershipClaim,
|
||||
},
|
||||
branch_to_remote_branch, context, errors, target, Iterator, RemoteBranch,
|
||||
VirtualBranchesHandle,
|
||||
};
|
||||
use crate::{
|
||||
askpass::AskpassBroker,
|
||||
@ -218,8 +219,11 @@ pub fn apply_branch(
|
||||
})
|
||||
})?;
|
||||
|
||||
let writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create branch writer")?;
|
||||
let writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create branch writer")?;
|
||||
|
||||
let mut branch = match branch::Reader::new(¤t_session_reader).read(branch_id) {
|
||||
Ok(branch) => Ok(branch),
|
||||
@ -661,8 +665,11 @@ pub fn unapply_branch(
|
||||
.find_commit(default_target.sha)
|
||||
.context("failed to find target commit")?;
|
||||
|
||||
let branch_writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
|
||||
let final_tree = if conflicts::is_resolving(project_repository) {
|
||||
// when applying branch leads to a conflict, all other branches are unapplied.
|
||||
@ -1334,8 +1341,11 @@ pub fn create_virtual_branch(
|
||||
.unwrap_or(all_virtual_branches.len())
|
||||
.clamp(0, all_virtual_branches.len());
|
||||
|
||||
let branch_writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
|
||||
let selected_for_changes = if let Some(selected_for_changes) = create.selected_for_changes {
|
||||
if selected_for_changes {
|
||||
@ -1553,9 +1563,11 @@ pub fn merge_virtual_branch_upstream(
|
||||
let merge_tree = repo
|
||||
.find_tree(merge_tree_oid)
|
||||
.context("failed to find merge tree")?;
|
||||
let branch_writer =
|
||||
branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
|
||||
if *project_repository.project().ok_with_force_push {
|
||||
// attempt a rebase
|
||||
@ -1663,8 +1675,11 @@ pub fn update_branch(
|
||||
let current_session_reader = sessions::Reader::open(gb_repository, ¤t_session)
|
||||
.context("failed to open current session")?;
|
||||
let branch_reader = branch::Reader::new(¤t_session_reader);
|
||||
let branch_writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
|
||||
let mut branch = branch_reader
|
||||
.read(&branch_update.id)
|
||||
@ -1769,8 +1784,11 @@ pub fn delete_branch(
|
||||
let current_session_reader = sessions::Reader::open(gb_repository, ¤t_session)
|
||||
.context("failed to open current session")?;
|
||||
let branch_reader = branch::Reader::new(¤t_session_reader);
|
||||
let branch_writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
|
||||
let branch = match branch_reader.read(branch_id) {
|
||||
Ok(branch) => Ok(branch),
|
||||
@ -2196,9 +2214,11 @@ fn get_applied_status(
|
||||
|
||||
// write updated state if not resolving
|
||||
if !project_repository.is_resolving() {
|
||||
let branch_writer =
|
||||
branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
for (vbranch, files) in &mut hunks_by_branch {
|
||||
vbranch.tree = write_tree(project_repository, default_target, files)?;
|
||||
branch_writer
|
||||
@ -2284,8 +2304,11 @@ pub fn reset_branch(
|
||||
));
|
||||
}
|
||||
|
||||
let branch_writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
branch.head = target_commit_oid;
|
||||
branch_writer
|
||||
.write(&mut branch)
|
||||
@ -2622,8 +2645,11 @@ pub fn commit(
|
||||
}
|
||||
|
||||
// update the virtual branch head
|
||||
let writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
branch.tree = tree_oid;
|
||||
branch.head = commit_oid;
|
||||
writer.write(branch).context("failed to write branch")?;
|
||||
@ -2651,8 +2677,11 @@ pub fn push(
|
||||
.map_err(errors::PushError::Other)?;
|
||||
|
||||
let branch_reader = branch::Reader::new(¤t_session_reader);
|
||||
let branch_writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
|
||||
let mut vbranch = branch_reader.read(branch_id).map_err(|error| match error {
|
||||
reader::Error::NotFound => errors::PushError::BranchNotFound(errors::BranchNotFoundError {
|
||||
@ -3095,8 +3124,11 @@ pub fn amend(
|
||||
)
|
||||
.context("failed to create commit")?;
|
||||
|
||||
let branch_writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
target_branch.head = commit_oid;
|
||||
branch_writer.write(target_branch)?;
|
||||
|
||||
@ -3278,8 +3310,11 @@ pub fn cherry_pick(
|
||||
.context("failed to checkout final tree")?;
|
||||
|
||||
// update branch status
|
||||
let writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
branch.head = commit_oid;
|
||||
writer
|
||||
.write(&mut branch)
|
||||
@ -3471,8 +3506,11 @@ pub fn squash(
|
||||
};
|
||||
|
||||
// save new branch head
|
||||
let writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
branch.head = new_head_id;
|
||||
writer
|
||||
.write(&mut branch)
|
||||
@ -3648,8 +3686,11 @@ pub fn update_commit_message(
|
||||
};
|
||||
|
||||
// save new branch head
|
||||
let writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
branch.head = new_head_id;
|
||||
writer
|
||||
.write(&mut branch)
|
||||
@ -3774,8 +3815,11 @@ pub fn move_commit(
|
||||
return Err(errors::MoveCommitError::SourceLocked);
|
||||
}
|
||||
|
||||
let branch_writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let branch_writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
let branch_reader = branch::Reader::new(&latest_session_reader);
|
||||
|
||||
// move files ownerships from source branch to the destination branch
|
||||
@ -3992,8 +4036,11 @@ pub fn create_virtual_branch_from_branch(
|
||||
selected_for_changes,
|
||||
};
|
||||
|
||||
let writer = branch::Writer::new(gb_repository, project_repository.project().gb_dir())
|
||||
.context("failed to create writer")?;
|
||||
let writer = branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)
|
||||
.context("failed to create writer")?;
|
||||
writer
|
||||
.write(&mut branch)
|
||||
.context("failed to write branch")?;
|
||||
|
@ -17,7 +17,10 @@ pub mod paths {
|
||||
}
|
||||
|
||||
pub mod virtual_branches {
|
||||
use gitbutler_core::{gb_repository, project_repository, virtual_branches};
|
||||
use gitbutler_core::{
|
||||
gb_repository, project_repository,
|
||||
virtual_branches::{self, VirtualBranchesHandle},
|
||||
};
|
||||
|
||||
use crate::shared::empty_bare_repository;
|
||||
|
||||
@ -35,13 +38,16 @@ pub mod virtual_branches {
|
||||
.expect("failed to add remote");
|
||||
remote.push(&["refs/heads/master:refs/heads/master"], None)?;
|
||||
|
||||
virtual_branches::target::Writer::new(gb_repo, project_repository.project().gb_dir())?
|
||||
.write_default(&virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: remote_repo.path().to_str().unwrap().parse().unwrap(),
|
||||
sha: remote_repo.head().unwrap().target().unwrap(),
|
||||
})
|
||||
.expect("failed to write target");
|
||||
virtual_branches::target::Writer::new(
|
||||
gb_repo,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)?
|
||||
.write_default(&virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: remote_repo.path().to_str().unwrap().parse().unwrap(),
|
||||
sha: remote_repo.head().unwrap().target().unwrap(),
|
||||
})
|
||||
.expect("failed to write target");
|
||||
|
||||
virtual_branches::integration::update_gitbutler_integration(gb_repo, project_repository)
|
||||
.expect("failed to update integration");
|
||||
|
@ -1,7 +1,10 @@
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use anyhow::Result;
|
||||
use gitbutler_core::virtual_branches::{branch, branch::BranchOwnershipClaims, Branch, BranchId};
|
||||
use gitbutler_core::virtual_branches::{
|
||||
branch::{self, BranchOwnershipClaims},
|
||||
Branch, BranchId, VirtualBranchesHandle,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::shared::{Case, Suite};
|
||||
@ -83,7 +86,7 @@ fn read_override() -> Result<()> {
|
||||
|
||||
let mut branch = test_branch();
|
||||
|
||||
let writer = branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let writer = branch::Writer::new(gb_repository, VirtualBranchesHandle::new(&project.gb_dir()))?;
|
||||
writer.write(&mut branch)?;
|
||||
|
||||
let session = gb_repository.get_current_session()?.unwrap();
|
||||
|
@ -4,7 +4,7 @@ use std::{
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use gitbutler_core::virtual_branches::branch;
|
||||
use gitbutler_core::virtual_branches::{branch, VirtualBranchesHandle};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use self::branch::BranchId;
|
||||
@ -66,7 +66,7 @@ fn write_branch() -> anyhow::Result<()> {
|
||||
|
||||
let mut branch = new_test_branch();
|
||||
|
||||
let writer = branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let writer = branch::Writer::new(gb_repository, VirtualBranchesHandle::new(&project.gb_dir()))?;
|
||||
writer.write(&mut branch)?;
|
||||
|
||||
let root = gb_repository
|
||||
@ -132,7 +132,7 @@ fn should_create_session() -> anyhow::Result<()> {
|
||||
|
||||
let mut branch = new_test_branch();
|
||||
|
||||
let writer = branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let writer = branch::Writer::new(gb_repository, VirtualBranchesHandle::new(&project.gb_dir()))?;
|
||||
writer.write(&mut branch)?;
|
||||
|
||||
assert!(gb_repository.get_current_session()?.is_some());
|
||||
@ -151,7 +151,7 @@ fn should_update() -> anyhow::Result<()> {
|
||||
|
||||
let mut branch = new_test_branch();
|
||||
|
||||
let writer = branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let writer = branch::Writer::new(gb_repository, VirtualBranchesHandle::new(&project.gb_dir()))?;
|
||||
writer.write(&mut branch)?;
|
||||
|
||||
let mut updated_branch = Branch {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use anyhow::Result;
|
||||
use gitbutler_core::virtual_branches;
|
||||
use gitbutler_core::virtual_branches::{self, VirtualBranchesHandle};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::shared::{Case, Suite};
|
||||
@ -90,12 +90,16 @@ fn iterate_all() -> Result<()> {
|
||||
..
|
||||
} = &suite.new_case();
|
||||
|
||||
let target_writer =
|
||||
gitbutler_core::virtual_branches::target::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let target_writer = gitbutler_core::virtual_branches::target::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project.gb_dir()),
|
||||
)?;
|
||||
target_writer.write_default(&new_test_target())?;
|
||||
|
||||
let branch_writer =
|
||||
gitbutler_core::virtual_branches::branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let branch_writer = gitbutler_core::virtual_branches::branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project.gb_dir()),
|
||||
)?;
|
||||
let mut branch_1 = new_test_branch();
|
||||
branch_writer.write(&mut branch_1)?;
|
||||
let mut branch_2 = new_test_branch();
|
||||
|
@ -15,15 +15,15 @@ use std::{
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use gitbutler_core::{
|
||||
git, reader, sessions, virtual_branches,
|
||||
git, reader, sessions,
|
||||
virtual_branches::{
|
||||
apply_branch,
|
||||
self, apply_branch,
|
||||
branch::{BranchCreateRequest, BranchOwnershipClaims},
|
||||
commit, create_virtual_branch,
|
||||
errors::CommitError,
|
||||
integration::verify_branch,
|
||||
is_remote_branch_mergeable, is_virtual_branch_mergeable, list_remote_branches,
|
||||
merge_virtual_branch_upstream, unapply_ownership, update_branch,
|
||||
merge_virtual_branch_upstream, unapply_ownership, update_branch, VirtualBranchesHandle,
|
||||
},
|
||||
};
|
||||
use pretty_assertions::assert_eq;
|
||||
@ -614,7 +614,10 @@ fn move_hunks_multiple_sources() -> Result<()> {
|
||||
let current_session = gb_repository.get_or_create_current_session()?;
|
||||
let current_session_reader = sessions::Reader::open(gb_repository, ¤t_session)?;
|
||||
let branch_reader = virtual_branches::branch::Reader::new(¤t_session_reader);
|
||||
let branch_writer = virtual_branches::branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let branch_writer = virtual_branches::branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project.gb_dir()),
|
||||
)?;
|
||||
let mut branch2 = branch_reader.read(&branch2_id)?;
|
||||
branch2.ownership = BranchOwnershipClaims {
|
||||
claims: vec!["test.txt:1-5".parse()?],
|
||||
@ -893,19 +896,25 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
|
||||
)?;
|
||||
|
||||
set_test_target(gb_repository, project_repository)?;
|
||||
virtual_branches::target::Writer::new(gb_repository, project_repository.project().gb_dir())?
|
||||
.write_default(&virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "origin".to_string(),
|
||||
sha: target_oid,
|
||||
})?;
|
||||
virtual_branches::target::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)?
|
||||
.write_default(&virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "origin".to_string(),
|
||||
sha: target_oid,
|
||||
})?;
|
||||
|
||||
// add some uncommitted work
|
||||
let file_path2 = Path::new("test2.txt");
|
||||
std::fs::write(Path::new(&project.path).join(file_path2), "file2\n")?;
|
||||
|
||||
let remote_branch: git::RemoteRefname = "refs/remotes/origin/master".parse().unwrap();
|
||||
let branch_writer = virtual_branches::branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let branch_writer = virtual_branches::branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project.gb_dir()),
|
||||
)?;
|
||||
let mut branch = create_virtual_branch(
|
||||
gb_repository,
|
||||
project_repository,
|
||||
@ -1018,13 +1027,15 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
|
||||
)?;
|
||||
|
||||
set_test_target(gb_repository, project_repository)?;
|
||||
virtual_branches::target::Writer::new(gb_repository, project.gb_dir())?.write_default(
|
||||
&virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "origin".to_string(),
|
||||
sha: target_oid,
|
||||
},
|
||||
)?;
|
||||
virtual_branches::target::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project.gb_dir()),
|
||||
)?
|
||||
.write_default(&virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "origin".to_string(),
|
||||
sha: target_oid,
|
||||
})?;
|
||||
|
||||
// add some uncommitted work
|
||||
std::fs::write(
|
||||
@ -1033,7 +1044,10 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
|
||||
)?;
|
||||
|
||||
let remote_branch: git::RemoteRefname = "refs/remotes/origin/master".parse().unwrap();
|
||||
let branch_writer = virtual_branches::branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let branch_writer = virtual_branches::branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project.gb_dir()),
|
||||
)?;
|
||||
let mut branch = create_virtual_branch(
|
||||
gb_repository,
|
||||
project_repository,
|
||||
@ -1389,7 +1403,10 @@ fn detect_mergeable_branch() -> Result<()> {
|
||||
let current_session = gb_repository.get_or_create_current_session()?;
|
||||
let current_session_reader = sessions::Reader::open(gb_repository, ¤t_session)?;
|
||||
let branch_reader = virtual_branches::branch::Reader::new(¤t_session_reader);
|
||||
let branch_writer = virtual_branches::branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let branch_writer = virtual_branches::branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project.gb_dir()),
|
||||
)?;
|
||||
|
||||
update_branch(
|
||||
gb_repository,
|
||||
@ -1580,12 +1597,15 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
||||
"update target",
|
||||
)?;
|
||||
|
||||
virtual_branches::target::Writer::new(gb_repository, project_repository.project().gb_dir())?
|
||||
.write_default(&virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "http://origin.com/project".to_string(),
|
||||
sha: base_commit,
|
||||
})?;
|
||||
virtual_branches::target::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project_repository.project().gb_dir()),
|
||||
)?
|
||||
.write_default(&virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "http://origin.com/project".to_string(),
|
||||
sha: base_commit,
|
||||
})?;
|
||||
project_repository
|
||||
.git_repository
|
||||
.remote("origin", &"http://origin.com/project".parse().unwrap())?;
|
||||
|
@ -1,7 +1,10 @@
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use anyhow::Result;
|
||||
use gitbutler_core::virtual_branches::{target, target::Target, BranchId};
|
||||
use gitbutler_core::virtual_branches::{
|
||||
target::{self, Target},
|
||||
BranchId, VirtualBranchesHandle,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::shared::{Case, Suite};
|
||||
@ -129,14 +132,17 @@ fn read_override_target() -> Result<()> {
|
||||
sha: "0123456789abcdef0123456789abcdef01234567".parse().unwrap(),
|
||||
};
|
||||
|
||||
let branch_writer =
|
||||
gitbutler_core::virtual_branches::branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let branch_writer = gitbutler_core::virtual_branches::branch::Writer::new(
|
||||
gb_repository,
|
||||
VirtualBranchesHandle::new(&project.gb_dir()),
|
||||
)?;
|
||||
branch_writer.write(&mut branch)?;
|
||||
|
||||
let session = gb_repository.get_current_session()?.unwrap();
|
||||
let session_reader = gitbutler_core::sessions::Reader::open(gb_repository, &session)?;
|
||||
|
||||
let target_writer = target::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let target_writer =
|
||||
target::Writer::new(gb_repository, VirtualBranchesHandle::new(&project.gb_dir()))?;
|
||||
let reader = target::Reader::new(&session_reader);
|
||||
|
||||
target_writer.write_default(&default_target)?;
|
||||
|
@ -4,7 +4,11 @@ use std::{
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use gitbutler_core::virtual_branches::{branch, target, target::Target, BranchId};
|
||||
use gitbutler_core::virtual_branches::{
|
||||
branch,
|
||||
target::{self, Target},
|
||||
BranchId, VirtualBranchesHandle,
|
||||
};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::shared::{Case, Suite};
|
||||
@ -69,10 +73,12 @@ fn write() -> anyhow::Result<()> {
|
||||
sha: "0123456789abcdef0123456789abcdef01234567".parse().unwrap(),
|
||||
};
|
||||
|
||||
let branch_writer = branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let branch_writer =
|
||||
branch::Writer::new(gb_repository, VirtualBranchesHandle::new(&project.gb_dir()))?;
|
||||
branch_writer.write(&mut branch)?;
|
||||
|
||||
let target_writer = target::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let target_writer =
|
||||
target::Writer::new(gb_repository, VirtualBranchesHandle::new(&project.gb_dir()))?;
|
||||
target_writer.write(&branch.id, &target)?;
|
||||
|
||||
let root = gb_repository
|
||||
@ -161,9 +167,11 @@ fn should_update() -> anyhow::Result<()> {
|
||||
sha: "0123456789abcdef0123456789abcdef01234567".parse().unwrap(),
|
||||
};
|
||||
|
||||
let branch_writer = branch::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let branch_writer =
|
||||
branch::Writer::new(gb_repository, VirtualBranchesHandle::new(&project.gb_dir()))?;
|
||||
branch_writer.write(&mut branch)?;
|
||||
let target_writer = target::Writer::new(gb_repository, project.gb_dir())?;
|
||||
let target_writer =
|
||||
target::Writer::new(gb_repository, VirtualBranchesHandle::new(&project.gb_dir()))?;
|
||||
target_writer.write(&branch.id, &target)?;
|
||||
|
||||
let updated_target = Target {
|
||||
|
Loading…
Reference in New Issue
Block a user