Remove unnecessary VirtualBranchActions struct

This commit is contained in:
Kiril Videlov 2024-09-06 14:12:14 +02:00
parent 32d766c2d6
commit 95e946b8a1
No known key found for this signature in database
GPG Key ID: A4C733025427C471
35 changed files with 2333 additions and 2398 deletions

View File

@ -1,14 +1,12 @@
use super::r#virtual as branch; use super::r#virtual as vbranch;
use crate::branch::get_uncommited_files_raw; use crate::branch;
use crate::{ use crate::{
base::{ base,
get_base_branch_data, set_base_branch, set_target_push_remote, update_base_branch, base::BaseBranch,
BaseBranch,
},
branch::get_uncommited_files,
branch_manager::BranchManagerExt, branch_manager::BranchManagerExt,
file::RemoteBranchFile, file::RemoteBranchFile,
remote::{get_branch_data, list_local_branches, RemoteBranch, RemoteBranchData}, remote,
remote::{RemoteBranch, RemoteBranchData},
VirtualBranchesExt, VirtualBranchesExt,
}; };
use anyhow::{Context, Result}; use anyhow::{Context, Result};
@ -28,12 +26,7 @@ use gitbutler_repo::{RepoActionsExt, RepositoryExt};
use std::path::PathBuf; use std::path::PathBuf;
use tracing::instrument; use tracing::instrument;
#[derive(Clone, Copy, Default)]
pub struct VirtualBranchActions;
impl VirtualBranchActions {
pub fn create_commit( pub fn create_commit(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
message: &str, message: &str,
@ -41,12 +34,11 @@ impl VirtualBranchActions {
run_hooks: bool, run_hooks: bool,
) -> Result<git2::Oid> { ) -> Result<git2::Oid> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Creating a commit requires open workspace mode")?;
.context("Creating a commit requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let snapshot_tree = ctx.project().prepare_snapshot(guard.read_permission()); let snapshot_tree = ctx.project().prepare_snapshot(guard.read_permission());
let result = let result =
branch::commit(&ctx, branch_id, message, ownership, run_hooks).map_err(Into::into); vbranch::commit(&ctx, branch_id, message, ownership, run_hooks).map_err(Into::into);
let _ = snapshot_tree.and_then(|snapshot_tree| { let _ = snapshot_tree.and_then(|snapshot_tree| {
ctx.project().snapshot_commit_creation( ctx.project().snapshot_commit_creation(
snapshot_tree, snapshot_tree,
@ -59,41 +51,35 @@ impl VirtualBranchActions {
result result
} }
pub fn can_apply_remote_branch( pub fn can_apply_remote_branch(project: &Project, branch_name: &RemoteRefname) -> Result<bool> {
&self,
project: &Project,
branch_name: &RemoteRefname,
) -> Result<bool> {
let ctx = CommandContext::open(project)?; let ctx = CommandContext::open(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx)
.context("Testing branch mergability requires open workspace mode")?; .context("Testing branch mergability requires open workspace mode")?;
branch::is_remote_branch_mergeable(&ctx, branch_name).map_err(Into::into) vbranch::is_remote_branch_mergeable(&ctx, branch_name).map_err(Into::into)
} }
pub fn list_virtual_branches( pub fn list_virtual_branches(
&self,
project: &Project, project: &Project,
) -> Result<(Vec<branch::VirtualBranch>, Vec<gitbutler_diff::FileDiff>)> { ) -> Result<(Vec<vbranch::VirtualBranch>, Vec<gitbutler_diff::FileDiff>)> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx)
.context("Listing virtual branches requires open workspace mode")?; .context("Listing virtual branches requires open workspace mode")?;
branch::list_virtual_branches(&ctx, project.exclusive_worktree_access().write_permission()) vbranch::list_virtual_branches(&ctx, project.exclusive_worktree_access().write_permission())
.map_err(Into::into) .map_err(Into::into)
} }
pub fn list_virtual_branches_cached( pub fn list_virtual_branches_cached(
&self,
project: &Project, project: &Project,
worktree_changes: Option<DiffByPathMap>, worktree_changes: Option<DiffByPathMap>,
) -> Result<(Vec<branch::VirtualBranch>, Vec<gitbutler_diff::FileDiff>)> { ) -> Result<(Vec<vbranch::VirtualBranch>, Vec<gitbutler_diff::FileDiff>)> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx)
.context("Listing virtual branches requires open workspace mode")?; .context("Listing virtual branches requires open workspace mode")?;
branch::list_virtual_branches_cached( vbranch::list_virtual_branches_cached(
&ctx, &ctx,
project.exclusive_worktree_access().write_permission(), project.exclusive_worktree_access().write_permission(),
worktree_changes, worktree_changes,
@ -101,14 +87,9 @@ impl VirtualBranchActions {
.map_err(Into::into) .map_err(Into::into)
} }
pub fn create_virtual_branch( pub fn create_virtual_branch(project: &Project, create: &BranchCreateRequest) -> Result<BranchId> {
&self,
project: &Project,
create: &BranchCreateRequest,
) -> Result<BranchId> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Creating a branch requires open workspace mode")?;
.context("Creating a branch requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let branch_manager = ctx.branch_manager(); let branch_manager = ctx.branch_manager();
let branch_id = branch_manager let branch_id = branch_manager
@ -120,12 +101,7 @@ impl VirtualBranchActions {
/// Deletes a local branch reference and it's associated virtual branch. /// Deletes a local branch reference and it's associated virtual branch.
/// If there is a virtual branch and it is applied, this function will return an error. /// If there is a virtual branch and it is applied, this function will return an error.
/// If there is no such local reference, this function will return an error. /// If there is no such local reference, this function will return an error.
pub fn delete_local_branch( pub fn delete_local_branch(project: &Project, refname: &Refname, given_name: String) -> Result<()> {
&self,
project: &Project,
refname: &Refname,
given_name: String,
) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
let repo = ctx.repository(); let repo = ctx.repository();
let handle = ctx.project().virtual_branches(); let handle = ctx.project().virtual_branches();
@ -157,11 +133,10 @@ impl VirtualBranchActions {
#[instrument(skip(project), err(Debug))] #[instrument(skip(project), err(Debug))]
pub fn get_base_branch_data(project: &Project) -> Result<BaseBranch> { pub fn get_base_branch_data(project: &Project) -> Result<BaseBranch> {
let ctx = CommandContext::open(project)?; let ctx = CommandContext::open(project)?;
get_base_branch_data(&ctx) base::get_base_branch_data(&ctx)
} }
pub fn list_remote_commit_files( pub fn list_remote_commit_files(
&self,
project: &Project, project: &Project,
commit_oid: git2::Oid, commit_oid: git2::Oid,
) -> Result<Vec<RemoteBranchFile>> { ) -> Result<Vec<RemoteBranchFile>> {
@ -169,26 +144,22 @@ impl VirtualBranchActions {
crate::file::list_remote_commit_files(ctx.repository(), commit_oid).map_err(Into::into) crate::file::list_remote_commit_files(ctx.repository(), commit_oid).map_err(Into::into)
} }
pub fn set_base_branch( pub fn set_base_branch(project: &Project, target_branch: &RemoteRefname) -> Result<BaseBranch> {
&self,
project: &Project,
target_branch: &RemoteRefname,
) -> Result<BaseBranch> {
let ctx = CommandContext::open(project)?; let ctx = CommandContext::open(project)?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let _ = ctx.project().create_snapshot( let _ = ctx.project().create_snapshot(
SnapshotDetails::new(OperationKind::SetBaseBranch), SnapshotDetails::new(OperationKind::SetBaseBranch),
guard.write_permission(), guard.write_permission(),
); );
set_base_branch(&ctx, target_branch) base::set_base_branch(&ctx, target_branch)
} }
pub fn set_target_push_remote(&self, project: &Project, push_remote: &str) -> Result<()> { pub fn set_target_push_remote(project: &Project, push_remote: &str) -> Result<()> {
let ctx = CommandContext::open(project)?; let ctx = CommandContext::open(project)?;
set_target_push_remote(&ctx, push_remote) base::set_target_push_remote(&ctx, push_remote)
} }
pub fn integrate_upstream_commits(&self, project: &Project, branch_id: BranchId) -> Result<()> { pub fn integrate_upstream_commits(project: &Project, branch_id: BranchId) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx)
.context("Integrating upstream commits requires open workspace mode")?; .context("Integrating upstream commits requires open workspace mode")?;
@ -197,10 +168,10 @@ impl VirtualBranchActions {
SnapshotDetails::new(OperationKind::MergeUpstream), SnapshotDetails::new(OperationKind::MergeUpstream),
guard.write_permission(), guard.write_permission(),
); );
branch::integrate_upstream_commits(&ctx, branch_id).map_err(Into::into) vbranch::integrate_upstream_commits(&ctx, branch_id).map_err(Into::into)
} }
pub fn update_base_branch(&self, project: &Project) -> Result<Vec<ReferenceName>> { pub fn update_base_branch(project: &Project) -> Result<Vec<ReferenceName>> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx)
.context("Updating base branch requires open workspace mode")?; .context("Updating base branch requires open workspace mode")?;
@ -209,24 +180,19 @@ impl VirtualBranchActions {
SnapshotDetails::new(OperationKind::UpdateWorkspaceBase), SnapshotDetails::new(OperationKind::UpdateWorkspaceBase),
guard.write_permission(), guard.write_permission(),
); );
update_base_branch(&ctx, guard.write_permission()).map_err(Into::into) base::update_base_branch(&ctx, guard.write_permission()).map_err(Into::into)
} }
pub fn update_virtual_branch( pub fn update_virtual_branch(project: &Project, branch_update: BranchUpdateRequest) -> Result<()> {
&self,
project: &Project,
branch_update: BranchUpdateRequest,
) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Updating a branch requires open workspace mode")?;
.context("Updating a branch requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let snapshot_tree = ctx.project().prepare_snapshot(guard.read_permission()); let snapshot_tree = ctx.project().prepare_snapshot(guard.read_permission());
let old_branch = ctx let old_branch = ctx
.project() .project()
.virtual_branches() .virtual_branches()
.get_branch_in_workspace(branch_update.id)?; .get_branch_in_workspace(branch_update.id)?;
let result = branch::update_branch(&ctx, &branch_update); let result = vbranch::update_branch(&ctx, &branch_update);
let _ = snapshot_tree.and_then(|snapshot_tree| { let _ = snapshot_tree.and_then(|snapshot_tree| {
ctx.project().snapshot_branch_update( ctx.project().snapshot_branch_update(
snapshot_tree, snapshot_tree,
@ -241,7 +207,6 @@ impl VirtualBranchActions {
} }
pub fn update_branch_order( pub fn update_branch_order(
&self,
project: &Project, project: &Project,
branch_updates: Vec<BranchUpdateRequest>, branch_updates: Vec<BranchUpdateRequest>,
) -> Result<()> { ) -> Result<()> {
@ -254,13 +219,13 @@ impl VirtualBranchActions {
.virtual_branches() .virtual_branches()
.get_branch_in_workspace(branch_update.id)?; .get_branch_in_workspace(branch_update.id)?;
if branch_update.order != Some(branch.order) { if branch_update.order != Some(branch.order) {
branch::update_branch(&ctx, &branch_update)?; vbranch::update_branch(&ctx, &branch_update)?;
} }
} }
Ok(()) Ok(())
} }
pub fn delete_virtual_branch(&self, project: &Project, branch_id: BranchId) -> Result<()> { pub fn delete_virtual_branch(project: &Project, branch_id: BranchId) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx)
.context("Deleting a branch order requires open workspace mode")?; .context("Deleting a branch order requires open workspace mode")?;
@ -271,11 +236,7 @@ impl VirtualBranchActions {
branch_manager.delete_branch(branch_id, guard.write_permission(), &target_commit) branch_manager.delete_branch(branch_id, guard.write_permission(), &target_commit)
} }
pub fn unapply_ownership( pub fn unapply_ownership(project: &Project, ownership: &BranchOwnershipClaims) -> Result<()> {
&self,
project: &Project,
ownership: &BranchOwnershipClaims,
) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx).context("Unapply a patch requires open workspace mode")?; assure_open_workspace_mode(&ctx).context("Unapply a patch requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
@ -283,46 +244,37 @@ impl VirtualBranchActions {
SnapshotDetails::new(OperationKind::DiscardHunk), SnapshotDetails::new(OperationKind::DiscardHunk),
guard.write_permission(), guard.write_permission(),
); );
branch::unapply_ownership(&ctx, ownership, guard.write_permission()).map_err(Into::into) vbranch::unapply_ownership(&ctx, ownership, guard.write_permission()).map_err(Into::into)
} }
pub fn reset_files( pub fn reset_files(project: &Project, branch_id: BranchId, files: &[PathBuf]) -> Result<()> {
&self,
project: &Project,
branch_id: BranchId,
files: &[PathBuf],
) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Resetting a file requires open workspace mode")?;
.context("Resetting a file requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let _ = ctx.project().create_snapshot( let _ = ctx.project().create_snapshot(
SnapshotDetails::new(OperationKind::DiscardFile), SnapshotDetails::new(OperationKind::DiscardFile),
guard.write_permission(), guard.write_permission(),
); );
branch::reset_files(&ctx, branch_id, files, guard.write_permission()).map_err(Into::into) vbranch::reset_files(&ctx, branch_id, files, guard.write_permission()).map_err(Into::into)
} }
pub fn amend( pub fn amend(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
ownership: &BranchOwnershipClaims, ownership: &BranchOwnershipClaims,
) -> Result<git2::Oid> { ) -> Result<git2::Oid> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Amending a commit requires open workspace mode")?;
.context("Amending a commit requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let _ = ctx.project().create_snapshot( let _ = ctx.project().create_snapshot(
SnapshotDetails::new(OperationKind::AmendCommit), SnapshotDetails::new(OperationKind::AmendCommit),
guard.write_permission(), guard.write_permission(),
); );
branch::amend(&ctx, branch_id, commit_oid, ownership) vbranch::amend(&ctx, branch_id, commit_oid, ownership)
} }
pub fn move_commit_file( pub fn move_commit_file(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
from_commit_oid: git2::Oid, from_commit_oid: git2::Oid,
@ -330,30 +282,22 @@ impl VirtualBranchActions {
ownership: &BranchOwnershipClaims, ownership: &BranchOwnershipClaims,
) -> Result<git2::Oid> { ) -> Result<git2::Oid> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Amending a commit requires open workspace mode")?;
.context("Amending a commit requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let _ = ctx.project().create_snapshot( let _ = ctx.project().create_snapshot(
SnapshotDetails::new(OperationKind::MoveCommitFile), SnapshotDetails::new(OperationKind::MoveCommitFile),
guard.write_permission(), guard.write_permission(),
); );
branch::move_commit_file(&ctx, branch_id, from_commit_oid, to_commit_oid, ownership) vbranch::move_commit_file(&ctx, branch_id, from_commit_oid, to_commit_oid, ownership)
.map_err(Into::into) .map_err(Into::into)
} }
pub fn undo_commit( pub fn undo_commit(project: &Project, branch_id: BranchId, commit_oid: git2::Oid) -> Result<()> {
&self,
project: &Project,
branch_id: BranchId,
commit_oid: git2::Oid,
) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Undoing a commit requires open workspace mode")?;
.context("Undoing a commit requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let snapshot_tree = ctx.project().prepare_snapshot(guard.read_permission()); let snapshot_tree = ctx.project().prepare_snapshot(guard.read_permission());
let result: Result<()> = let result: Result<()> = vbranch::undo_commit(&ctx, branch_id, commit_oid).map_err(Into::into);
branch::undo_commit(&ctx, branch_id, commit_oid).map_err(Into::into);
let _ = snapshot_tree.and_then(|snapshot_tree| { let _ = snapshot_tree.and_then(|snapshot_tree| {
ctx.project().snapshot_commit_undo( ctx.project().snapshot_commit_undo(
snapshot_tree, snapshot_tree,
@ -366,7 +310,6 @@ impl VirtualBranchActions {
} }
pub fn insert_blank_commit( pub fn insert_blank_commit(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
@ -380,11 +323,10 @@ impl VirtualBranchActions {
SnapshotDetails::new(OperationKind::InsertBlankCommit), SnapshotDetails::new(OperationKind::InsertBlankCommit),
guard.write_permission(), guard.write_permission(),
); );
branch::insert_blank_commit(&ctx, branch_id, commit_oid, offset).map_err(Into::into) vbranch::insert_blank_commit(&ctx, branch_id, commit_oid, offset).map_err(Into::into)
} }
pub fn create_change_reference( pub fn create_change_reference(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
name: ReferenceName, name: ReferenceName,
@ -396,7 +338,6 @@ impl VirtualBranchActions {
} }
pub fn push_change_reference( pub fn push_change_reference(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
name: ReferenceName, name: ReferenceName,
@ -407,7 +348,6 @@ impl VirtualBranchActions {
} }
pub fn update_change_reference( pub fn update_change_reference(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
name: ReferenceName, name: ReferenceName,
@ -418,45 +358,37 @@ impl VirtualBranchActions {
} }
pub fn reorder_commit( pub fn reorder_commit(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
offset: i32, offset: i32,
) -> Result<()> { ) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Reordering a commit requires open workspace mode")?;
.context("Reordering a commit requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let _ = ctx.project().create_snapshot( let _ = ctx.project().create_snapshot(
SnapshotDetails::new(OperationKind::ReorderCommit), SnapshotDetails::new(OperationKind::ReorderCommit),
guard.write_permission(), guard.write_permission(),
); );
branch::reorder_commit(&ctx, branch_id, commit_oid, offset).map_err(Into::into) vbranch::reorder_commit(&ctx, branch_id, commit_oid, offset).map_err(Into::into)
} }
pub fn reset_virtual_branch( pub fn reset_virtual_branch(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
target_commit_oid: git2::Oid, target_commit_oid: git2::Oid,
) -> Result<()> { ) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Resetting a branch requires open workspace mode")?;
.context("Resetting a branch requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let _ = ctx.project().create_snapshot( let _ = ctx.project().create_snapshot(
SnapshotDetails::new(OperationKind::UndoCommit), SnapshotDetails::new(OperationKind::UndoCommit),
guard.write_permission(), guard.write_permission(),
); );
branch::reset_branch(&ctx, branch_id, target_commit_oid).map_err(Into::into) vbranch::reset_branch(&ctx, branch_id, target_commit_oid).map_err(Into::into)
} }
pub fn convert_to_real_branch( pub fn convert_to_real_branch(project: &Project, branch_id: BranchId) -> Result<ReferenceName> {
&self,
project: &Project,
branch_id: BranchId,
) -> Result<ReferenceName> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx)
.context("Converting branch to a real branch requires open workspace mode")?; .context("Converting branch to a real branch requires open workspace mode")?;
@ -477,51 +409,38 @@ impl VirtualBranchActions {
} }
pub fn push_virtual_branch( pub fn push_virtual_branch(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
with_force: bool, with_force: bool,
askpass: Option<Option<BranchId>>, askpass: Option<Option<BranchId>>,
) -> Result<()> { ) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Pushing a branch requires open workspace mode")?;
.context("Pushing a branch requires open workspace mode")?; vbranch::push(&ctx, branch_id, with_force, askpass)
branch::push(&ctx, branch_id, with_force, askpass)
} }
pub fn list_local_branches(project: Project) -> Result<Vec<RemoteBranch>> { pub fn list_local_branches(project: Project) -> Result<Vec<RemoteBranch>> {
let ctx = CommandContext::open(&project)?; let ctx = CommandContext::open(&project)?;
list_local_branches(&ctx) remote::list_local_branches(&ctx)
} }
pub fn get_remote_branch_data( pub fn get_remote_branch_data(project: &Project, refname: &Refname) -> Result<RemoteBranchData> {
&self,
project: &Project,
refname: &Refname,
) -> Result<RemoteBranchData> {
let ctx = CommandContext::open(project)?; let ctx = CommandContext::open(project)?;
get_branch_data(&ctx, refname) remote::get_branch_data(&ctx, refname)
} }
pub fn squash( pub fn squash(project: &Project, branch_id: BranchId, commit_oid: git2::Oid) -> Result<()> {
&self,
project: &Project,
branch_id: BranchId,
commit_oid: git2::Oid,
) -> Result<()> {
let ctx = open_with_verify(project)?; let ctx = open_with_verify(project)?;
assure_open_workspace_mode(&ctx) assure_open_workspace_mode(&ctx).context("Squashing a commit requires open workspace mode")?;
.context("Squashing a commit requires open workspace mode")?;
let mut guard = project.exclusive_worktree_access(); let mut guard = project.exclusive_worktree_access();
let _ = ctx.project().create_snapshot( let _ = ctx.project().create_snapshot(
SnapshotDetails::new(OperationKind::SquashCommit), SnapshotDetails::new(OperationKind::SquashCommit),
guard.write_permission(), guard.write_permission(),
); );
branch::squash(&ctx, branch_id, commit_oid).map_err(Into::into) vbranch::squash(&ctx, branch_id, commit_oid).map_err(Into::into)
} }
pub fn update_commit_message( pub fn update_commit_message(
&self,
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
@ -535,14 +454,10 @@ impl VirtualBranchActions {
SnapshotDetails::new(OperationKind::UpdateCommitMessage), SnapshotDetails::new(OperationKind::UpdateCommitMessage),
guard.write_permission(), guard.write_permission(),
); );
branch::update_commit_message(&ctx, branch_id, commit_oid, message).map_err(Into::into) vbranch::update_commit_message(&ctx, branch_id, commit_oid, message).map_err(Into::into)
} }
pub fn fetch_from_remotes( pub fn fetch_from_remotes(project: &Project, askpass: Option<String>) -> Result<FetchResult> {
&self,
project: &Project,
askpass: Option<String>,
) -> Result<FetchResult> {
let ctx = CommandContext::open(project)?; let ctx = CommandContext::open(project)?;
let remotes = ctx.repository().remotes_as_string()?; let remotes = ctx.repository().remotes_as_string()?;
@ -569,7 +484,6 @@ impl VirtualBranchActions {
} }
pub fn move_commit( pub fn move_commit(
&self,
project: &Project, project: &Project,
target_branch_id: BranchId, target_branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
@ -581,12 +495,11 @@ impl VirtualBranchActions {
SnapshotDetails::new(OperationKind::MoveCommit), SnapshotDetails::new(OperationKind::MoveCommit),
guard.write_permission(), guard.write_permission(),
); );
branch::move_commit(&ctx, target_branch_id, commit_oid).map_err(Into::into) vbranch::move_commit(&ctx, target_branch_id, commit_oid).map_err(Into::into)
} }
#[instrument(level = tracing::Level::DEBUG, skip(self, project), err(Debug))] #[instrument(level = tracing::Level::DEBUG, skip(project), err(Debug))]
pub fn create_virtual_branch_from_branch( pub fn create_virtual_branch_from_branch(
&self,
project: &Project, project: &Project,
branch: &Refname, branch: &Refname,
remote: Option<RemoteRefname>, remote: Option<RemoteRefname>,
@ -601,19 +514,18 @@ impl VirtualBranchActions {
.map_err(Into::into) .map_err(Into::into)
} }
pub fn get_uncommited_files(&self, project: &Project) -> Result<Vec<RemoteBranchFile>> { pub fn get_uncommited_files(project: &Project) -> Result<Vec<RemoteBranchFile>> {
let context = CommandContext::open(project)?; let context = CommandContext::open(project)?;
let guard = project.exclusive_worktree_access(); let guard = project.exclusive_worktree_access();
get_uncommited_files(&context, guard.read_permission()) branch::get_uncommited_files(&context, guard.read_permission())
} }
/// Like [`get_uncommited_files()`], but returns a type that can be re-used with /// Like [`get_uncommited_files()`], but returns a type that can be re-used with
/// [`crate::list_virtual_branches()`]. /// [`crate::list_virtual_branches()`].
pub fn get_uncommited_files_reusable(&self, project: &Project) -> Result<DiffByPathMap> { pub fn get_uncommited_files_reusable(project: &Project) -> Result<DiffByPathMap> {
let context = CommandContext::open(project)?; let context = CommandContext::open(project)?;
let guard = project.exclusive_worktree_access(); let guard = project.exclusive_worktree_access();
get_uncommited_files_raw(&context, guard.read_permission()) branch::get_uncommited_files_raw(&context, guard.read_permission())
}
} }
fn open_with_verify(project: &Project) -> Result<CommandContext> { fn open_with_verify(project: &Project) -> Result<CommandContext> {

View File

@ -1,5 +1,6 @@
use std::borrow::Cow; use std::borrow::Cow;
use crate::r#virtual as vbranch;
use anyhow::{anyhow, bail, Context, Result}; use anyhow::{anyhow, bail, Context, Result};
use gitbutler_branch::{self, dedup, Branch, BranchCreateRequest, BranchId, BranchOwnershipClaims}; use gitbutler_branch::{self, dedup, Branch, BranchCreateRequest, BranchId, BranchOwnershipClaims};
use gitbutler_commit::commit_headers::HasCommitHeaders; use gitbutler_commit::commit_headers::HasCommitHeaders;
@ -14,10 +15,9 @@ use tracing::instrument;
use super::BranchManager; use super::BranchManager;
use crate::{ use crate::{
conflicts::{self, RepoConflictsExt}, conflicts::{self, RepoConflictsExt},
ensure_selected_for_changes,
hunk::VirtualBranchHunk, hunk::VirtualBranchHunk,
integration::update_workspace_commit, integration::update_workspace_commit,
set_ownership, undo_commit, VirtualBranchesExt, VirtualBranchesExt,
}; };
impl BranchManager<'_> { impl BranchManager<'_> {
@ -118,7 +118,8 @@ impl BranchManager<'_> {
}; };
if let Some(ownership) = &create.ownership { if let Some(ownership) = &create.ownership {
set_ownership(&vb_state, &mut branch, ownership).context("failed to set ownership")?; vbranch::set_ownership(&vb_state, &mut branch, ownership)
.context("failed to set ownership")?;
} }
vb_state.set_branch(branch.clone())?; vb_state.set_branch(branch.clone())?;
@ -489,7 +490,8 @@ impl BranchManager<'_> {
// apply the branch // apply the branch
vb_state.set_branch(branch.clone())?; vb_state.set_branch(branch.clone())?;
ensure_selected_for_changes(&vb_state).context("failed to ensure selected for changes")?; vbranch::ensure_selected_for_changes(&vb_state)
.context("failed to ensure selected for changes")?;
// checkout the merge index // checkout the merge index
repo.checkout_index_builder(&mut merge_index) repo.checkout_index_builder(&mut merge_index)
.force() .force()
@ -505,7 +507,7 @@ impl BranchManager<'_> {
if let Some(headers) = potential_wip_commit.gitbutler_headers() { if let Some(headers) = potential_wip_commit.gitbutler_headers() {
if headers.change_id == wip_commit_to_unapply { if headers.change_id == wip_commit_to_unapply {
undo_commit(self.ctx, branch.id, branch.head)?; vbranch::undo_commit(self.ctx, branch.id, branch.head)?;
} }
} }

View File

@ -11,9 +11,10 @@ use gitbutler_repo::{RepoActionsExt, RepositoryExt};
use tracing::instrument; use tracing::instrument;
use super::BranchManager; use super::BranchManager;
use crate::r#virtual as vbranch;
use crate::{ use crate::{
conflicts::{self}, conflicts::{self},
ensure_selected_for_changes, get_applied_status, get_applied_status,
hunk::VirtualBranchHunk, hunk::VirtualBranchHunk,
VirtualBranchesExt, VirtualBranchesExt,
}; };
@ -47,7 +48,8 @@ impl BranchManager<'_> {
vb_state.update_ordering()?; vb_state.update_ordering()?;
// Ensure we still have a default target // Ensure we still have a default target
ensure_selected_for_changes(&vb_state).context("failed to ensure selected for changes")?; vbranch::ensure_selected_for_changes(&vb_state)
.context("failed to ensure selected for changes")?;
crate::integration::update_workspace_commit(&vb_state, self.ctx)?; crate::integration::update_workspace_commit(&vb_state, self.ctx)?;
@ -132,7 +134,8 @@ impl BranchManager<'_> {
self.ctx.delete_branch_reference(&branch)?; self.ctx.delete_branch_reference(&branch)?;
ensure_selected_for_changes(&vb_state).context("failed to ensure selected for changes")?; vbranch::ensure_selected_for_changes(&vb_state)
.context("failed to ensure selected for changes")?;
Ok(()) Ok(())
} }

View File

@ -1,9 +1,27 @@
//! GitButler internal library containing functionality related to branches, i.e. the virtual branches implementation //! GitButler internal library containing functionality related to branches, i.e. the virtual branches implementation
mod actions; mod actions;
pub use actions::VirtualBranchActions; // This is our API
pub use actions::{
amend, can_apply_remote_branch, convert_to_real_branch, create_change_reference, create_commit,
create_virtual_branch, create_virtual_branch_from_branch, delete_local_branch,
delete_virtual_branch, fetch_from_remotes, get_base_branch_data, get_remote_branch_data,
get_uncommited_files, get_uncommited_files_reusable, insert_blank_commit,
integrate_upstream_commits, list_local_branches, list_remote_commit_files,
list_virtual_branches, list_virtual_branches_cached, move_commit, move_commit_file,
push_change_reference, push_virtual_branch, reorder_commit, reset_files, reset_virtual_branch,
set_base_branch, set_target_push_remote, squash, unapply_ownership, undo_commit,
update_base_branch, update_branch_order, update_change_reference, update_commit_message,
update_virtual_branch,
};
mod r#virtual; mod r#virtual;
pub use r#virtual::*; pub use r#virtual::{BranchStatus, VirtualBranch, VirtualBranchHunksByPathMap, VirtualBranches};
/// Avoid using these!
/// This was previously `pub use r#virtual::*;`
pub mod internal {
pub use super::r#virtual::*;
pub use super::remote::list_local_branches;
}
mod branch_manager; mod branch_manager;
pub use branch_manager::{BranchManager, BranchManagerExt}; pub use branch_manager::{BranchManager, BranchManagerExt};
@ -18,7 +36,7 @@ mod file;
pub use file::{Get, RemoteBranchFile}; pub use file::{Get, RemoteBranchFile};
mod remote; mod remote;
pub use remote::{list_local_branches, RemoteBranch, RemoteBranchData, RemoteCommit}; pub use remote::{RemoteBranch, RemoteBranchData, RemoteCommit};
pub mod conflicts; pub mod conflicts;

View File

@ -16,9 +16,7 @@ use gitbutler_branch::{
BranchCreateRequest, BranchOwnershipClaims, BranchUpdateRequest, Target, VirtualBranchesHandle, BranchCreateRequest, BranchOwnershipClaims, BranchUpdateRequest, Target, VirtualBranchesHandle,
}; };
use gitbutler_branch_actions::{ use gitbutler_branch_actions::{
commit, get_applied_status, integrate_upstream_commits, is_remote_branch_mergeable, get_applied_status, internal, update_workspace_commit, verify_branch, BranchManagerExt, Get,
list_virtual_branches, unapply_ownership, update_branch, update_workspace_commit,
verify_branch, BranchManagerExt, Get,
}; };
use gitbutler_commit::{commit_ext::CommitExt, commit_headers::CommitHeadersV2}; use gitbutler_commit::{commit_ext::CommitExt, commit_headers::CommitHeadersV2};
use gitbutler_reference::{Refname, RemoteRefname}; use gitbutler_reference::{Refname, RemoteRefname};
@ -48,16 +46,16 @@ fn commit_on_branch_then_change_file_then_get_status() -> Result<()> {
"line0\nline1\nline2\nline3\nline4\n", "line0\nline1\nline2\nline3\nline4\n",
)?; )?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches[0]; let branch = &branches[0];
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
assert_eq!(branch.commits.len(), 0); assert_eq!(branch.commits.len(), 0);
// commit // commit
commit(ctx, branch1_id, "test commit", None, false)?; internal::commit(ctx, branch1_id, "test commit", None, false)?;
// status (no files) // status (no files)
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches[0]; let branch = &branches[0];
assert_eq!(branch.files.len(), 0); assert_eq!(branch.files.len(), 0);
assert_eq!(branch.commits.len(), 1); assert_eq!(branch.commits.len(), 1);
@ -68,7 +66,7 @@ fn commit_on_branch_then_change_file_then_get_status() -> Result<()> {
)?; )?;
// should have just the last change now, the other line is committed // should have just the last change now, the other line is committed
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches[0]; let branch = &branches[0];
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
assert_eq!(branch.commits.len(), 1); assert_eq!(branch.commits.len(), 1);
@ -127,7 +125,7 @@ fn track_binary_files() -> Result<()> {
let mut file = std::fs::File::create(Path::new(&project.path).join("image.bin"))?; let mut file = std::fs::File::create(Path::new(&project.path).join("image.bin"))?;
file.write_all(&image_data)?; file.write_all(&image_data)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches[0]; let branch = &branches[0];
assert_eq!(branch.files.len(), 2); assert_eq!(branch.files.len(), 2);
let img_file = &branch let img_file = &branch
@ -144,10 +142,10 @@ fn track_binary_files() -> Result<()> {
); );
// commit // commit
commit(ctx, branch1_id, "test commit", None, false)?; internal::commit(ctx, branch1_id, "test commit", None, false)?;
// status (no files) // status (no files)
let (branches, _) = list_virtual_branches(ctx, guard.write_permission()).unwrap(); let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission()).unwrap();
let commit_id = &branches[0].commits[0].id; let commit_id = &branches[0].commits[0].id;
let commit_obj = ctx.repository().find_commit(commit_id.to_owned())?; let commit_obj = ctx.repository().find_commit(commit_id.to_owned())?;
let tree = commit_obj.tree()?; let tree = commit_obj.tree()?;
@ -168,9 +166,9 @@ fn track_binary_files() -> Result<()> {
file.write_all(&image_data)?; file.write_all(&image_data)?;
// commit // commit
commit(ctx, branch1_id, "test commit", None, false)?; internal::commit(ctx, branch1_id, "test commit", None, false)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission()).unwrap(); let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission()).unwrap();
let commit_id = &branches[0].commits[0].id; let commit_id = &branches[0].commits[0].id;
// get tree from commit_id // get tree from commit_id
let commit_obj = ctx.repository().find_commit(commit_id.to_owned())?; let commit_obj = ctx.repository().find_commit(commit_id.to_owned())?;
@ -335,7 +333,7 @@ fn hunk_expantion() -> Result<()> {
assert_eq!(files_by_branch_id[&branch2_id].len(), 0); assert_eq!(files_by_branch_id[&branch2_id].len(), 0);
// even though selected branch has changed // even though selected branch has changed
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch1_id, id: branch1_id,
@ -343,7 +341,7 @@ fn hunk_expantion() -> Result<()> {
..Default::default() ..Default::default()
}, },
)?; )?;
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch2_id, id: branch2_id,
@ -483,7 +481,7 @@ fn move_hunks_multiple_sources() -> Result<()> {
// assert_eq!(files_by_branch_id[&branch2_id][0].hunks.len(), 1); // assert_eq!(files_by_branch_id[&branch2_id][0].hunks.len(), 1);
assert_eq!(files_by_branch_id[&branch3_id].len(), 0); assert_eq!(files_by_branch_id[&branch3_id].len(), 0);
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch3_id, id: branch3_id,
@ -576,7 +574,7 @@ fn move_hunks_partial_explicitly() -> Result<()> {
// assert_eq!(files_by_branch_id[&branch1_id][0].hunks.len(), 2); // assert_eq!(files_by_branch_id[&branch1_id][0].hunks.len(), 2);
assert_eq!(files_by_branch_id[&branch2_id].len(), 0); assert_eq!(files_by_branch_id[&branch2_id].len(), 0);
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch2_id, id: branch2_id,
@ -828,7 +826,7 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
vb_state.set_branch(branch.clone())?; vb_state.set_branch(branch.clone())?;
// create the branch // create the branch
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let branch1 = &branches[0]; let branch1 = &branches[0];
assert_eq!( assert_eq!(
@ -840,9 +838,9 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
assert_eq!(branch1.commits.len(), 1); assert_eq!(branch1.commits.len(), 1);
// assert_eq!(branch1.upstream.as_ref().unwrap().commits.len(), 1); // assert_eq!(branch1.upstream.as_ref().unwrap().commits.len(), 1);
integrate_upstream_commits(ctx, branch1.id)?; internal::integrate_upstream_commits(ctx, branch1.id)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch1 = &branches[0]; let branch1 = &branches[0];
let contents = std::fs::read(Path::new(&project.path).join(file_path))?; let contents = std::fs::read(Path::new(&project.path).join(file_path))?;
@ -933,7 +931,7 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
branch.head = last_push; branch.head = last_push;
vb_state.set_branch(branch.clone())?; vb_state.set_branch(branch.clone())?;
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch.id, id: branch.id,
@ -944,16 +942,16 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
.unwrap(); .unwrap();
// create the branch // create the branch
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch1 = &branches[0]; let branch1 = &branches[0];
assert_eq!(branch1.files.len(), 1); assert_eq!(branch1.files.len(), 1);
assert_eq!(branch1.commits.len(), 1); assert_eq!(branch1.commits.len(), 1);
// assert_eq!(branch1.upstream.as_ref().unwrap().commits.len(), 1); // assert_eq!(branch1.upstream.as_ref().unwrap().commits.len(), 1);
integrate_upstream_commits(ctx, branch1.id)?; internal::integrate_upstream_commits(ctx, branch1.id)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch1 = &branches[0]; let branch1 = &branches[0];
let contents = std::fs::read(Path::new(&project.path).join(file_path))?; let contents = std::fs::read(Path::new(&project.path).join(file_path))?;
@ -974,13 +972,13 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
// make gb see the conflict resolution // make gb see the conflict resolution
update_workspace_commit(&vb_state, ctx)?; update_workspace_commit(&vb_state, ctx)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
// commit the merge resolution // commit the merge resolution
commit(ctx, branch1.id, "fix merge conflict", None, false)?; internal::commit(ctx, branch1.id, "fix merge conflict", None, false)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch1 = &branches[0]; let branch1 = &branches[0];
assert!(!branch1.conflicted); assert!(!branch1.conflicted);
assert_eq!(branch1.files.len(), 0); assert_eq!(branch1.files.len(), 0);
@ -1015,7 +1013,7 @@ fn unapply_ownership_partial() -> Result<()> {
.create_virtual_branch(&BranchCreateRequest::default(), guard.write_permission()) .create_virtual_branch(&BranchCreateRequest::default(), guard.write_permission())
.expect("failed to create virtual branch"); .expect("failed to create virtual branch");
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].ownership.claims.len(), 1); assert_eq!(branches[0].ownership.claims.len(), 1);
@ -1026,14 +1024,14 @@ fn unapply_ownership_partial() -> Result<()> {
"line1\nline2\nline3\nline4\nbranch1\n" "line1\nline2\nline3\nline4\nbranch1\n"
); );
unapply_ownership( internal::unapply_ownership(
ctx, ctx,
&"test.txt:2-6".parse().unwrap(), &"test.txt:2-6".parse().unwrap(),
guard.write_permission(), guard.write_permission(),
) )
.unwrap(); .unwrap();
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 0); assert_eq!(branches[0].files.len(), 0);
assert_eq!(branches[0].ownership.claims.len(), 0); assert_eq!(branches[0].ownership.claims.len(), 0);
@ -1078,7 +1076,7 @@ fn unapply_branch() -> Result<()> {
.expect("failed to create virtual branch") .expect("failed to create virtual branch")
.id; .id;
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch2_id, id: branch2_id,
@ -1095,7 +1093,7 @@ fn unapply_branch() -> Result<()> {
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?; let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
assert_eq!("line5\nline6\n", String::from_utf8(contents)?); assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
assert!(branch.active); assert!(branch.active);
@ -1109,7 +1107,7 @@ fn unapply_branch() -> Result<()> {
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?; let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
assert_eq!("line5\nline6\n", String::from_utf8(contents)?); assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
assert!(!branches.iter().any(|b| b.id == branch1_id)); assert!(!branches.iter().any(|b| b.id == branch1_id));
let branch_manager = ctx.branch_manager(); let branch_manager = ctx.branch_manager();
@ -1126,7 +1124,7 @@ fn unapply_branch() -> Result<()> {
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?; let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
assert_eq!("line5\nline6\n", String::from_utf8(contents)?); assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
// TODO: expect there to be 0 branches // TODO: expect there to be 0 branches
assert_eq!(branch.files.len(), 0); assert_eq!(branch.files.len(), 0);
@ -1165,7 +1163,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
.expect("failed to create virtual branch") .expect("failed to create virtual branch")
.id; .id;
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch2_id, id: branch2_id,
@ -1173,7 +1171,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
..Default::default() ..Default::default()
}, },
)?; )?;
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch3_id, id: branch3_id,
@ -1182,7 +1180,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
}, },
)?; )?;
list_virtual_branches(ctx, guard.write_permission()).unwrap(); internal::list_virtual_branches(ctx, guard.write_permission()).unwrap();
let branch_manager = ctx.branch_manager(); let branch_manager = ctx.branch_manager();
let real_branch_2 = let real_branch_2 =
@ -1257,7 +1255,7 @@ fn detect_mergeable_branch() -> Result<()> {
.expect("failed to create virtual branch") .expect("failed to create virtual branch")
.id; .id;
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch2_id, id: branch2_id,
@ -1344,13 +1342,13 @@ fn detect_mergeable_branch() -> Result<()> {
}; };
vb_state.set_branch(branch4.clone())?; vb_state.set_branch(branch4.clone())?;
let remotes = let remotes = gitbutler_branch_actions::internal::list_local_branches(ctx)
gitbutler_branch_actions::list_local_branches(ctx).expect("failed to list remotes"); .expect("failed to list remotes");
let _remote1 = &remotes let _remote1 = &remotes
.iter() .iter()
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch") .find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch")
.unwrap(); .unwrap();
assert!(!is_remote_branch_mergeable( assert!(!internal::is_remote_branch_mergeable(
ctx, ctx,
&"refs/remotes/origin/remote_branch".parse().unwrap() &"refs/remotes/origin/remote_branch".parse().unwrap()
) )
@ -1361,7 +1359,7 @@ fn detect_mergeable_branch() -> Result<()> {
.iter() .iter()
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch2") .find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch2")
.unwrap(); .unwrap();
assert!(is_remote_branch_mergeable( assert!(internal::is_remote_branch_mergeable(
ctx, ctx,
&"refs/remotes/origin/remote_branch2".parse().unwrap() &"refs/remotes/origin/remote_branch2".parse().unwrap()
) )
@ -1437,7 +1435,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
"file3\nversion2\n", "file3\nversion2\n",
)?; )?;
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch1_id, id: branch1_id,
@ -1447,7 +1445,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
}, },
)?; )?;
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch2_id, id: branch2_id,
@ -1457,7 +1455,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
}, },
)?; )?;
update_branch( internal::update_branch(
ctx, ctx,
&BranchUpdateRequest { &BranchUpdateRequest {
id: branch3_id, id: branch3_id,
@ -1468,10 +1466,10 @@ fn upstream_integrated_vbranch() -> Result<()> {
)?; )?;
// create a new virtual branch from the remote branch // create a new virtual branch from the remote branch
commit(ctx, branch1_id, "integrated commit", None, false)?; internal::commit(ctx, branch1_id, "integrated commit", None, false)?;
commit(ctx, branch2_id, "non-integrated commit", None, false)?; internal::commit(ctx, branch2_id, "non-integrated commit", None, false)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert!(branch1.commits.iter().any(|c| c.is_integrated)); assert!(branch1.commits.iter().any(|c| c.is_integrated));
@ -1517,7 +1515,7 @@ fn commit_same_hunk_twice() -> Result<()> {
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n", "line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
)?; )?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
@ -1525,9 +1523,9 @@ fn commit_same_hunk_twice() -> Result<()> {
assert_eq!(branch.commits.len(), 0); assert_eq!(branch.commits.len(), 0);
// commit // commit
commit(ctx, branch1_id, "first commit to test.txt", None, false)?; internal::commit(ctx, branch1_id, "first commit to test.txt", None, false)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 0, "no files expected"); assert_eq!(branch.files.len(), 0, "no files expected");
@ -1547,15 +1545,15 @@ fn commit_same_hunk_twice() -> Result<()> {
"line1\nPATCH1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n", "line1\nPATCH1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
)?; )?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1, "one file should be changed"); assert_eq!(branch.files.len(), 1, "one file should be changed");
assert_eq!(branch.commits.len(), 1, "commit is still there"); assert_eq!(branch.commits.len(), 1, "commit is still there");
commit(ctx, branch1_id, "second commit to test.txt", None, false)?; internal::commit(ctx, branch1_id, "second commit to test.txt", None, false)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!( assert_eq!(
@ -1599,7 +1597,7 @@ fn commit_same_file_twice() -> Result<()> {
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n", "line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
)?; )?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
@ -1607,9 +1605,9 @@ fn commit_same_file_twice() -> Result<()> {
assert_eq!(branch.commits.len(), 0); assert_eq!(branch.commits.len(), 0);
// commit // commit
commit(ctx, branch1_id, "first commit to test.txt", None, false)?; internal::commit(ctx, branch1_id, "first commit to test.txt", None, false)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 0, "no files expected"); assert_eq!(branch.files.len(), 0, "no files expected");
@ -1629,15 +1627,15 @@ fn commit_same_file_twice() -> Result<()> {
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n", "line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n",
)?; )?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1, "one file should be changed"); assert_eq!(branch.files.len(), 1, "one file should be changed");
assert_eq!(branch.commits.len(), 1, "commit is still there"); assert_eq!(branch.commits.len(), 1, "commit is still there");
commit(ctx, branch1_id, "second commit to test.txt", None, false)?; internal::commit(ctx, branch1_id, "second commit to test.txt", None, false)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!( assert_eq!(
@ -1681,7 +1679,7 @@ fn commit_partial_by_hunk() -> Result<()> {
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n", "line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n",
)?; )?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
@ -1689,7 +1687,7 @@ fn commit_partial_by_hunk() -> Result<()> {
assert_eq!(branch.commits.len(), 0); assert_eq!(branch.commits.len(), 0);
// commit // commit
commit( internal::commit(
ctx, ctx,
branch1_id, branch1_id,
"first commit to test.txt", "first commit to test.txt",
@ -1697,7 +1695,7 @@ fn commit_partial_by_hunk() -> Result<()> {
false, false,
)?; )?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
@ -1706,7 +1704,7 @@ fn commit_partial_by_hunk() -> Result<()> {
assert_eq!(branch.commits[0].files.len(), 1); assert_eq!(branch.commits[0].files.len(), 1);
assert_eq!(branch.commits[0].files[0].hunks.len(), 1); assert_eq!(branch.commits[0].files[0].hunks.len(), 1);
commit( internal::commit(
ctx, ctx,
branch1_id, branch1_id,
"second commit to test.txt", "second commit to test.txt",
@ -1714,7 +1712,7 @@ fn commit_partial_by_hunk() -> Result<()> {
false, false,
)?; )?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 0); assert_eq!(branch.files.len(), 0);
@ -1754,9 +1752,9 @@ fn commit_partial_by_file() -> Result<()> {
.id; .id;
// commit // commit
commit(ctx, branch1_id, "branch1 commit", None, false)?; internal::commit(ctx, branch1_id, "branch1 commit", None, false)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
// branch one test.txt has just the 1st and 3rd hunks applied // branch one test.txt has just the 1st and 3rd hunks applied
@ -1805,9 +1803,9 @@ fn commit_add_and_delete_files() -> Result<()> {
.id; .id;
// commit // commit
commit(ctx, branch1_id, "branch1 commit", None, false)?; internal::commit(ctx, branch1_id, "branch1 commit", None, false)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
// branch one test.txt has just the 1st and 3rd hunks applied // branch one test.txt has just the 1st and 3rd hunks applied
@ -1862,9 +1860,9 @@ fn commit_executable_and_symlinks() -> Result<()> {
.id; .id;
// commit // commit
commit(ctx, branch1_id, "branch1 commit", None, false)?; internal::commit(ctx, branch1_id, "branch1 commit", None, false)?;
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap(); let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
let commit = &branch1.commits[0].id; let commit = &branch1.commits[0].id;
@ -1960,7 +1958,7 @@ fn verify_branch_commits_to_workspace() -> Result<()> {
verify_branch(ctx, guard.write_permission()).unwrap(); verify_branch(ctx, guard.write_permission()).unwrap();
// one virtual branch with two commits was created // one virtual branch with two commits was created
let (virtual_branches, _) = list_virtual_branches(ctx, guard.write_permission())?; let (virtual_branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
assert_eq!(virtual_branches.len(), 1); assert_eq!(virtual_branches.len(), 1);
let branch = &virtual_branches.first().unwrap(); let branch = &virtual_branches.first().unwrap();
@ -2021,7 +2019,7 @@ fn pre_commit_hook_rejection() -> Result<()> {
git2_hooks::create_hook(ctx.repository(), git2_hooks::HOOK_PRE_COMMIT, hook); git2_hooks::create_hook(ctx.repository(), git2_hooks::HOOK_PRE_COMMIT, hook);
let res = commit(ctx, branch1_id, "test commit", None, true); let res = internal::commit(ctx, branch1_id, "test commit", None, true);
let err = res.unwrap_err(); let err = res.unwrap_err();
assert_eq!( assert_eq!(
@ -2064,7 +2062,7 @@ fn post_commit_hook() -> Result<()> {
assert!(!hook_ran_proof.exists()); assert!(!hook_ran_proof.exists());
commit(ctx, branch1_id, "test commit", None, true)?; internal::commit(ctx, branch1_id, "test commit", None, true)?;
assert!(hook_ran_proof.exists()); assert!(hook_ran_proof.exists());
@ -2100,7 +2098,7 @@ fn commit_msg_hook_rejection() -> Result<()> {
git2_hooks::create_hook(ctx.repository(), git2_hooks::HOOK_COMMIT_MSG, hook); git2_hooks::create_hook(ctx.repository(), git2_hooks::HOOK_COMMIT_MSG, hook);
let res = commit(ctx, branch1_id, "test commit", None, true); let res = internal::commit(ctx, branch1_id, "test commit", None, true);
let err = res.unwrap_err(); let err = res.unwrap_err();
assert_eq!( assert_eq!(

View File

@ -8,7 +8,6 @@ fn forcepush_allowed() {
repository, repository,
project_id, project_id,
project, project,
controller,
projects, projects,
.. ..
} = &Test::default(); } = &Test::default();
@ -20,8 +19,10 @@ fn forcepush_allowed() {
}) })
.unwrap(); .unwrap();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
projects projects
@ -31,30 +32,25 @@ fn forcepush_allowed() {
}) })
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit_id = controller let commit_id =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
{ {
// amend another hunk // amend another hunk
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
controller gitbutler_branch_actions::amend(project, branch_id, commit_id, &to_amend).unwrap();
.amend(project, branch_id, commit_id, &to_amend)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -72,20 +68,20 @@ fn forcepush_forbidden() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
controller gitbutler_branch_actions::update_virtual_branch(
.update_virtual_branch(
project, project,
BranchUpdateRequest { BranchUpdateRequest {
id: branch_id, id: branch_id,
@ -97,20 +93,17 @@ fn forcepush_forbidden() {
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit_oid = controller let commit_oid =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
{ {
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend)
.amend(project, branch_id, commit_oid, &to_amend)
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
"force-push is not allowed" "force-push is not allowed"
@ -123,26 +116,26 @@ fn non_locked_hunk() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit_oid = controller let commit_oid =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -156,12 +149,9 @@ fn non_locked_hunk() {
// amend another hunk // amend another hunk
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
controller gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend).unwrap();
.amend(project, branch_id, commit_oid, &to_amend)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -178,26 +168,26 @@ fn locked_hunk() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit_oid = controller let commit_oid =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -215,12 +205,9 @@ fn locked_hunk() {
// amend another hunk // amend another hunk
fs::write(repository.path().join("file.txt"), "more content").unwrap(); fs::write(repository.path().join("file.txt"), "more content").unwrap();
let to_amend: BranchOwnershipClaims = "file.txt:1-2".parse().unwrap(); let to_amend: BranchOwnershipClaims = "file.txt:1-2".parse().unwrap();
controller gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend).unwrap();
.amend(project, branch_id, commit_oid, &to_amend)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -242,26 +229,26 @@ fn non_existing_ownership() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit_oid = controller let commit_oid =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -275,8 +262,7 @@ fn non_existing_ownership() {
// amend non existing hunk // amend non existing hunk
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend)
.amend(project, branch_id, commit_oid, &to_amend)
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
"target ownership not found" "target ownership not found"

View File

@ -8,7 +8,6 @@ fn rebase_commit() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -23,22 +22,25 @@ fn rebase_commit() {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let mut branch1_id = { let mut branch1_id = {
// create a branch with some commited work // create a branch with some commited work
let branch1_id = controller let branch1_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("another_file.txt"), "virtual").unwrap(); fs::write(repository.path().join("another_file.txt"), "virtual").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch1_id, "virtual commit", None, false)
.create_commit(project, branch1_id, "virtual commit", None, false)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -50,9 +52,8 @@ fn rebase_commit() {
let unapplied_branch = { let unapplied_branch = {
// unapply first vbranch // unapply first vbranch
let unapplied_branch = controller let unapplied_branch =
.convert_to_real_branch(project, branch1_id) gitbutler_branch_actions::convert_to_real_branch(project, branch1_id).unwrap();
.unwrap();
assert_eq!( assert_eq!(
fs::read_to_string(repository.path().join("another_file.txt")).unwrap(), fs::read_to_string(repository.path().join("another_file.txt")).unwrap(),
@ -63,7 +64,7 @@ fn rebase_commit() {
"one" "one"
); );
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
Refname::from_str(&unapplied_branch).unwrap() Refname::from_str(&unapplied_branch).unwrap()
@ -71,10 +72,10 @@ fn rebase_commit() {
{ {
// fetch remote // fetch remote
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// branch is stil unapplied // branch is stil unapplied
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert_eq!( assert_eq!(
@ -89,12 +90,15 @@ fn rebase_commit() {
{ {
// apply first vbranch again // apply first vbranch again
branch1_id = controller branch1_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(project, &unapplied_branch, None) project,
&unapplied_branch,
None,
)
.unwrap(); .unwrap();
// it should be rebased // it should be rebased
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].files.len(), 0); assert_eq!(branches[0].files.len(), 0);
@ -119,7 +123,6 @@ fn rebase_work() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -132,18 +135,22 @@ fn rebase_work() {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let mut branch1_id = { let mut branch1_id = {
// make a branch with some work // make a branch with some work
let branch1_id = controller let branch1_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("another_file.txt"), "").unwrap(); fs::write(repository.path().join("another_file.txt"), "").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -155,11 +162,10 @@ fn rebase_work() {
let unapplied_branch = { let unapplied_branch = {
// unapply first vbranch // unapply first vbranch
let unapplied_branch = controller let unapplied_branch =
.convert_to_real_branch(project, branch1_id) gitbutler_branch_actions::convert_to_real_branch(project, branch1_id).unwrap();
.unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert!(!repository.path().join("another_file.txt").exists()); assert!(!repository.path().join("another_file.txt").exists());
@ -170,10 +176,10 @@ fn rebase_work() {
{ {
// fetch remote // fetch remote
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// first branch is stil unapplied // first branch is stil unapplied
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert!(!repository.path().join("another_file.txt").exists()); assert!(!repository.path().join("another_file.txt").exists());
@ -182,12 +188,15 @@ fn rebase_work() {
{ {
// apply first vbranch again // apply first vbranch again
branch1_id = controller branch1_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(project, &unapplied_branch, None) project,
&unapplied_branch,
None,
)
.unwrap(); .unwrap();
// workdir should be rebased, and work should be restored // workdir should be rebased, and work should be restored
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
// TODO: Should be 1 // TODO: Should be 1

View File

@ -4,27 +4,26 @@ use super::*;
fn unapply_with_data() { fn unapply_with_data() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
controller gitbutler_branch_actions::convert_to_real_branch(project, branches[0].id).unwrap();
.convert_to_real_branch(project, branches[0].id)
.unwrap();
assert!(!repository.path().join("file.txt").exists()); assert!(!repository.path().join("file.txt").exists());
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
} }
@ -32,7 +31,6 @@ fn unapply_with_data() {
fn conflicting() { fn conflicting() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
@ -47,8 +45,10 @@ fn conflicting() {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let unapplied_branch = { let unapplied_branch = {
@ -56,7 +56,7 @@ fn conflicting() {
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap(); std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let branch = &branches[0]; let branch = &branches[0];
assert_eq!( assert_eq!(
@ -70,16 +70,15 @@ fn conflicting() {
"@@ -1 +1 @@\n-first\n\\ No newline at end of file\n+conflict\n\\ No newline at end of file\n" "@@ -1 +1 @@\n-first\n\\ No newline at end of file\n+conflict\n\\ No newline at end of file\n"
); );
let unapplied_branch = controller let unapplied_branch =
.convert_to_real_branch(project, branch.id) gitbutler_branch_actions::convert_to_real_branch(project, branch.id).unwrap();
.unwrap();
Refname::from_str(&unapplied_branch).unwrap() Refname::from_str(&unapplied_branch).unwrap()
}; };
{ {
// update base branch, causing conflict // update base branch, causing conflict
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
assert_eq!( assert_eq!(
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(), std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
@ -89,8 +88,11 @@ fn conflicting() {
let branch_id = { let branch_id = {
// apply branch, it should conflict // apply branch, it should conflict
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(project, &unapplied_branch, None) project,
&unapplied_branch,
None,
)
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
@ -101,7 +103,7 @@ fn conflicting() {
let vb_state = VirtualBranchesHandle::new(project.gb_dir()); let vb_state = VirtualBranchesHandle::new(project.gb_dir());
let ctx = CommandContext::open(project).unwrap(); let ctx = CommandContext::open(project).unwrap();
update_workspace_commit(&vb_state, &ctx).unwrap(); update_workspace_commit(&vb_state, &ctx).unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let branch = &branches[0]; let branch = &branches[0];
@ -116,9 +118,7 @@ fn conflicting() {
{ {
// Converting the branch to a real branch should put us back in an unconflicted state // Converting the branch to a real branch should put us back in an unconflicted state
controller gitbutler_branch_actions::convert_to_real_branch(project, branch_id).unwrap();
.convert_to_real_branch(project, branch_id)
.unwrap();
assert_eq!( assert_eq!(
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(), std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
@ -129,27 +129,22 @@ fn conflicting() {
#[test] #[test]
fn delete_if_empty() { fn delete_if_empty() {
let Test { let Test { project, .. } = &Test::default();
gitbutler_branch_actions::set_base_branch(
project, project,
controller, &"refs/remotes/origin/master".parse().unwrap(),
.. )
} = &Test::default();
controller
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.unwrap(); .unwrap();
controller gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
controller gitbutler_branch_actions::convert_to_real_branch(project, branches[0].id).unwrap();
.convert_to_real_branch(project, branches[0].id)
.unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
} }

View File

@ -8,40 +8,38 @@ use super::*;
fn should_lock_updated_hunks() { fn should_lock_updated_hunks() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
{ {
// by default, hunks are not locked // by default, hunks are not locked
repository.write_file("file.txt", &["content".to_string()]); repository.write_file("file.txt", &["content".to_string()]);
let branch = get_virtual_branch(controller, project, branch_id); let branch = get_virtual_branch(project, branch_id);
assert_eq!(branch.files.len(), 1); assert_eq!(branch.files.len(), 1);
assert_eq!(branch.files[0].path.display().to_string(), "file.txt"); assert_eq!(branch.files[0].path.display().to_string(), "file.txt");
assert_eq!(branch.files[0].hunks.len(), 1); assert_eq!(branch.files[0].hunks.len(), 1);
assert!(!branch.files[0].hunks[0].locked); assert!(!branch.files[0].hunks[0].locked);
} }
controller gitbutler_branch_actions::create_commit(project, branch_id, "test", None, false).unwrap();
.create_commit(project, branch_id, "test", None, false)
.unwrap();
{ {
// change in the committed hunks leads to hunk locking // change in the committed hunks leads to hunk locking
repository.write_file("file.txt", &["updated content".to_string()]); repository.write_file("file.txt", &["updated content".to_string()]);
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -58,7 +56,6 @@ fn should_lock_updated_hunks() {
fn should_reset_into_same_branch() { fn should_reset_into_same_branch() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
@ -66,16 +63,16 @@ fn should_reset_into_same_branch() {
let mut lines = repository.gen_file("file.txt", 7); let mut lines = repository.gen_file("file.txt", 7);
commit_and_push_initial(repository); commit_and_push_initial(repository);
let base_branch = controller let base_branch = gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let branch_2_id = controller let branch_2_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
@ -87,16 +84,20 @@ fn should_reset_into_same_branch() {
lines[0] = "change 1".to_string(); lines[0] = "change 1".to_string();
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
controller gitbutler_branch_actions::create_commit(
.create_commit(project, branch_2_id, "commit to branch 2", None, false) project,
branch_2_id,
"commit to branch 2",
None,
false,
)
.unwrap(); .unwrap();
let files = get_virtual_branch(controller, project, branch_2_id).files; let files = get_virtual_branch(project, branch_2_id).files;
assert_eq!(files.len(), 0); assert_eq!(files.len(), 0);
// Set target to branch 1 and verify the file resets into branch 2. // Set target to branch 1 and verify the file resets into branch 2.
controller gitbutler_branch_actions::update_virtual_branch(
.update_virtual_branch(
project, project,
BranchUpdateRequest { BranchUpdateRequest {
id: branch_2_id, id: branch_2_id,
@ -106,11 +107,10 @@ fn should_reset_into_same_branch() {
) )
.unwrap(); .unwrap();
controller gitbutler_branch_actions::reset_virtual_branch(project, branch_2_id, base_branch.base_sha)
.reset_virtual_branch(project, branch_2_id, base_branch.base_sha)
.unwrap(); .unwrap();
let files = get_virtual_branch(controller, project, branch_2_id).files; let files = get_virtual_branch(project, branch_2_id).files;
assert_eq!(files.len(), 1); assert_eq!(files.len(), 1);
} }
@ -119,13 +119,8 @@ fn commit_and_push_initial(repository: &TestProject) {
repository.push(); repository.push();
} }
fn get_virtual_branch( fn get_virtual_branch(project: &Project, branch_id: Id<Branch>) -> VirtualBranch {
controller: &VirtualBranchActions, gitbutler_branch_actions::list_virtual_branches(project)
project: &Project,
branch_id: Id<Branch>,
) -> VirtualBranch {
controller
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()

View File

@ -8,31 +8,29 @@ fn integration() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_name = { let branch_name = {
// make a remote branch // make a remote branch
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "first\n").unwrap(); std::fs::write(repository.path().join("file.txt"), "first\n").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "first", None, false).unwrap();
.create_commit(project, branch_id, "first", None, false) gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.unwrap();
controller
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -41,25 +39,21 @@ fn integration() {
let name = branch.upstream.unwrap().name; let name = branch.upstream.unwrap().name;
controller gitbutler_branch_actions::delete_virtual_branch(project, branch_id).unwrap();
.delete_virtual_branch(project, branch_id)
.unwrap();
name name
}; };
// checkout a existing remote branch // checkout a existing remote branch
let branch_id = controller let branch_id =
.create_virtual_branch_from_branch(project, &branch_name, None) gitbutler_branch_actions::create_virtual_branch_from_branch(project, &branch_name, None)
.unwrap(); .unwrap();
{ {
// add a commit // add a commit
std::fs::write(repository.path().join("file.txt"), "first\nsecond").unwrap(); std::fs::write(repository.path().join("file.txt"), "first\nsecond").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "second", None, false).unwrap();
.create_commit(project, branch_id, "second", None, false)
.unwrap();
} }
{ {
@ -73,12 +67,9 @@ fn integration() {
{ {
// merge branch into master // merge branch into master
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -95,10 +86,9 @@ fn integration() {
{ {
// should mark commits as integrated // should mark commits as integrated
controller.fetch_from_remotes(project, None).unwrap(); gitbutler_branch_actions::fetch_from_remotes(project, None).unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -117,7 +107,6 @@ fn no_conflicts() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -131,22 +120,23 @@ fn no_conflicts() {
repository.checkout(&"refs/heads/master".parse().unwrap()); repository.checkout(&"refs/heads/master".parse().unwrap());
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert!(branches.is_empty()); assert!(branches.is_empty());
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(
project, project,
&"refs/remotes/origin/branch".parse().unwrap(), &"refs/remotes/origin/branch".parse().unwrap(),
None, None,
) )
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -158,7 +148,6 @@ fn conflicts_with_uncommited() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -172,29 +161,29 @@ fn conflicts_with_uncommited() {
repository.checkout(&"refs/heads/master".parse().unwrap()); repository.checkout(&"refs/heads/master".parse().unwrap());
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
// create a local branch that conflicts with remote // create a local branch that conflicts with remote
{ {
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap(); std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
}; };
// branch should be created unapplied, because of the conflict // branch should be created unapplied, because of the conflict
let new_branch_id = controller let new_branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(
project, project,
&"refs/remotes/origin/branch".parse().unwrap(), &"refs/remotes/origin/branch".parse().unwrap(),
None, None,
) )
.unwrap(); .unwrap();
let new_branch = controller let new_branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -210,7 +199,6 @@ fn conflicts_with_commited() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -224,33 +212,32 @@ fn conflicts_with_commited() {
repository.checkout(&"refs/heads/master".parse().unwrap()); repository.checkout(&"refs/heads/master".parse().unwrap());
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
// create a local branch that conflicts with remote // create a local branch that conflicts with remote
{ {
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap(); std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
controller gitbutler_branch_actions::create_commit(project, branches[0].id, "hej", None, false)
.create_commit(project, branches[0].id, "hej", None, false)
.unwrap(); .unwrap();
}; };
// branch should be created unapplied, because of the conflict // branch should be created unapplied, because of the conflict
let new_branch_id = controller let new_branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(
project, project,
&"refs/remotes/origin/branch".parse().unwrap(), &"refs/remotes/origin/branch".parse().unwrap(),
None, None,
) )
.unwrap(); .unwrap();
let new_branch = controller let new_branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -263,21 +250,18 @@ fn conflicts_with_commited() {
#[test] #[test]
fn from_default_target() { fn from_default_target() {
let Test { let Test { project, .. } = &Test::default();
project,
controller,
..
} = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
// branch should be created unapplied, because of the conflict // branch should be created unapplied, because of the conflict
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(
project, project,
&"refs/remotes/origin/master".parse().unwrap(), &"refs/remotes/origin/master".parse().unwrap(),
None None
@ -290,21 +274,18 @@ fn from_default_target() {
#[test] #[test]
fn from_non_existent_branch() { fn from_non_existent_branch() {
let Test { let Test { project, .. } = &Test::default();
project,
controller,
..
} = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
// branch should be created unapplied, because of the conflict // branch should be created unapplied, because of the conflict
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(
project, project,
&"refs/remotes/origin/branch".parse().unwrap(), &"refs/remotes/origin/branch".parse().unwrap(),
None None
@ -320,7 +301,6 @@ fn from_state_remote_branch() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -339,19 +319,20 @@ fn from_state_remote_branch() {
repository.push(); repository.push();
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(
project, project,
&"refs/remotes/origin/branch".parse().unwrap(), &"refs/remotes/origin/branch".parse().unwrap(),
None, None,
) )
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);

View File

@ -6,25 +6,24 @@ use super::*;
fn should_unapply_diff() { fn should_unapply_diff() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
// write some // write some
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
controller gitbutler_branch_actions::delete_virtual_branch(project, branches[0].id).unwrap();
.delete_virtual_branch(project, branches[0].id)
.unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert!(!repository.path().join("file.txt").exists()); assert!(!repository.path().join("file.txt").exists());
@ -40,17 +39,17 @@ fn should_unapply_diff() {
fn should_remove_reference() { fn should_remove_reference() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let id = controller let id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
@ -59,9 +58,9 @@ fn should_remove_reference() {
) )
.unwrap(); .unwrap();
controller.delete_virtual_branch(project, id).unwrap(); gitbutler_branch_actions::delete_virtual_branch(project, id).unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
let refnames = repository let refnames = repository

View File

@ -7,33 +7,33 @@ fn twice() {
let test_project = TestProject::default(); let test_project = TestProject::default();
let controller = VirtualBranchActions {};
{ {
let project = projects let project = projects
.add(test_project.path()) .add(test_project.path())
.expect("failed to add project"); .expect("failed to add project");
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(&project, &"refs/remotes/origin/master".parse().unwrap()) &project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
assert!(controller assert!(gitbutler_branch_actions::list_virtual_branches(&project)
.list_virtual_branches(&project)
.unwrap() .unwrap()
.0 .0
.is_empty()); .is_empty());
projects.delete(project.id).unwrap(); projects.delete(project.id).unwrap();
controller.list_virtual_branches(&project).unwrap_err(); gitbutler_branch_actions::list_virtual_branches(&project).unwrap_err();
} }
{ {
let project = projects.add(test_project.path()).unwrap(); let project = projects.add(test_project.path()).unwrap();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(&project, &"refs/remotes/origin/master".parse().unwrap()) &project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
// even though project is on gitbutler/workspace, we should not import it // even though project is on gitbutler/workspace, we should not import it
assert!(controller assert!(gitbutler_branch_actions::list_virtual_branches(&project)
.list_virtual_branches(&project)
.unwrap() .unwrap()
.0 .0
.is_empty()); .is_empty());
@ -47,7 +47,6 @@ fn dirty_non_target() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -55,11 +54,13 @@ fn dirty_non_target() {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].files[0].hunks.len(), 1); assert_eq!(branches[0].files[0].hunks.len(), 1);
@ -74,17 +75,18 @@ fn dirty_target() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].files[0].hunks.len(), 1); assert_eq!(branches[0].files[0].hunks.len(), 1);
@ -97,7 +99,6 @@ fn commit_on_non_target_local() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -105,11 +106,13 @@ fn commit_on_non_target_local() {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
repository.commit_all("commit on target"); repository.commit_all("commit on target");
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].files.is_empty()); assert!(branches[0].files.is_empty());
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -122,7 +125,6 @@ fn commit_on_non_target_remote() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -131,11 +133,13 @@ fn commit_on_non_target_remote() {
repository.commit_all("commit on target"); repository.commit_all("commit on target");
repository.push_branch(&"refs/heads/some-feature".parse().unwrap()); repository.push_branch(&"refs/heads/some-feature".parse().unwrap());
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].files.is_empty()); assert!(branches[0].files.is_empty());
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -148,18 +152,19 @@ fn commit_on_target() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
repository.commit_all("commit on target"); repository.commit_all("commit on target");
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].files.is_empty()); assert!(branches[0].files.is_empty());
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -172,7 +177,6 @@ fn submodule() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -181,11 +185,13 @@ fn submodule() {
test_project.path().display().to_string().parse().unwrap(); test_project.path().display().to_string().parse().unwrap();
repository.add_submodule(&submodule_url, path::Path::new("submodule")); repository.add_submodule(&submodule_url, path::Path::new("submodule"));
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].files[0].hunks.len(), 1); assert_eq!(branches[0].files[0].hunks.len(), 1);

View File

@ -7,43 +7,41 @@ fn insert_blank_commit_down() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let _commit1_id = controller let _commit1_id =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id =
.create_commit(project, branch_id, "commit two", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file4.txt"), "content4").unwrap(); fs::write(repository.path().join("file4.txt"), "content4").unwrap();
let _commit3_id = controller let _commit3_id =
.create_commit(project, branch_id, "commit three", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::insert_blank_commit(project, branch_id, commit2_id, 1).unwrap();
.insert_blank_commit(project, branch_id, commit2_id, 1)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -72,43 +70,41 @@ fn insert_blank_commit_up() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let _commit1_id = controller let _commit1_id =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id =
.create_commit(project, branch_id, "commit two", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file4.txt"), "content4").unwrap(); fs::write(repository.path().join("file4.txt"), "content4").unwrap();
let _commit3_id = controller let _commit3_id =
.create_commit(project, branch_id, "commit three", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::insert_blank_commit(project, branch_id, commit2_id, -1).unwrap();
.insert_blank_commit(project, branch_id, commit2_id, -1)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()

View File

@ -1,8 +1,8 @@
use std::{fs, path, path::PathBuf, str::FromStr}; use std::{fs, path, path::PathBuf, str::FromStr};
use gitbutler_branch::{BranchCreateRequest, VirtualBranchesHandle}; use gitbutler_branch::{BranchCreateRequest, VirtualBranchesHandle};
use gitbutler_branch_actions::update_workspace_commit;
use gitbutler_branch_actions::GITBUTLER_WORKSPACE_COMMIT_TITLE; use gitbutler_branch_actions::GITBUTLER_WORKSPACE_COMMIT_TITLE;
use gitbutler_branch_actions::{update_workspace_commit, VirtualBranchActions};
use gitbutler_command_context::CommandContext; use gitbutler_command_context::CommandContext;
use gitbutler_error::error::Marker; use gitbutler_error::error::Marker;
use gitbutler_project::{self as projects, Project, ProjectId}; use gitbutler_project::{self as projects, Project, ProjectId};
@ -15,7 +15,6 @@ struct Test {
project_id: ProjectId, project_id: ProjectId,
project: Project, project: Project,
projects: projects::Controller, projects: projects::Controller,
controller: VirtualBranchActions,
data_dir: Option<TempDir>, data_dir: Option<TempDir>,
} }
@ -40,7 +39,6 @@ impl Default for Test {
Self { Self {
repository: test_project, repository: test_project,
project_id: project.id, project_id: project.id,
controller: VirtualBranchActions {},
projects, projects,
project, project,
data_dir: Some(data_dir), data_dir: Some(data_dir),
@ -89,7 +87,6 @@ fn resolve_conflict_flow() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -105,18 +102,22 @@ fn resolve_conflict_flow() {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
{ {
// make a branch that conflicts with the remote branch, but doesn't know about it yet // make a branch that conflicts with the remote branch, but doesn't know about it yet
let branch1_id = controller let branch1_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -124,11 +125,11 @@ fn resolve_conflict_flow() {
let unapplied_branch = { let unapplied_branch = {
// fetch remote. There is now a conflict, so the branch will be unapplied // fetch remote. There is now a conflict, so the branch will be unapplied
let unapplied_branches = controller.update_base_branch(project).unwrap(); let unapplied_branches = gitbutler_branch_actions::update_base_branch(project).unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// there is a conflict now, so the branch should be inactive // there is a conflict now, so the branch should be inactive
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
Refname::from_str(&unapplied_branches[0]).unwrap() Refname::from_str(&unapplied_branches[0]).unwrap()
@ -136,14 +137,17 @@ fn resolve_conflict_flow() {
let branch1_id = { let branch1_id = {
// when we apply conflicted branch, it has conflict // when we apply conflicted branch, it has conflict
let branch1_id = controller let branch1_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(project, &unapplied_branch, None) project,
&unapplied_branch,
None,
)
.unwrap(); .unwrap();
let vb_state = VirtualBranchesHandle::new(project.gb_dir()); let vb_state = VirtualBranchesHandle::new(project.gb_dir());
let ctx = CommandContext::open(project).unwrap(); let ctx = CommandContext::open(project).unwrap();
update_workspace_commit(&vb_state, &ctx).unwrap(); update_workspace_commit(&vb_state, &ctx).unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].active); assert!(branches[0].active);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
@ -161,8 +165,13 @@ fn resolve_conflict_flow() {
{ {
// can't commit conflicts // can't commit conflicts
assert!(matches!( assert!(matches!(
controller gitbutler_branch_actions::create_commit(
.create_commit(project, branch1_id, "commit conflicts", None, false) project,
branch1_id,
"commit conflicts",
None,
false
)
.unwrap_err() .unwrap_err()
.downcast_ref(), .downcast_ref(),
Some(Marker::ProjectConflict) Some(Marker::ProjectConflict)
@ -172,15 +181,15 @@ fn resolve_conflict_flow() {
{ {
// fixing the conflict removes conflicted mark // fixing the conflict removes conflicted mark
fs::write(repository.path().join("file.txt"), "resolved").unwrap(); fs::write(repository.path().join("file.txt"), "resolved").unwrap();
controller.list_virtual_branches(project).unwrap(); gitbutler_branch_actions::list_virtual_branches(project).unwrap();
let commit_oid = controller let commit_oid =
.create_commit(project, branch1_id, "resolution", None, false) gitbutler_branch_actions::create_commit(project, branch1_id, "resolution", None, false)
.unwrap(); .unwrap();
let commit = repository.find_commit(commit_oid).unwrap(); let commit = repository.find_commit(commit_oid).unwrap();
assert_eq!(commit.parent_count(), 2); assert_eq!(commit.parent_count(), 2);
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active); assert!(branches[0].active);

View File

@ -8,41 +8,42 @@ fn move_file_down() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit1_id = controller let commit1_id =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
let commit1 = repository.find_commit(commit1_id).unwrap(); let commit1 = repository.find_commit(commit1_id).unwrap();
// create commit // create commit
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id =
.create_commit(project, branch_id, "commit two", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.unwrap(); .unwrap();
let commit2 = repository.find_commit(commit2_id).unwrap(); let commit2 = repository.find_commit(commit2_id).unwrap();
// amend another hunk // amend another hunk
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
controller gitbutler_branch_actions::move_commit_file(
.move_commit_file(project, branch_id, commit2_id, commit1_id, &to_amend) project, branch_id, commit2_id, commit1_id, &to_amend,
)
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -66,39 +67,40 @@ fn move_file_up() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
let commit1_id = controller let commit1_id =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id =
.create_commit(project, branch_id, "commit two", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.unwrap(); .unwrap();
// amend another hunk // amend another hunk
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap(); let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
controller gitbutler_branch_actions::move_commit_file(
.move_commit_file(project, branch_id, commit1_id, commit2_id, &to_amend) project, branch_id, commit1_id, commit2_id, &to_amend,
)
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -119,32 +121,28 @@ fn move_file_up_overlapping_hunks() {
let Test { let Test {
repository, repository,
project_id, project_id,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.unwrap(); .unwrap();
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create bottom commit // create bottom commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let _commit1_id = controller let _commit1_id = gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
// create middle commit one // create middle commit one
fs::write(repository.path().join("file2.txt"), "content2\ncontent2a\n").unwrap(); fs::write(repository.path().join("file2.txt"), "content2\ncontent2a\n").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id = gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.create_commit(project, branch_id, "commit two", None, false)
.unwrap(); .unwrap();
@ -155,27 +153,23 @@ fn move_file_up_overlapping_hunks() {
) )
.unwrap(); .unwrap();
fs::write(repository.path().join("file4.txt"), "content4").unwrap(); fs::write(repository.path().join("file4.txt"), "content4").unwrap();
let commit3_id = controller let commit3_id = gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.create_commit(project, branch_id, "commit three", None, false)
.unwrap(); .unwrap();
// create top commit // create top commit
fs::write(repository.path().join("file5.txt"), "content5").unwrap(); fs::write(repository.path().join("file5.txt"), "content5").unwrap();
let _commit4_id = controller let _commit4_id = gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
.create_commit(project, branch_id, "commit four", None, false)
.unwrap(); .unwrap();
// move one line from middle commit two up to middle commit one // move one line from middle commit two up to middle commit one
let to_amend: BranchOwnershipClaims = "file2.txt:1-6".parse().unwrap(); let to_amend: BranchOwnershipClaims = "file2.txt:1-6".parse().unwrap();
controller gitbutler_branch_actions::move_commit_file(project, branch_id, commit2_id, commit3_id, &to_amend)
.move_commit_file(project, branch_id, commit2_id, commit3_id, &to_amend)
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0

View File

@ -7,43 +7,40 @@ fn no_diffs() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
let commit_oid = controller let commit_oid =
.create_commit(project, source_branch_id, "commit", None, false) gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
.unwrap(); .unwrap();
let target_branch_id = controller let target_branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
controller gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid).unwrap();
.move_commit(project, target_branch_id, commit_oid)
.unwrap();
let destination_branch = controller let destination_branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
.find(|b| b.id == target_branch_id) .find(|b| b.id == target_branch_id)
.unwrap(); .unwrap();
let source_branch = controller let source_branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -61,23 +58,24 @@ fn diffs_on_source_branch() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
let commit_oid = controller let commit_oid =
.create_commit(project, source_branch_id, "commit", None, false) gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
.unwrap(); .unwrap();
std::fs::write( std::fs::write(
@ -86,24 +84,20 @@ fn diffs_on_source_branch() {
) )
.unwrap(); .unwrap();
let target_branch_id = controller let target_branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
controller gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid).unwrap();
.move_commit(project, target_branch_id, commit_oid)
.unwrap();
let destination_branch = controller let destination_branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
.find(|b| b.id == target_branch_id) .find(|b| b.id == target_branch_id)
.unwrap(); .unwrap();
let source_branch = controller let source_branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -121,27 +115,27 @@ fn diffs_on_target_branch() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
let commit_oid = controller let commit_oid =
.create_commit(project, source_branch_id, "commit", None, false) gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
.unwrap(); .unwrap();
let target_branch_id = controller let target_branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
@ -156,20 +150,16 @@ fn diffs_on_target_branch() {
) )
.unwrap(); .unwrap();
controller gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid).unwrap();
.move_commit(project, target_branch_id, commit_oid)
.unwrap();
let destination_branch = controller let destination_branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
.find(|b| b.id == target_branch_id) .find(|b| b.id == target_branch_id)
.unwrap(); .unwrap();
let source_branch = controller let source_branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -187,34 +177,34 @@ fn locked_hunks_on_source_branch() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
let commit_oid = controller let commit_oid =
.create_commit(project, source_branch_id, "commit", None, false) gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "locked content").unwrap(); std::fs::write(repository.path().join("file.txt"), "locked content").unwrap();
let target_branch_id = controller let target_branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid)
.move_commit(project, target_branch_id, commit_oid)
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
"the source branch contains hunks locked to the target commit" "the source branch contains hunks locked to the target commit"
@ -226,33 +216,32 @@ fn no_commit() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
controller gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
.create_commit(project, source_branch_id, "commit", None, false)
.unwrap(); .unwrap();
let target_branch_id = controller let target_branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let commit_id_hex = "a99c95cca7a60f1a2180c2f86fb18af97333c192"; let commit_id_hex = "a99c95cca7a60f1a2180c2f86fb18af97333c192";
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::move_commit(
.move_commit(
project, project,
target_branch_id, target_branch_id,
git2::Oid::from_str(commit_id_hex).unwrap() git2::Oid::from_str(commit_id_hex).unwrap()
@ -268,29 +257,29 @@ fn no_branch() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id; let source_branch_id = branches[0].id;
let commit_oid = controller let commit_oid =
.create_commit(project, source_branch_id, "commit", None, false) gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
.unwrap(); .unwrap();
let id = BranchId::generate(); let id = BranchId::generate();
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::move_commit(project, id, commit_oid)
.move_commit(project, id, commit_oid)
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
format!("branch {id} is not among applied branches") format!("branch {id} is not among applied branches")

View File

@ -11,13 +11,15 @@ fn workdir_vbranch_restore() -> anyhow::Result<()> {
let test = Test::default(); let test = Test::default();
let Test { let Test {
repository, repository,
controller,
project, project,
.. ..
} = &test; } = &test;
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let worktree_dir = repository.path(); let worktree_dir = repository.path();
@ -27,14 +29,14 @@ fn workdir_vbranch_restore() -> anyhow::Result<()> {
worktree_dir.join(format!("file{round}.txt")), worktree_dir.join(format!("file{round}.txt")),
make_lines(line_count), make_lines(line_count),
)?; )?;
let branch_id = controller.create_virtual_branch( let branch_id = gitbutler_branch_actions::create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
name: Some(round.to_string()), name: Some(round.to_string()),
..Default::default() ..Default::default()
}, },
)?; )?;
controller.create_commit( gitbutler_branch_actions::create_commit(
project, project,
branch_id, branch_id,
&format!("commit {round}"), &format!("commit {round}"),
@ -51,7 +53,7 @@ fn workdir_vbranch_restore() -> anyhow::Result<()> {
line_count > 20 line_count > 20
); );
} }
let _empty = controller.create_virtual_branch(project, &Default::default())?; let _empty = gitbutler_branch_actions::create_virtual_branch(project, &Default::default())?;
let snapshots = project.list_snapshots(10, None)?; let snapshots = project.list_snapshots(10, None)?;
assert_eq!( assert_eq!(
@ -96,18 +98,20 @@ fn make_lines(count: usize) -> Vec<u8> {
fn basic_oplog() -> anyhow::Result<()> { fn basic_oplog() -> anyhow::Result<()> {
let Test { let Test {
repository, repository,
controller,
project, project,
.. ..
} = &Test::default(); } = &Test::default();
controller.set_base_branch(project, &"refs/remotes/origin/master".parse()?)?; gitbutler_branch_actions::set_base_branch(project, &"refs/remotes/origin/master".parse()?)?;
let branch_id = controller.create_virtual_branch(project, &BranchCreateRequest::default())?; let branch_id =
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())?;
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content")?; fs::write(repository.path().join("file.txt"), "content")?;
let _commit1_id = controller.create_commit(project, branch_id, "commit one", None, false)?; let _commit1_id =
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)?;
// dont store large files // dont store large files
let file_path = repository.path().join("large.txt"); let file_path = repository.path().join("large.txt");
@ -121,7 +125,8 @@ fn basic_oplog() -> anyhow::Result<()> {
// create commit with large file // create commit with large file
fs::write(repository.path().join("file2.txt"), "content2")?; fs::write(repository.path().join("file2.txt"), "content2")?;
fs::write(repository.path().join("file3.txt"), "content3")?; fs::write(repository.path().join("file3.txt"), "content3")?;
let commit2_id = controller.create_commit(project, branch_id, "commit two", None, false)?; let commit2_id =
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)?;
// Create conflict state // Create conflict state
let conflicts_path = repository.path().join(".git").join("conflicts"); let conflicts_path = repository.path().join(".git").join("conflicts");
@ -131,22 +136,22 @@ fn basic_oplog() -> anyhow::Result<()> {
// create state with conflict state // create state with conflict state
let _empty_branch_id = let _empty_branch_id =
controller.create_virtual_branch(project, &BranchCreateRequest::default())?; gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())?;
std::fs::remove_file(&base_merge_parent_path)?; std::fs::remove_file(&base_merge_parent_path)?;
std::fs::remove_file(&conflicts_path)?; std::fs::remove_file(&conflicts_path)?;
fs::write(repository.path().join("file4.txt"), "content4")?; fs::write(repository.path().join("file4.txt"), "content4")?;
let _commit3_id = controller.create_commit(project, branch_id, "commit three", None, false)?; let _commit3_id =
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)?;
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)?
.list_virtual_branches(project)?
.0 .0
.into_iter() .into_iter()
.find(|b| b.id == branch_id) .find(|b| b.id == branch_id)
.unwrap(); .unwrap();
let branches = controller.list_virtual_branches(project)?; let branches = gitbutler_branch_actions::list_virtual_branches(project)?;
assert_eq!(branches.0.len(), 2); assert_eq!(branches.0.len(), 2);
assert_eq!(branch.commits.len(), 3); assert_eq!(branch.commits.len(), 3);
@ -185,7 +190,7 @@ fn basic_oplog() -> anyhow::Result<()> {
project.restore_snapshot(snapshots[2].clone().commit_id)?; project.restore_snapshot(snapshots[2].clone().commit_id)?;
// the restore removed our new branch // the restore removed our new branch
let branches = controller.list_virtual_branches(project)?; let branches = gitbutler_branch_actions::list_virtual_branches(project)?;
assert_eq!(branches.0.len(), 1); assert_eq!(branches.0.len(), 1);
// assert that the conflicts file was removed // assert that the conflicts file was removed
@ -233,12 +238,12 @@ fn basic_oplog() -> anyhow::Result<()> {
fn restores_gitbutler_workspace() -> anyhow::Result<()> { fn restores_gitbutler_workspace() -> anyhow::Result<()> {
let Test { let Test {
repository, repository,
controller,
project, project,
.. ..
} = &Test::default(); } = &Test::default();
controller.set_base_branch(project, &"refs/remotes/origin/master".parse()?)?; gitbutler_branch_actions::set_base_branch(project, &"refs/remotes/origin/master".parse()?)?;
assert_eq!( assert_eq!(
VirtualBranchesHandle::new(project.gb_dir()) VirtualBranchesHandle::new(project.gb_dir())
@ -246,7 +251,8 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
.len(), .len(),
0 0
); );
let branch_id = controller.create_virtual_branch(project, &BranchCreateRequest::default())?; let branch_id =
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())?;
assert_eq!( assert_eq!(
VirtualBranchesHandle::new(project.gb_dir()) VirtualBranchesHandle::new(project.gb_dir())
.list_branches_in_workspace()? .list_branches_in_workspace()?
@ -256,7 +262,8 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content")?; fs::write(repository.path().join("file.txt"), "content")?;
let _commit1_id = controller.create_commit(project, branch_id, "commit one", None, false)?; let _commit1_id =
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)?;
let repo = git2::Repository::open(&project.path)?; let repo = git2::Repository::open(&project.path)?;
@ -269,7 +276,8 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
// create second commit // create second commit
fs::write(repository.path().join("file.txt"), "changed content")?; fs::write(repository.path().join("file.txt"), "changed content")?;
let _commit2_id = controller.create_commit(project, branch_id, "commit two", None, false)?; let _commit2_id =
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)?;
// check the workspace commit changed // check the workspace commit changed
let head = repo.head().expect("never unborn"); let head = repo.head().expect("never unborn");
@ -347,16 +355,20 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
fn head_corrupt_is_recreated_automatically() { fn head_corrupt_is_recreated_automatically() {
let Test { let Test {
repository, repository,
controller,
project, project,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let snapshots = project.list_snapshots(10, None).unwrap(); let snapshots = project.list_snapshots(10, None).unwrap();
@ -374,8 +386,10 @@ fn head_corrupt_is_recreated_automatically() {
) )
.unwrap(); .unwrap();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.expect("the snapshot doesn't fail despite the corrupt head"); .expect("the snapshot doesn't fail despite the corrupt head");
let snapshots = project.list_snapshots(10, None).unwrap(); let snapshots = project.list_snapshots(10, None).unwrap();

View File

@ -9,20 +9,24 @@ mod create_virtual_branch {
fn simple() { fn simple() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].name, "Virtual branch"); assert_eq!(branches[0].name, "Virtual branch");
@ -39,17 +43,18 @@ mod create_virtual_branch {
fn duplicate_name() { fn duplicate_name() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
@ -58,8 +63,7 @@ mod create_virtual_branch {
) )
.unwrap(); .unwrap();
let branch2_id = controller let branch2_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
@ -68,7 +72,7 @@ mod create_virtual_branch {
) )
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 2); assert_eq!(branches.len(), 2);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].name, "name"); assert_eq!(branches[0].name, "name");
@ -94,17 +98,18 @@ mod update_virtual_branch {
fn simple() { fn simple() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
@ -113,8 +118,7 @@ mod update_virtual_branch {
) )
.unwrap(); .unwrap();
controller gitbutler_branch_actions::update_virtual_branch(
.update_virtual_branch(
project, project,
BranchUpdateRequest { BranchUpdateRequest {
id: branch_id, id: branch_id,
@ -124,7 +128,7 @@ mod update_virtual_branch {
) )
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].name, "new name"); assert_eq!(branches[0].name, "new name");
@ -142,17 +146,18 @@ mod update_virtual_branch {
fn duplicate_name() { fn duplicate_name() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
@ -161,8 +166,7 @@ mod update_virtual_branch {
) )
.unwrap(); .unwrap();
let branch2_id = controller let branch2_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
..Default::default() ..Default::default()
@ -170,8 +174,7 @@ mod update_virtual_branch {
) )
.unwrap(); .unwrap();
controller gitbutler_branch_actions::update_virtual_branch(
.update_virtual_branch(
project, project,
BranchUpdateRequest { BranchUpdateRequest {
id: branch2_id, id: branch2_id,
@ -181,7 +184,7 @@ mod update_virtual_branch {
) )
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 2); assert_eq!(branches.len(), 2);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].name, "name"); assert_eq!(branches[0].name, "name");
@ -207,17 +210,18 @@ mod push_virtual_branch {
fn simple() { fn simple() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
@ -228,14 +232,10 @@ mod push_virtual_branch {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch1_id, "test", None, false).unwrap();
.create_commit(project, branch1_id, "test", None, false) gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None).unwrap();
.unwrap();
controller
.push_virtual_branch(project, branch1_id, false, None)
.unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].name, "name"); assert_eq!(branches[0].name, "name");
@ -256,19 +256,20 @@ mod push_virtual_branch {
fn duplicate_names() { fn duplicate_names() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch1_id = { let branch1_id = {
// create and push branch with some work // create and push branch with some work
let branch1_id = controller let branch1_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
@ -277,18 +278,15 @@ mod push_virtual_branch {
) )
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch1_id, "test", None, false)
.create_commit(project, branch1_id, "test", None, false)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None)
.push_virtual_branch(project, branch1_id, false, None)
.unwrap(); .unwrap();
branch1_id branch1_id
}; };
// rename first branch // rename first branch
controller gitbutler_branch_actions::update_virtual_branch(
.update_virtual_branch(
project, project,
BranchUpdateRequest { BranchUpdateRequest {
id: branch1_id, id: branch1_id,
@ -300,8 +298,7 @@ mod push_virtual_branch {
let branch2_id = { let branch2_id = {
// create another branch with first branch's old name and push it // create another branch with first branch's old name and push it
let branch2_id = controller let branch2_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
name: Some("name".to_string()), name: Some("name".to_string()),
@ -310,16 +307,14 @@ mod push_virtual_branch {
) )
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "updated content").unwrap(); fs::write(repository.path().join("file.txt"), "updated content").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch2_id, "test", None, false)
.create_commit(project, branch2_id, "test", None, false)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::push_virtual_branch(project, branch2_id, false, None)
.push_virtual_branch(project, branch2_id, false, None)
.unwrap(); .unwrap();
branch2_id branch2_id
}; };
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 2); assert_eq!(branches.len(), 2);
// first branch is pushing to old ref remotely // first branch is pushing to old ref remotely
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);

View File

@ -7,37 +7,35 @@ fn reorder_commit_down() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let _commit1_id = controller let _commit1_id =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id =
.create_commit(project, branch_id, "commit two", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::reorder_commit(project, branch_id, commit2_id, 1).unwrap();
.reorder_commit(project, branch_id, commit2_id, 1)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -62,37 +60,35 @@ fn reorder_commit_up() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let commit1_id = controller let commit1_id =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let _commit2_id = controller let _commit2_id =
.create_commit(project, branch_id, "commit two", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::reorder_commit(project, branch_id, commit1_id, -1).unwrap();
.reorder_commit(project, branch_id, commit1_id, -1)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()

View File

@ -9,27 +9,28 @@ fn to_head() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let oid = { let oid = {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
// commit changes // commit changes
let oid = controller let oid =
.create_commit(project, branch1_id, "commit", None, false) gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -45,11 +46,9 @@ fn to_head() {
{ {
// reset changes to head // reset changes to head
controller gitbutler_branch_actions::reset_virtual_branch(project, branch1_id, oid).unwrap();
.reset_virtual_branch(project, branch1_id, oid)
.unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -67,27 +66,28 @@ fn to_target() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
let base_branch = controller let base_branch = gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
// commit changes // commit changes
let oid = controller let oid =
.create_commit(project, branch1_id, "commit", None, false) gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -101,11 +101,10 @@ fn to_target() {
{ {
// reset changes to head // reset changes to head
controller gitbutler_branch_actions::reset_virtual_branch(project, branch1_id, base_branch.base_sha)
.reset_virtual_branch(project, branch1_id, base_branch.base_sha)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 0); assert_eq!(branches[0].commits.len(), 0);
@ -122,16 +121,17 @@ fn to_commit() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let first_commit_oid = { let first_commit_oid = {
@ -139,11 +139,11 @@ fn to_commit() {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let oid = controller let oid =
.create_commit(project, branch1_id, "commit", None, false) gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -161,11 +161,11 @@ fn to_commit() {
// commit some more // commit some more
fs::write(repository.path().join("file.txt"), "more content").unwrap(); fs::write(repository.path().join("file.txt"), "more content").unwrap();
let second_commit_oid = controller let second_commit_oid =
.create_commit(project, branch1_id, "commit", None, false) gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 2); assert_eq!(branches[0].commits.len(), 2);
@ -180,11 +180,10 @@ fn to_commit() {
{ {
// reset changes to the first commit // reset changes to the first commit
controller gitbutler_branch_actions::reset_virtual_branch(project, branch1_id, first_commit_oid)
.reset_virtual_branch(project, branch1_id, first_commit_oid)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -202,27 +201,28 @@ fn to_non_existing() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
// commit changes // commit changes
let oid = controller let oid =
.create_commit(project, branch1_id, "commit", None, false) gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
@ -237,8 +237,7 @@ fn to_non_existing() {
}; };
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::reset_virtual_branch(
.reset_virtual_branch(
project, project,
branch1_id, branch1_id,
"fe14df8c66b73c6276f7bb26102ad91da680afcb".parse().unwrap() "fe14df8c66b73c6276f7bb26102ad91da680afcb".parse().unwrap()

View File

@ -7,27 +7,28 @@ fn unapplying_selected_branch_selects_anther() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file one.txt"), "").unwrap(); std::fs::write(repository.path().join("file one.txt"), "").unwrap();
// first branch should be created as default // first branch should be created as default
let b_id = controller let b_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// if default branch exists, new branch should not be created as default // if default branch exists, new branch should not be created as default
let b2_id = controller let b2_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
let b = branches.iter().find(|b| b.id == b_id).unwrap(); let b = branches.iter().find(|b| b.id == b_id).unwrap();
@ -36,9 +37,9 @@ fn unapplying_selected_branch_selects_anther() {
assert!(b.selected_for_changes); assert!(b.selected_for_changes);
assert!(!b2.selected_for_changes); assert!(!b2.selected_for_changes);
controller.convert_to_real_branch(project, b_id).unwrap(); gitbutler_branch_actions::convert_to_real_branch(project, b_id).unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, b2.id); assert_eq!(branches[0].id, b2.id);
@ -48,27 +49,25 @@ fn unapplying_selected_branch_selects_anther() {
#[test] #[test]
fn deleting_selected_branch_selects_anther() { fn deleting_selected_branch_selects_anther() {
let Test { let Test { project, .. } = &Test::default();
project,
controller,
..
} = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
// first branch should be created as default // first branch should be created as default
let b_id = controller let b_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// if default branch exists, new branch should not be created as default // if default branch exists, new branch should not be created as default
let b2_id = controller let b2_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
let b = branches.iter().find(|b| b.id == b_id).unwrap(); let b = branches.iter().find(|b| b.id == b_id).unwrap();
@ -77,9 +76,9 @@ fn deleting_selected_branch_selects_anther() {
assert!(b.selected_for_changes); assert!(b.selected_for_changes);
assert!(!b2.selected_for_changes); assert!(!b2.selected_for_changes);
controller.delete_virtual_branch(project, b_id).unwrap(); gitbutler_branch_actions::delete_virtual_branch(project, b_id).unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, b2.id); assert_eq!(branches[0].id, b2.id);
@ -88,22 +87,19 @@ fn deleting_selected_branch_selects_anther() {
#[test] #[test]
fn create_virtual_branch_should_set_selected_for_changes() { fn create_virtual_branch_should_set_selected_for_changes() {
let Test { let Test { project, .. } = &Test::default();
project,
controller,
..
} = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
// first branch should be created as default // first branch should be created as default
let b_id = controller let b_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -112,11 +108,10 @@ fn create_virtual_branch_should_set_selected_for_changes() {
assert!(branch.selected_for_changes); assert!(branch.selected_for_changes);
// if default branch exists, new branch should not be created as default // if default branch exists, new branch should not be created as default
let b_id = controller let b_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -125,8 +120,7 @@ fn create_virtual_branch_should_set_selected_for_changes() {
assert!(!branch.selected_for_changes); assert!(!branch.selected_for_changes);
// explicitly don't make this one default // explicitly don't make this one default
let b_id = controller let b_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
selected_for_changes: Some(false), selected_for_changes: Some(false),
@ -134,8 +128,7 @@ fn create_virtual_branch_should_set_selected_for_changes() {
}, },
) )
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -144,8 +137,7 @@ fn create_virtual_branch_should_set_selected_for_changes() {
assert!(!branch.selected_for_changes); assert!(!branch.selected_for_changes);
// explicitly make this one default // explicitly make this one default
let b_id = controller let b_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
@ -153,8 +145,7 @@ fn create_virtual_branch_should_set_selected_for_changes() {
}, },
) )
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -165,21 +156,18 @@ fn create_virtual_branch_should_set_selected_for_changes() {
#[test] #[test]
fn update_virtual_branch_should_reset_selected_for_changes() { fn update_virtual_branch_should_reset_selected_for_changes() {
let Test { let Test { project, .. } = &Test::default();
gitbutler_branch_actions::set_base_branch(
project, project,
controller, &"refs/remotes/origin/master".parse().unwrap(),
.. )
} = &Test::default();
controller
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
.unwrap(); .unwrap();
let b1_id = controller let b1_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let b1 = controller let b1 = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -187,11 +175,10 @@ fn update_virtual_branch_should_reset_selected_for_changes() {
.unwrap(); .unwrap();
assert!(b1.selected_for_changes); assert!(b1.selected_for_changes);
let b2_id = controller let b2_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let b2 = controller let b2 = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -199,8 +186,7 @@ fn update_virtual_branch_should_reset_selected_for_changes() {
.unwrap(); .unwrap();
assert!(!b2.selected_for_changes); assert!(!b2.selected_for_changes);
controller gitbutler_branch_actions::update_virtual_branch(
.update_virtual_branch(
project, project,
BranchUpdateRequest { BranchUpdateRequest {
id: b2_id, id: b2_id,
@ -210,8 +196,7 @@ fn update_virtual_branch_should_reset_selected_for_changes() {
) )
.unwrap(); .unwrap();
let b1 = controller let b1 = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -219,8 +204,7 @@ fn update_virtual_branch_should_reset_selected_for_changes() {
.unwrap(); .unwrap();
assert!(!b1.selected_for_changes); assert!(!b1.selected_for_changes);
let b2 = controller let b2 = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -234,21 +218,21 @@ fn unapply_virtual_branch_should_reset_selected_for_changes() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let b1_id = controller let b1_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let b1 = controller let b1 = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -256,12 +240,11 @@ fn unapply_virtual_branch_should_reset_selected_for_changes() {
.unwrap(); .unwrap();
assert!(b1.selected_for_changes); assert!(b1.selected_for_changes);
let b2_id = controller let b2_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let b2 = controller let b2 = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -269,10 +252,9 @@ fn unapply_virtual_branch_should_reset_selected_for_changes() {
.unwrap(); .unwrap();
assert!(!b2.selected_for_changes); assert!(!b2.selected_for_changes);
controller.convert_to_real_branch(project, b1_id).unwrap(); gitbutler_branch_actions::convert_to_real_branch(project, b1_id).unwrap();
assert!(controller assert!(gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -284,21 +266,21 @@ fn hunks_distribution() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
controller gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
@ -307,7 +289,7 @@ fn hunks_distribution() {
) )
.unwrap(); .unwrap();
std::fs::write(repository.path().join("another_file.txt"), "content").unwrap(); std::fs::write(repository.path().join("another_file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[1].files.len(), 1); assert_eq!(branches[1].files.len(), 1);
} }
@ -317,28 +299,27 @@ fn applying_first_branch() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("file.txt"), "content").unwrap(); std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
let unapplied_branch = controller let unapplied_branch =
.convert_to_real_branch(project, branches[0].id) gitbutler_branch_actions::convert_to_real_branch(project, branches[0].id).unwrap();
.unwrap();
let unapplied_branch = Refname::from_str(&unapplied_branch).unwrap(); let unapplied_branch = Refname::from_str(&unapplied_branch).unwrap();
controller gitbutler_branch_actions::create_virtual_branch_from_branch(project, &unapplied_branch, None)
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].active); assert!(branches[0].active);
assert!(branches[0].selected_for_changes); assert!(branches[0].selected_for_changes);
@ -351,7 +332,6 @@ fn new_locked_hunk_without_modifying_existing() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -359,26 +339,26 @@ fn new_locked_hunk_without_modifying_existing() {
repository.commit_all("first commit"); repository.commit_all("first commit");
repository.push(); repository.push();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
lines[0] = "modification 1".to_string(); lines[0] = "modification 1".to_string();
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
controller gitbutler_branch_actions::create_commit(project, branches[0].id, "second commit", None, false)
.create_commit(project, branches[0].id, "second commit", None, false)
.expect("failed to create commit"); .expect("failed to create commit");
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches[0].files.len(), 0); assert_eq!(branches[0].files.len(), 0);
assert_eq!(branches[0].commits.len(), 1); assert_eq!(branches[0].commits.len(), 1);
controller gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
@ -390,13 +370,13 @@ fn new_locked_hunk_without_modifying_existing() {
lines[8] = "modification 2".to_string(); lines[8] = "modification 2".to_string();
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches[0].files.len(), 0); assert_eq!(branches[0].files.len(), 0);
assert_eq!(branches[1].files.len(), 1); assert_eq!(branches[1].files.len(), 1);
lines[0] = "modification 3".to_string(); lines[0] = "modification 3".to_string();
repository.write_file("file.txt", &lines); repository.write_file("file.txt", &lines);
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches[0].files.len(), 1); assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[1].files.len(), 1); assert_eq!(branches[1].files.len(), 1);
} }

View File

@ -2,14 +2,12 @@ use super::*;
#[test] #[test]
fn success() { fn success() {
let Test { let Test { project, .. } = &Test::default();
project,
controller,
..
} = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
} }
@ -20,15 +18,10 @@ mod error {
#[test] #[test]
fn missing() { fn missing() {
let Test { let Test { project, .. } = &Test::default();
project,
controller,
..
} = &Test::default();
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(
project, project,
&RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(), &RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(),
) )
@ -50,7 +43,6 @@ mod go_back_to_workspace {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -60,29 +52,33 @@ mod go_back_to_workspace {
repository.commit_all("two"); repository.commit_all("two");
repository.push(); repository.push();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let vbranch_id = controller let vbranch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
std::fs::write(repository.path().join("another file.txt"), "content").unwrap(); std::fs::write(repository.path().join("another file.txt"), "content").unwrap();
controller gitbutler_branch_actions::create_commit(project, vbranch_id, "one", None, false).unwrap();
.create_commit(project, vbranch_id, "one", None, false)
.unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
repository.checkout_commit(oid_one); repository.checkout_commit(oid_one);
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, vbranch_id); assert_eq!(branches[0].id, vbranch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -93,7 +89,6 @@ mod go_back_to_workspace {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -103,19 +98,23 @@ mod go_back_to_workspace {
repository.commit_all("two"); repository.commit_all("two");
repository.push(); repository.push();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert!(branches.is_empty()); assert!(branches.is_empty());
repository.checkout_commit(oid_one); repository.checkout_commit(oid_one);
std::fs::write(repository.path().join("file.txt"), "tree").unwrap(); std::fs::write(repository.path().join("file.txt"), "tree").unwrap();
assert!(matches!( assert!(matches!(
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap()
)
.unwrap_err() .unwrap_err()
.downcast_ref(), .downcast_ref(),
Some(Marker::ProjectConflict) Some(Marker::ProjectConflict)
@ -127,7 +126,6 @@ mod go_back_to_workspace {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -137,19 +135,23 @@ mod go_back_to_workspace {
repository.commit_all("two"); repository.commit_all("two");
repository.push(); repository.push();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert!(branches.is_empty()); assert!(branches.is_empty());
repository.checkout_commit(oid_one); repository.checkout_commit(oid_one);
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap(); std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
assert!(matches!( assert!(matches!(
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap()
)
.unwrap_err() .unwrap_err()
.downcast_ref(), .downcast_ref(),
Some(Marker::ProjectConflict) Some(Marker::ProjectConflict)
@ -161,7 +163,6 @@ mod go_back_to_workspace {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -171,22 +172,26 @@ mod go_back_to_workspace {
repository.commit_all("two"); repository.commit_all("two");
repository.push(); repository.push();
let base = controller let base = gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert!(branches.is_empty()); assert!(branches.is_empty());
repository.checkout_commit(oid_one); repository.checkout_commit(oid_one);
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap(); std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
repository.commit_all("three"); repository.commit_all("three");
let base_two = controller let base_two = gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert_eq!(base_two, base); assert_eq!(base_two, base);
} }
@ -196,7 +201,6 @@ mod go_back_to_workspace {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -206,20 +210,24 @@ mod go_back_to_workspace {
repository.commit_all("two"); repository.commit_all("two");
repository.push(); repository.push();
let base = controller let base = gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert!(branches.is_empty()); assert!(branches.is_empty());
repository.checkout_commit(oid_one); repository.checkout_commit(oid_one);
let base_two = controller let base_two = gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert_eq!(base_two, base); assert_eq!(base_two, base);
} }

View File

@ -7,52 +7,46 @@ fn head() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.create_commit(project, branch_id, "commit two", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.create_commit(project, branch_id, "commit three", None, false)
.unwrap() .unwrap()
}; };
let commit_four_oid = { let commit_four_oid = {
fs::write(repository.path().join("file four.txt"), "").unwrap(); fs::write(repository.path().join("file four.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
.create_commit(project, branch_id, "commit four", None, false)
.unwrap() .unwrap()
}; };
controller gitbutler_branch_actions::squash(project, branch_id, commit_four_oid).unwrap();
.squash(project, branch_id, commit_four_oid)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -75,52 +69,46 @@ fn middle() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
let commit_two_oid = { let commit_two_oid = {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.create_commit(project, branch_id, "commit two", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.create_commit(project, branch_id, "commit three", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file four.txt"), "").unwrap(); fs::write(repository.path().join("file four.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
.create_commit(project, branch_id, "commit four", None, false)
.unwrap() .unwrap()
}; };
controller gitbutler_branch_actions::squash(project, branch_id, commit_two_oid).unwrap();
.squash(project, branch_id, commit_two_oid)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -144,7 +132,6 @@ fn forcepush_allowed() {
repository, repository,
project_id, project_id,
project, project,
controller,
projects, projects,
.. ..
} = &Test::default(); } = &Test::default();
@ -156,52 +143,45 @@ fn forcepush_allowed() {
}) })
.unwrap(); .unwrap();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
let commit_two_oid = { let commit_two_oid = {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.create_commit(project, branch_id, "commit two", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.create_commit(project, branch_id, "commit three", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file four.txt"), "").unwrap(); fs::write(repository.path().join("file four.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
.create_commit(project, branch_id, "commit four", None, false)
.unwrap() .unwrap()
}; };
controller gitbutler_branch_actions::squash(project, branch_id, commit_two_oid).unwrap();
.squash(project, branch_id, commit_two_oid)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -225,20 +205,20 @@ fn forcepush_forbidden() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
controller gitbutler_branch_actions::update_virtual_branch(
.update_virtual_branch(
project, project,
BranchUpdateRequest { BranchUpdateRequest {
id: branch_id, id: branch_id,
@ -250,39 +230,32 @@ fn forcepush_forbidden() {
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
let commit_two_oid = { let commit_two_oid = {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.create_commit(project, branch_id, "commit two", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.create_commit(project, branch_id, "commit three", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file four.txt"), "").unwrap(); fs::write(repository.path().join("file four.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
.create_commit(project, branch_id, "commit four", None, false)
.unwrap() .unwrap()
}; };
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::squash(project, branch_id, commit_two_oid)
.squash(project, branch_id, commit_two_oid)
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
"force push not allowed" "force push not allowed"
@ -294,28 +267,27 @@ fn root_forbidden() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let commit_one_oid = { let commit_one_oid = {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::squash(project, branch_id, commit_one_oid)
.squash(project, branch_id, commit_one_oid)
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
"can not squash root commit" "can not squash root commit"

View File

@ -8,17 +8,18 @@ use super::Test;
fn should_unapply_with_commits() { fn should_unapply_with_commits() {
let Test { let Test {
project, project,
controller,
repository, repository,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
fs::write( fs::write(
@ -26,9 +27,7 @@ fn should_unapply_with_commits() {
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n",
) )
.unwrap(); .unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "test", None, false).unwrap();
.create_commit(project, branch_id, "test", None, false)
.unwrap();
// change in the committed hunks leads to hunk locking // change in the committed hunks leads to hunk locking
fs::write( fs::write(
@ -37,8 +36,7 @@ fn should_unapply_with_commits() {
) )
.unwrap(); .unwrap();
controller gitbutler_branch_actions::unapply_ownership(
.unapply_ownership(
project, project,
&"file.txt:1-5,7-11" &"file.txt:1-5,7-11"
.parse::<BranchOwnershipClaims>() .parse::<BranchOwnershipClaims>()
@ -46,8 +44,7 @@ fn should_unapply_with_commits() {
) )
.unwrap_or_else(|err| panic!("{err:?}")); .unwrap_or_else(|err| panic!("{err:?}"));
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()

View File

@ -7,43 +7,41 @@ fn undo_commit_simple() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
let _commit1_id = controller let _commit1_id =
.create_commit(project, branch_id, "commit one", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file2.txt"), "content2").unwrap(); fs::write(repository.path().join("file2.txt"), "content2").unwrap();
fs::write(repository.path().join("file3.txt"), "content3").unwrap(); fs::write(repository.path().join("file3.txt"), "content3").unwrap();
let commit2_id = controller let commit2_id =
.create_commit(project, branch_id, "commit two", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.unwrap(); .unwrap();
// create commit // create commit
fs::write(repository.path().join("file4.txt"), "content4").unwrap(); fs::write(repository.path().join("file4.txt"), "content4").unwrap();
let _commit3_id = controller let _commit3_id =
.create_commit(project, branch_id, "commit three", None, false) gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::undo_commit(project, branch_id, commit2_id).unwrap();
.undo_commit(project, branch_id, commit2_id)
.unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()

View File

@ -10,7 +10,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -24,14 +23,18 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
{ {
// make a branch that conflicts with the remote branch, but doesn't know about it yet // make a branch that conflicts with the remote branch, but doesn't know about it yet
controller gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
@ -39,12 +42,12 @@ mod applied_branch {
let unapplied_branch = { let unapplied_branch = {
// fetch remote // fetch remote
let unapplied_branches = controller.update_base_branch(project).unwrap(); let unapplied_branches = gitbutler_branch_actions::update_base_branch(project).unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// should stash conflicting branch // should stash conflicting branch
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
Refname::from_str(unapplied_branches[0].as_str()).unwrap() Refname::from_str(unapplied_branches[0].as_str()).unwrap()
@ -52,10 +55,13 @@ mod applied_branch {
{ {
// applying the branch should produce conflict markers // applying the branch should produce conflict markers
controller gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(project, &unapplied_branch, None) project,
&unapplied_branch,
None,
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
assert!(branches[0].base_current); assert!(branches[0].base_current);
@ -72,7 +78,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -86,31 +91,40 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
{ {
// make a branch with a commit that conflicts with upstream, and work that fixes // make a branch with a commit that conflicts with upstream, and work that fixes
// that conflict // that conflict
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
controller gitbutler_branch_actions::create_commit(
.create_commit(project, branch_id, "conflicting commit", None, false) project,
branch_id,
"conflicting commit",
None,
false,
)
.unwrap(); .unwrap();
} }
let unapplied_branch = { let unapplied_branch = {
// when fetching remote // when fetching remote
let unapplied_branches = controller.update_base_branch(project).unwrap(); let unapplied_branches = gitbutler_branch_actions::update_base_branch(project).unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// should stash the branch. // should stash the branch.
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
Refname::from_str(unapplied_branches[0].as_str()).unwrap() Refname::from_str(unapplied_branches[0].as_str()).unwrap()
@ -118,10 +132,13 @@ mod applied_branch {
{ {
// applying the branch should produce conflict markers // applying the branch should produce conflict markers
controller gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(project, &unapplied_branch, None) project,
&unapplied_branch,
None,
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
assert!(branches[0].base_current); assert!(branches[0].base_current);
@ -139,7 +156,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -153,35 +169,42 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
{ {
// make a branch with a commit that conflicts with upstream, and work that fixes // make a branch with a commit that conflicts with upstream, and work that fixes
// that conflict // that conflict
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
controller gitbutler_branch_actions::create_commit(
.create_commit(project, branch_id, "conflicting commit", None, false) project,
branch_id,
"conflicting commit",
None,
false,
)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
} }
let unapplied_branch = { let unapplied_branch = {
// when fetching remote // when fetching remote
let unapplied_branches = controller.update_base_branch(project).unwrap(); let unapplied_branches = gitbutler_branch_actions::update_base_branch(project).unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// should stash the branch. // should stash the branch.
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
Refname::from_str(unapplied_branches[0].as_str()).unwrap() Refname::from_str(unapplied_branches[0].as_str()).unwrap()
@ -189,10 +212,13 @@ mod applied_branch {
{ {
// applying the branch should produce conflict markers // applying the branch should produce conflict markers
controller gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(project, &unapplied_branch, None) project,
&unapplied_branch,
None,
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
assert!(branches[0].base_current); assert!(branches[0].base_current);
@ -210,7 +236,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -224,20 +249,29 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
{ {
// make a branch with a commit that conflicts with upstream, and work that fixes // make a branch with a commit that conflicts with upstream, and work that fixes
// that conflict // that conflict
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
controller gitbutler_branch_actions::create_commit(
.create_commit(project, branch_id, "conflicting commit", None, false) project,
branch_id,
"conflicting commit",
None,
false,
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "fix conflict").unwrap(); fs::write(repository.path().join("file.txt"), "fix conflict").unwrap();
@ -245,12 +279,12 @@ mod applied_branch {
let unapplied_branch = { let unapplied_branch = {
// when fetching remote // when fetching remote
let unapplied_branches = controller.update_base_branch(project).unwrap(); let unapplied_branches = gitbutler_branch_actions::update_base_branch(project).unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// should rebase upstream, and leave uncommited file as is // should rebase upstream, and leave uncommited file as is
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
Refname::from_str(unapplied_branches[0].as_str()).unwrap() Refname::from_str(unapplied_branches[0].as_str()).unwrap()
@ -258,10 +292,13 @@ mod applied_branch {
{ {
// applying the branch should produce conflict markers // applying the branch should produce conflict markers
controller gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(project, &unapplied_branch, None) project,
&unapplied_branch,
None,
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
assert!(branches[0].base_current); assert!(branches[0].base_current);
@ -279,7 +316,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -293,20 +329,29 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
{ {
// make a branch with a commit that conflicts with upstream, and work that fixes // make a branch with a commit that conflicts with upstream, and work that fixes
// that conflict // that conflict
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap(); fs::write(repository.path().join("file.txt"), "conflict").unwrap();
controller gitbutler_branch_actions::create_commit(
.create_commit(project, branch_id, "conflicting commit", None, false) project,
branch_id,
"conflicting commit",
None,
false,
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "fix conflict").unwrap(); fs::write(repository.path().join("file.txt"), "fix conflict").unwrap();
@ -314,12 +359,12 @@ mod applied_branch {
let unapplied_branch = { let unapplied_branch = {
// when fetching remote // when fetching remote
let unapplied_branches = controller.update_base_branch(project).unwrap(); let unapplied_branches = gitbutler_branch_actions::update_base_branch(project).unwrap();
assert_eq!(unapplied_branches.len(), 1); assert_eq!(unapplied_branches.len(), 1);
// should merge upstream, and leave uncommited file as is. // should merge upstream, and leave uncommited file as is.
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
Refname::from_str(unapplied_branches[0].as_str()).unwrap() Refname::from_str(unapplied_branches[0].as_str()).unwrap()
@ -327,10 +372,13 @@ mod applied_branch {
{ {
// applying the branch should produce conflict markers // applying the branch should produce conflict markers
controller gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(project, &unapplied_branch, None) project,
&unapplied_branch,
None,
)
.unwrap(); .unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
assert!(branches[0].base_current); assert!(branches[0].base_current);
@ -354,7 +402,6 @@ mod applied_branch {
repository, repository,
project, project,
project_id, project_id,
controller,
projects, projects,
.. ..
} = &Test::default(); } = &Test::default();
@ -376,22 +423,30 @@ mod applied_branch {
}) })
.unwrap(); .unwrap();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file2.txt"), "no conflict").unwrap(); fs::write(repository.path().join("file2.txt"), "no conflict").unwrap();
controller gitbutler_branch_actions::create_commit(
.create_commit(project, branch_id, "no conflicts", None, false) project,
branch_id,
"no conflicts",
None,
false,
)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None)
.push_virtual_branch(project, branch_id, false, None)
.unwrap(); .unwrap();
fs::write(repository.path().join("file2.txt"), "still no conflict").unwrap(); fs::write(repository.path().join("file2.txt"), "still no conflict").unwrap();
@ -401,12 +456,13 @@ mod applied_branch {
{ {
// fetch remote // fetch remote
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// rebases branch, since the branch is pushed and force pushing is // rebases branch, since the branch is pushed and force pushing is
// allowed // allowed
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) =
gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -429,7 +485,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -443,22 +498,30 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file2.txt"), "no conflict").unwrap(); fs::write(repository.path().join("file2.txt"), "no conflict").unwrap();
controller gitbutler_branch_actions::create_commit(
.create_commit(project, branch_id, "no conflicts", None, false) project,
branch_id,
"no conflicts",
None,
false,
)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None)
.push_virtual_branch(project, branch_id, false, None)
.unwrap(); .unwrap();
fs::write(repository.path().join("file2.txt"), "still no conflict").unwrap(); fs::write(repository.path().join("file2.txt"), "still no conflict").unwrap();
@ -466,8 +529,7 @@ mod applied_branch {
branch_id branch_id
}; };
controller gitbutler_branch_actions::update_virtual_branch(
.update_virtual_branch(
project, project,
BranchUpdateRequest { BranchUpdateRequest {
id: branch_id, id: branch_id,
@ -479,11 +541,12 @@ mod applied_branch {
{ {
// fetch remote // fetch remote
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// creates a merge commit, since the branch is pushed // creates a merge commit, since the branch is pushed
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) =
gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -504,7 +567,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -518,19 +580,28 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file2.txt"), "no conflict").unwrap(); fs::write(repository.path().join("file2.txt"), "no conflict").unwrap();
controller gitbutler_branch_actions::create_commit(
.create_commit(project, branch_id, "no conflicts", None, false) project,
branch_id,
"no conflicts",
None,
false,
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file2.txt"), "still no conflict").unwrap(); fs::write(repository.path().join("file2.txt"), "still no conflict").unwrap();
@ -540,11 +611,11 @@ mod applied_branch {
{ {
// fetch remote // fetch remote
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// just rebases branch // just rebases branch
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -568,7 +639,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -578,29 +648,29 @@ mod applied_branch {
repository.push(); repository.push();
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
// make a branch that conflicts with the remote branch, but doesn't know about it yet // make a branch that conflicts with the remote branch, but doesn't know about it yet
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "second").unwrap(); fs::write(repository.path().join("file.txt"), "second").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "second", None, false)
.create_commit(project, branch_id, "second", None, false)
.unwrap();
controller
.push_virtual_branch(project, branch_id, false, None)
.unwrap(); .unwrap();
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
{ {
// merge branch upstream // merge branch upstream
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -618,11 +688,11 @@ mod applied_branch {
{ {
// fetch remote // fetch remote
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// should remove integrated commit, but leave non integrated work as is // should remove integrated commit, but leave non integrated work as is
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -646,7 +716,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -668,14 +737,18 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
// branch has no conflict // branch has no conflict
let branch_id = { let branch_id = {
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write( fs::write(
@ -684,17 +757,14 @@ mod applied_branch {
) )
.unwrap(); .unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "fourth", None, false)
.create_commit(project, branch_id, "fourth", None, false)
.unwrap(); .unwrap();
branch_id branch_id
}; };
// push the branch // push the branch
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
// another locked conflicting hunk // another locked conflicting hunk
fs::write( fs::write(
@ -705,19 +775,22 @@ mod applied_branch {
{ {
// merge branch remotely // merge branch remotely
let branch = controller.list_virtual_branches(project).unwrap().0[0].clone(); let branch = gitbutler_branch_actions::list_virtual_branches(project)
.unwrap()
.0[0]
.clone();
repository.merge(&branch.upstream.as_ref().unwrap().name); repository.merge(&branch.upstream.as_ref().unwrap().name);
} }
repository.fetch(); repository.fetch();
let unapplied_refname = { let unapplied_refname = {
let unapplied_refnames = controller.update_base_branch(project).unwrap(); let unapplied_refnames = gitbutler_branch_actions::update_base_branch(project).unwrap();
assert_eq!(unapplied_refnames.len(), 1); assert_eq!(unapplied_refnames.len(), 1);
// removes integrated commit, leaves non commited work as is // removes integrated commit, leaves non commited work as is
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
assert_eq!( assert_eq!(
fs::read_to_string(repository.path().join("file.txt")).unwrap(), fs::read_to_string(repository.path().join("file.txt")).unwrap(),
@ -728,8 +801,7 @@ mod applied_branch {
}; };
{ {
controller gitbutler_branch_actions::create_virtual_branch_from_branch(
.create_virtual_branch_from_branch(
project, project,
&Refname::from_str(unapplied_refname.as_str()).unwrap(), &Refname::from_str(unapplied_refname.as_str()).unwrap(),
None, None,
@ -739,7 +811,7 @@ mod applied_branch {
let vb_state = VirtualBranchesHandle::new(project.gb_dir()); let vb_state = VirtualBranchesHandle::new(project.gb_dir());
let ctx = CommandContext::open(project).unwrap(); let ctx = CommandContext::open(project).unwrap();
update_workspace_commit(&vb_state, &ctx).unwrap(); update_workspace_commit(&vb_state, &ctx).unwrap();
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert!(branches[0].active); assert!(branches[0].active);
assert!(branches[0].conflicted); assert!(branches[0].conflicted);
@ -759,7 +831,6 @@ mod applied_branch {
repository, repository,
project, project,
project_id, project_id,
controller,
projects, projects,
.. ..
} = &Test::default(); } = &Test::default();
@ -771,45 +842,49 @@ mod applied_branch {
}) })
.unwrap(); .unwrap();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "first").unwrap(); fs::write(repository.path().join("file.txt"), "first").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "first", None, false)
.create_commit(project, branch_id, "first", None, false)
.unwrap(); .unwrap();
branch_id branch_id
}; };
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
// another non-locked hunk // another non-locked hunk
fs::write(repository.path().join("file.txt"), "first\nsecond").unwrap(); fs::write(repository.path().join("file.txt"), "first\nsecond").unwrap();
{ {
// push and merge branch remotely // push and merge branch remotely
let branch = controller.list_virtual_branches(project).unwrap().0[0].clone(); let branch = gitbutler_branch_actions::list_virtual_branches(project)
.unwrap()
.0[0]
.clone();
repository.merge(&branch.upstream.as_ref().unwrap().name); repository.merge(&branch.upstream.as_ref().unwrap().name);
} }
repository.fetch(); repository.fetch();
{ {
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// removes integrated commit, leaves non commited work as is // removes integrated commit, leaves non commited work as is
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -824,50 +899,53 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = { let branch_id = {
// make a branch that conflicts with the remote branch, but doesn't know about it yet // make a branch that conflicts with the remote branch, but doesn't know about it yet
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "first").unwrap(); fs::write(repository.path().join("file.txt"), "first").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "first", None, false)
.create_commit(project, branch_id, "first", None, false)
.unwrap(); .unwrap();
branch_id branch_id
}; };
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
// another non-locked hunk // another non-locked hunk
fs::write(repository.path().join("another_file.txt"), "first").unwrap(); fs::write(repository.path().join("another_file.txt"), "first").unwrap();
{ {
// push and merge branch remotely // push and merge branch remotely
let branch = controller.list_virtual_branches(project).unwrap().0[0].clone(); let branch = gitbutler_branch_actions::list_virtual_branches(project)
.unwrap()
.0[0]
.clone();
repository.merge(&branch.upstream.as_ref().unwrap().name); repository.merge(&branch.upstream.as_ref().unwrap().name);
} }
repository.fetch(); repository.fetch();
{ {
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// removes integrated commit, leaves non commited work as is // removes integrated commit, leaves non commited work as is
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id); assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active); assert!(branches[0].active);
@ -882,7 +960,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -896,30 +973,33 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
{ {
// make a branch that conflicts with the remote branch, but doesn't know about it yet // make a branch that conflicts with the remote branch, but doesn't know about it yet
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file.txt"), "second").unwrap(); fs::write(repository.path().join("file.txt"), "second").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "second", None, false)
.create_commit(project, branch_id, "second", None, false)
.unwrap(); .unwrap();
}; };
{ {
// fetch remote // fetch remote
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// just removes integrated branch // just removes integrated branch
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
} }
} }
@ -929,7 +1009,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -943,38 +1022,42 @@ mod applied_branch {
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
} }
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
{ {
// open pr // open pr
fs::write(repository.path().join("file2.txt"), "new file").unwrap(); fs::write(repository.path().join("file2.txt"), "new file").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "second", None, false)
.create_commit(project, branch_id, "second", None, false)
.unwrap();
controller
.push_virtual_branch(project, branch_id, false, None)
.unwrap(); .unwrap();
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
} }
{ {
// merge pr // merge pr
let branch = controller.list_virtual_branches(project).unwrap().0[0].clone(); let branch = gitbutler_branch_actions::list_virtual_branches(project)
.unwrap()
.0[0]
.clone();
repository.merge(&branch.upstream.as_ref().unwrap().name); repository.merge(&branch.upstream.as_ref().unwrap().name);
repository.fetch(); repository.fetch();
} }
{ {
// fetch remote // fetch remote
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// just removes integrated branch // just removes integrated branch
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 0); assert_eq!(branches.len(), 0);
} }
} }
@ -986,7 +1069,6 @@ mod applied_branch {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
@ -997,21 +1079,23 @@ mod applied_branch {
repository.push(); repository.push();
repository.reset_hard(Some(first_commit_oid)); repository.reset_hard(Some(first_commit_oid));
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_1_id = controller let branch_1_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(project, &BranchCreateRequest::default()) project,
&BranchCreateRequest::default(),
)
.unwrap(); .unwrap();
fs::write(repository.path().join("file-3.txt"), "three").unwrap(); fs::write(repository.path().join("file-3.txt"), "three").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_1_id, "third", None, false)
.create_commit(project, branch_1_id, "third", None, false)
.unwrap(); .unwrap();
let branch_2_id = controller let branch_2_id = gitbutler_branch_actions::create_virtual_branch(
.create_virtual_branch(
project, project,
&BranchCreateRequest { &BranchCreateRequest {
selected_for_changes: Some(true), selected_for_changes: Some(true),
@ -1022,26 +1106,26 @@ mod applied_branch {
fs::write(repository.path().join("file-4.txt"), "four").unwrap(); fs::write(repository.path().join("file-4.txt"), "four").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_2_id, "fourth", None, false)
.create_commit(project, branch_2_id, "fourth", None, false)
.unwrap(); .unwrap();
controller gitbutler_branch_actions::push_virtual_branch(project, branch_2_id, false, None).unwrap();
.push_virtual_branch(project, branch_2_id, false, None)
.unwrap();
let branch = controller.list_virtual_branches(project).unwrap().0[1].clone(); let branch = gitbutler_branch_actions::list_virtual_branches(project)
.unwrap()
.0[1]
.clone();
repository.merge(&branch.upstream.as_ref().unwrap().name); repository.merge(&branch.upstream.as_ref().unwrap().name);
repository.fetch(); repository.fetch();
// TODO(mg): Figure out why test fails without listing first. // TODO(mg): Figure out why test fails without listing first.
controller.list_virtual_branches(project).unwrap(); gitbutler_branch_actions::list_virtual_branches(project).unwrap();
controller.update_base_branch(project).unwrap(); gitbutler_branch_actions::update_base_branch(project).unwrap();
// Verify we have only the first branch left, and that no files // Verify we have only the first branch left, and that no files
// are present. // are present.
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 0); assert_eq!(branches[0].files.len(), 0);
} }

View File

@ -8,47 +8,48 @@ fn head() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.create_commit(project, branch_id, "commit two", None, false)
.unwrap() .unwrap()
}; };
let commit_three_oid = { let commit_three_oid = {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.create_commit(project, branch_id, "commit three", None, false)
.unwrap() .unwrap()
}; };
let commit_three = repository.find_commit(commit_three_oid).unwrap(); let commit_three = repository.find_commit(commit_three_oid).unwrap();
let before_change_id = &commit_three.change_id(); let before_change_id = &commit_three.change_id();
controller gitbutler_branch_actions::update_commit_message(
.update_commit_message(project, branch_id, commit_three_oid, "commit three updated") project,
branch_id,
commit_three_oid,
"commit three updated",
)
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -79,45 +80,46 @@ fn middle() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
{ {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
let commit_two_oid = { let commit_two_oid = {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.create_commit(project, branch_id, "commit two", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.create_commit(project, branch_id, "commit three", None, false)
.unwrap() .unwrap()
}; };
controller gitbutler_branch_actions::update_commit_message(
.update_commit_message(project, branch_id, commit_two_oid, "commit two updated") project,
branch_id,
commit_two_oid,
"commit two updated",
)
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -141,13 +143,14 @@ fn forcepush_allowed() {
repository, repository,
project_id, project_id,
project, project,
controller,
projects, projects,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
projects projects
@ -157,27 +160,27 @@ fn forcepush_allowed() {
}) })
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let commit_one_oid = { let commit_one_oid = {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
gitbutler_branch_actions::update_commit_message(
project,
branch_id,
commit_one_oid,
"commit one updated",
)
.unwrap(); .unwrap();
controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.update_commit_message(project, branch_id, commit_one_oid, "commit one updated")
.unwrap();
let branch = controller
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -198,20 +201,20 @@ fn forcepush_forbidden() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
controller gitbutler_branch_actions::update_virtual_branch(
.update_virtual_branch(
project, project,
BranchUpdateRequest { BranchUpdateRequest {
id: branch_id, id: branch_id,
@ -223,18 +226,19 @@ fn forcepush_forbidden() {
let commit_one_oid = { let commit_one_oid = {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
controller gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
.push_virtual_branch(project, branch_id, false, None)
.unwrap();
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::update_commit_message(
.update_commit_message(project, branch_id, commit_one_oid, "commit one updated",) project,
branch_id,
commit_one_oid,
"commit one updated",
)
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
"force push not allowed" "force push not allowed"
@ -246,45 +250,46 @@ fn root() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let commit_one_oid = { let commit_one_oid = {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file two.txt"), "").unwrap(); fs::write(repository.path().join("file two.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
.create_commit(project, branch_id, "commit two", None, false)
.unwrap() .unwrap()
}; };
{ {
fs::write(repository.path().join("file three.txt"), "").unwrap(); fs::write(repository.path().join("file three.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
.create_commit(project, branch_id, "commit three", None, false)
.unwrap() .unwrap()
}; };
controller gitbutler_branch_actions::update_commit_message(
.update_commit_message(project, branch_id, commit_one_oid, "commit one updated") project,
branch_id,
commit_one_oid,
"commit one updated",
)
.unwrap(); .unwrap();
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -307,28 +312,27 @@ fn empty() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch_id = controller let branch_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let commit_one_oid = { let commit_one_oid = {
fs::write(repository.path().join("file one.txt"), "").unwrap(); fs::write(repository.path().join("file one.txt"), "").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
.create_commit(project, branch_id, "commit one", None, false)
.unwrap() .unwrap()
}; };
assert_eq!( assert_eq!(
controller gitbutler_branch_actions::update_commit_message(project, branch_id, commit_one_oid, "",)
.update_commit_message(project, branch_id, commit_one_oid, "",)
.unwrap_err() .unwrap_err()
.to_string(), .to_string(),
"commit message can not be empty" "commit message can not be empty"

View File

@ -7,50 +7,43 @@ fn detect_upstream_commits() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let oid1 = { let oid1 = {
// create first commit // create first commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
.create_commit(project, branch1_id, "commit", None, false)
.unwrap()
}; };
let oid2 = { let oid2 = {
// create second commit // create second commit
fs::write(repository.path().join("file.txt"), "content2").unwrap(); fs::write(repository.path().join("file.txt"), "content2").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
.create_commit(project, branch1_id, "commit", None, false)
.unwrap()
}; };
// push // push
controller gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None).unwrap();
.push_virtual_branch(project, branch1_id, false, None)
.unwrap();
let oid3 = { let oid3 = {
// create third commit // create third commit
fs::write(repository.path().join("file.txt"), "content3").unwrap(); fs::write(repository.path().join("file.txt"), "content3").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
.create_commit(project, branch1_id, "commit", None, false)
.unwrap()
}; };
{ {
// should correctly detect pushed commits // should correctly detect pushed commits
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 3); assert_eq!(branches[0].commits.len(), 3);
@ -68,43 +61,37 @@ fn detect_integrated_commits() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
controller gitbutler_branch_actions::set_base_branch(
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap()) project,
&"refs/remotes/origin/master".parse().unwrap(),
)
.unwrap(); .unwrap();
let branch1_id = controller let branch1_id =
.create_virtual_branch(project, &BranchCreateRequest::default()) gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
.unwrap(); .unwrap();
let oid1 = { let oid1 = {
// create first commit // create first commit
fs::write(repository.path().join("file.txt"), "content").unwrap(); fs::write(repository.path().join("file.txt"), "content").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
.create_commit(project, branch1_id, "commit", None, false)
.unwrap()
}; };
let oid2 = { let oid2 = {
// create second commit // create second commit
fs::write(repository.path().join("file.txt"), "content2").unwrap(); fs::write(repository.path().join("file.txt"), "content2").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
.create_commit(project, branch1_id, "commit", None, false)
.unwrap()
}; };
// push // push
controller gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None).unwrap();
.push_virtual_branch(project, branch1_id, false, None)
.unwrap();
{ {
// merge branch upstream // merge branch upstream
let branch = controller let branch = gitbutler_branch_actions::list_virtual_branches(project)
.list_virtual_branches(project)
.unwrap() .unwrap()
.0 .0
.into_iter() .into_iter()
@ -117,14 +104,12 @@ fn detect_integrated_commits() {
let oid3 = { let oid3 = {
// create third commit // create third commit
fs::write(repository.path().join("file.txt"), "content3").unwrap(); fs::write(repository.path().join("file.txt"), "content3").unwrap();
controller gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
.create_commit(project, branch1_id, "commit", None, false)
.unwrap()
}; };
{ {
// should correctly detect pushed commits // should correctly detect pushed commits
let (branches, _) = controller.list_virtual_branches(project).unwrap(); let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
assert_eq!(branches.len(), 1); assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id); assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].commits.len(), 3); assert_eq!(branches[0].commits.len(), 3);

View File

@ -8,13 +8,12 @@ fn should_fail_on_incorrect_branch() {
let Test { let Test {
repository, repository,
project, project,
controller,
.. ..
} = &Test::default(); } = &Test::default();
let branch_name: LocalRefname = "refs/heads/somebranch".parse().unwrap(); let branch_name: LocalRefname = "refs/heads/somebranch".parse().unwrap();
repository.checkout(&branch_name); repository.checkout(&branch_name);
let result = controller.list_virtual_branches(project); let result = gitbutler_branch_actions::list_virtual_branches(project);
let err = result.unwrap_err(); let err = result.unwrap_err();
assert_eq!( assert_eq!(

View File

@ -1,7 +1,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use gitbutler_branch_actions::VirtualBranchActions;
use gitbutler_project::Project; use gitbutler_project::Project;
use gitbutler_reference::RemoteRefname; use gitbutler_reference::RemoteRefname;
@ -31,11 +30,13 @@ pub fn add(
.canonicalize()?; .canonicalize()?;
let project = ctrl.add(path)?; let project = ctrl.add(path)?;
if let Some(refname) = refname { if let Some(refname) = refname {
VirtualBranchActions.set_base_branch(&project, &refname)?; gitbutler_branch_actions::set_base_branch(&project, &refname)?;
}; };
debug_print(project) debug_print(project)
} }
pub fn switch_to_workspace(project: Project, refname: RemoteRefname) -> Result<()> { pub fn switch_to_workspace(project: Project, refname: RemoteRefname) -> Result<()> {
debug_print(VirtualBranchActions.set_base_branch(&project, &refname)?) debug_print(gitbutler_branch_actions::set_base_branch(
&project, &refname,
)?)
} }

View File

@ -2,14 +2,14 @@ use anyhow::{bail, Result};
use gitbutler_branch::{ use gitbutler_branch::{
Branch, BranchCreateRequest, BranchIdentity, BranchUpdateRequest, VirtualBranchesHandle, Branch, BranchCreateRequest, BranchIdentity, BranchUpdateRequest, VirtualBranchesHandle,
}; };
use gitbutler_branch_actions::{get_branch_listing_details, list_branches, VirtualBranchActions}; use gitbutler_branch_actions::{get_branch_listing_details, list_branches};
use gitbutler_command_context::CommandContext; use gitbutler_command_context::CommandContext;
use gitbutler_project::Project; use gitbutler_project::Project;
use crate::command::debug_print; use crate::command::debug_print;
pub fn update_target(project: Project) -> Result<()> { pub fn update_target(project: Project) -> Result<()> {
let unapplied = VirtualBranchActions.update_base_branch(&project)?; let unapplied = gitbutler_branch_actions::update_base_branch(&project)?;
debug_print(unapplied) debug_print(unapplied)
} }
@ -19,7 +19,7 @@ pub fn list_all(project: Project) -> Result<()> {
} }
pub fn list_local(project: Project) -> Result<()> { pub fn list_local(project: Project) -> Result<()> {
debug_print(VirtualBranchActions::list_local_branches(project)?) debug_print(gitbutler_branch_actions::list_local_branches(project)?)
} }
pub fn details(project: Project, branch_names: Vec<BranchIdentity>) -> Result<()> { pub fn details(project: Project, branch_names: Vec<BranchIdentity>) -> Result<()> {
@ -45,16 +45,18 @@ pub fn list(project: Project) -> Result<()> {
} }
pub fn status(project: Project) -> Result<()> { pub fn status(project: Project) -> Result<()> {
debug_print(VirtualBranchActions.list_virtual_branches(&project)?) debug_print(gitbutler_branch_actions::list_virtual_branches(&project)?)
} }
pub fn unapply(project: Project, branch_name: String) -> Result<()> { pub fn unapply(project: Project, branch_name: String) -> Result<()> {
let branch = branch_by_name(&project, &branch_name)?; let branch = branch_by_name(&project, &branch_name)?;
debug_print(VirtualBranchActions.convert_to_real_branch(&project, branch.id)?) debug_print(gitbutler_branch_actions::convert_to_real_branch(
&project, branch.id,
)?)
} }
pub fn create(project: Project, branch_name: String, set_default: bool) -> Result<()> { pub fn create(project: Project, branch_name: String, set_default: bool) -> Result<()> {
let new = VirtualBranchActions.create_virtual_branch( let new = gitbutler_branch_actions::create_virtual_branch(
&project, &project,
&BranchCreateRequest { &BranchCreateRequest {
name: Some(branch_name), name: Some(branch_name),
@ -74,7 +76,7 @@ pub fn set_default(project: Project, branch_name: String) -> Result<()> {
} }
fn set_default_branch(project: &Project, branch: &Branch) -> Result<()> { fn set_default_branch(project: &Project, branch: &Branch) -> Result<()> {
VirtualBranchActions.update_virtual_branch( gitbutler_branch_actions::update_virtual_branch(
project, project,
BranchUpdateRequest { BranchUpdateRequest {
id: branch.id, id: branch.id,
@ -91,7 +93,7 @@ fn set_default_branch(project: &Project, branch: &Branch) -> Result<()> {
pub fn commit(project: Project, branch_name: String, message: String) -> Result<()> { pub fn commit(project: Project, branch_name: String, message: String) -> Result<()> {
let branch = branch_by_name(&project, &branch_name)?; let branch = branch_by_name(&project, &branch_name)?;
let (info, skipped) = VirtualBranchActions.list_virtual_branches(&project)?; let (info, skipped) = gitbutler_branch_actions::list_virtual_branches(&project)?;
if !skipped.is_empty() { if !skipped.is_empty() {
eprintln!( eprintln!(
@ -129,7 +131,7 @@ pub fn commit(project: Project, branch_name: String, message: String) -> Result<
} }
let run_hooks = false; let run_hooks = false;
debug_print(VirtualBranchActions.create_commit( debug_print(gitbutler_branch_actions::create_commit(
&project, &project,
branch.id, branch.id,
&message, &message,

View File

@ -4,7 +4,8 @@ use anyhow::{bail, Context, Result};
use bstr::ByteSlice; use bstr::ByteSlice;
use git2::build::CheckoutBuilder; use git2::build::CheckoutBuilder;
use gitbutler_branch::{signature, Branch, SignaturePurpose, VirtualBranchesHandle}; use gitbutler_branch::{signature, Branch, SignaturePurpose, VirtualBranchesHandle};
use gitbutler_branch_actions::{list_virtual_branches, update_workspace_commit, RemoteBranchFile}; use gitbutler_branch_actions::internal::list_virtual_branches;
use gitbutler_branch_actions::{update_workspace_commit, RemoteBranchFile};
use gitbutler_cherry_pick::RepositoryExt as _; use gitbutler_cherry_pick::RepositoryExt as _;
use gitbutler_command_context::CommandContext; use gitbutler_command_context::CommandContext;
use gitbutler_commit::{ use gitbutler_commit::{

View File

@ -1,6 +1,6 @@
pub mod commands { pub mod commands {
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use gitbutler_branch_actions::{RemoteBranchFile, VirtualBranchActions}; use gitbutler_branch_actions::RemoteBranchFile;
use gitbutler_project as projects; use gitbutler_project as projects;
use gitbutler_project::ProjectId; use gitbutler_project::ProjectId;
use gitbutler_repo::RepoCommands; use gitbutler_repo::RepoCommands;
@ -69,6 +69,6 @@ pub mod commands {
) -> Result<Vec<RemoteBranchFile>, Error> { ) -> Result<Vec<RemoteBranchFile>, Error> {
let project = projects.get(id)?; let project = projects.get(id)?;
Ok(VirtualBranchActions.get_uncommited_files(&project)?) Ok(gitbutler_branch_actions::get_uncommited_files(&project)?)
} }
} }

View File

@ -5,7 +5,7 @@ pub mod commands {
}; };
use gitbutler_branch_actions::{ use gitbutler_branch_actions::{
BaseBranch, BranchListing, BranchListingDetails, BranchListingFilter, RemoteBranch, BaseBranch, BranchListing, BranchListingDetails, BranchListingFilter, RemoteBranch,
RemoteBranchData, RemoteBranchFile, VirtualBranchActions, VirtualBranches, RemoteBranchData, RemoteBranchFile, VirtualBranches,
}; };
use gitbutler_command_context::CommandContext; use gitbutler_command_context::CommandContext;
use gitbutler_error::error::Code; use gitbutler_error::error::Code;
@ -38,7 +38,7 @@ pub mod commands {
run_hooks: bool, run_hooks: bool,
) -> Result<String, Error> { ) -> Result<String, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let oid = VirtualBranchActions.create_commit( let oid = gitbutler_branch_actions::create_commit(
&project, &project,
branch, branch,
message, message,
@ -56,8 +56,7 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
) -> Result<VirtualBranches, Error> { ) -> Result<VirtualBranches, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions gitbutler_branch_actions::list_virtual_branches(&project)
.list_virtual_branches(&project)
.map_err(Into::into) .map_err(Into::into)
.map(|(branches, skipped_files)| VirtualBranches { .map(|(branches, skipped_files)| VirtualBranches {
branches, branches,
@ -74,7 +73,7 @@ pub mod commands {
branch: BranchCreateRequest, branch: BranchCreateRequest,
) -> Result<BranchId, Error> { ) -> Result<BranchId, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let branch_id = VirtualBranchActions.create_virtual_branch(&project, &branch)?; let branch_id = gitbutler_branch_actions::create_virtual_branch(&project, &branch)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(branch_id) Ok(branch_id)
} }
@ -89,7 +88,7 @@ pub mod commands {
given_name: String, given_name: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.delete_local_branch(&project, &refname, given_name)?; gitbutler_branch_actions::delete_local_branch(&project, &refname, given_name)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -105,7 +104,7 @@ pub mod commands {
) -> Result<BranchId, Error> { ) -> Result<BranchId, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let branch_id = let branch_id =
VirtualBranchActions.create_virtual_branch_from_branch(&project, &branch, remote)?; gitbutler_branch_actions::create_virtual_branch_from_branch(&project, &branch, remote)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(branch_id) Ok(branch_id)
} }
@ -119,7 +118,7 @@ pub mod commands {
branch: BranchId, branch: BranchId,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.integrate_upstream_commits(&project, branch)?; gitbutler_branch_actions::integrate_upstream_commits(&project, branch)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -131,7 +130,7 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
) -> Result<Option<BaseBranch>, Error> { ) -> Result<Option<BaseBranch>, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
if let Ok(base_branch) = VirtualBranchActions::get_base_branch_data(&project) { if let Ok(base_branch) = gitbutler_branch_actions::get_base_branch_data(&project) {
Ok(Some(base_branch)) Ok(Some(base_branch))
} else { } else {
Ok(None) Ok(None)
@ -151,11 +150,11 @@ pub mod commands {
let branch_name = format!("refs/remotes/{}", branch) let branch_name = format!("refs/remotes/{}", branch)
.parse() .parse()
.context("Invalid branch name")?; .context("Invalid branch name")?;
let base_branch = VirtualBranchActions.set_base_branch(&project, &branch_name)?; let base_branch = gitbutler_branch_actions::set_base_branch(&project, &branch_name)?;
// if they also sent a different push remote, set that too // if they also sent a different push remote, set that too
if let Some(push_remote) = push_remote { if let Some(push_remote) = push_remote {
VirtualBranchActions.set_target_push_remote(&project, push_remote)?; gitbutler_branch_actions::set_target_push_remote(&project, push_remote)?;
} }
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(base_branch) Ok(base_branch)
@ -169,7 +168,7 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
) -> Result<Vec<ReferenceName>, Error> { ) -> Result<Vec<ReferenceName>, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let unapplied_branches = VirtualBranchActions.update_base_branch(&project)?; let unapplied_branches = gitbutler_branch_actions::update_base_branch(&project)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(unapplied_branches) Ok(unapplied_branches)
} }
@ -183,7 +182,7 @@ pub mod commands {
branch: BranchUpdateRequest, branch: BranchUpdateRequest,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.update_virtual_branch(&project, branch)?; gitbutler_branch_actions::update_virtual_branch(&project, branch)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
@ -198,7 +197,7 @@ pub mod commands {
branches: Vec<BranchUpdateRequest>, branches: Vec<BranchUpdateRequest>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.update_branch_order(&project, branches)?; gitbutler_branch_actions::update_branch_order(&project, branches)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -212,7 +211,7 @@ pub mod commands {
branch_id: BranchId, branch_id: BranchId,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.delete_virtual_branch(&project, branch_id)?; gitbutler_branch_actions::delete_virtual_branch(&project, branch_id)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -226,7 +225,7 @@ pub mod commands {
branch: BranchId, branch: BranchId,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.convert_to_real_branch(&project, branch)?; gitbutler_branch_actions::convert_to_real_branch(&project, branch)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -240,7 +239,7 @@ pub mod commands {
ownership: BranchOwnershipClaims, ownership: BranchOwnershipClaims,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.unapply_ownership(&project, &ownership)?; gitbutler_branch_actions::unapply_ownership(&project, &ownership)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -255,7 +254,7 @@ pub mod commands {
files: Vec<PathBuf>, files: Vec<PathBuf>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.reset_files(&project, branch_id, &files)?; gitbutler_branch_actions::reset_files(&project, branch_id, &files)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -270,8 +269,12 @@ pub mod commands {
with_force: bool, with_force: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions gitbutler_branch_actions::push_virtual_branch(
.push_virtual_branch(&project, branch_id, with_force, Some(Some(branch_id))) &project,
branch_id,
with_force,
Some(Some(branch_id)),
)
.map_err(|err| err.context(Code::Unknown))?; .map_err(|err| err.context(Code::Unknown))?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
@ -285,7 +288,9 @@ pub mod commands {
branch: RemoteRefname, branch: RemoteRefname,
) -> Result<bool, Error> { ) -> Result<bool, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
Ok(VirtualBranchActions.can_apply_remote_branch(&project, &branch)?) Ok(gitbutler_branch_actions::can_apply_remote_branch(
&project, &branch,
)?)
} }
#[tauri::command(async)] #[tauri::command(async)]
@ -297,9 +302,7 @@ pub mod commands {
) -> Result<Vec<RemoteBranchFile>, Error> { ) -> Result<Vec<RemoteBranchFile>, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
VirtualBranchActions gitbutler_branch_actions::list_remote_commit_files(&project, commit_oid).map_err(Into::into)
.list_remote_commit_files(&project, commit_oid)
.map_err(Into::into)
} }
#[tauri::command(async)] #[tauri::command(async)]
@ -313,7 +316,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?; let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
VirtualBranchActions.reset_virtual_branch(&project, branch_id, target_commit_oid)?; gitbutler_branch_actions::reset_virtual_branch(&project, branch_id, target_commit_oid)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -330,7 +333,7 @@ pub mod commands {
) -> Result<String, Error> { ) -> Result<String, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
let oid = VirtualBranchActions.amend(&project, branch_id, commit_oid, &ownership)?; let oid = gitbutler_branch_actions::amend(&project, branch_id, commit_oid, &ownership)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(oid.to_string()) Ok(oid.to_string())
} }
@ -349,7 +352,7 @@ pub mod commands {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let from_commit_oid = git2::Oid::from_str(&from_commit_oid).map_err(|e| anyhow!(e))?; let from_commit_oid = git2::Oid::from_str(&from_commit_oid).map_err(|e| anyhow!(e))?;
let to_commit_oid = git2::Oid::from_str(&to_commit_oid).map_err(|e| anyhow!(e))?; let to_commit_oid = git2::Oid::from_str(&to_commit_oid).map_err(|e| anyhow!(e))?;
let oid = VirtualBranchActions.move_commit_file( let oid = gitbutler_branch_actions::move_commit_file(
&project, &project,
branch_id, branch_id,
from_commit_oid, from_commit_oid,
@ -371,7 +374,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
VirtualBranchActions.undo_commit(&project, branch_id, commit_oid)?; gitbutler_branch_actions::undo_commit(&project, branch_id, commit_oid)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -388,7 +391,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
VirtualBranchActions.insert_blank_commit(&project, branch_id, commit_oid, offset)?; gitbutler_branch_actions::insert_blank_commit(&project, branch_id, commit_oid, offset)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -404,7 +407,7 @@ pub mod commands {
change_id: String, change_id: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.create_change_reference(&project, branch_id, name, change_id)?; gitbutler_branch_actions::create_change_reference(&project, branch_id, name, change_id)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -420,7 +423,7 @@ pub mod commands {
with_force: bool, with_force: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.push_change_reference(&project, branch_id, name, with_force)?; gitbutler_branch_actions::push_change_reference(&project, branch_id, name, with_force)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -436,7 +439,12 @@ pub mod commands {
new_change_id: String, new_change_id: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
VirtualBranchActions.update_change_reference(&project, branch_id, name, new_change_id)?; gitbutler_branch_actions::update_change_reference(
&project,
branch_id,
name,
new_change_id,
)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -453,7 +461,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
VirtualBranchActions.reorder_commit(&project, branch_id, commit_oid, offset)?; gitbutler_branch_actions::reorder_commit(&project, branch_id, commit_oid, offset)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -465,7 +473,7 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
) -> Result<Vec<RemoteBranch>, Error> { ) -> Result<Vec<RemoteBranch>, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let branches = VirtualBranchActions::list_local_branches(project)?; let branches = gitbutler_branch_actions::list_local_branches(project)?;
Ok(branches) Ok(branches)
} }
@ -501,7 +509,7 @@ pub mod commands {
refname: Refname, refname: Refname,
) -> Result<RemoteBranchData, Error> { ) -> Result<RemoteBranchData, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let branch_data = VirtualBranchActions.get_remote_branch_data(&project, &refname)?; let branch_data = gitbutler_branch_actions::get_remote_branch_data(&project, &refname)?;
Ok(branch_data) Ok(branch_data)
} }
@ -516,7 +524,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?; let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
VirtualBranchActions.squash(&project, branch_id, target_commit_oid)?; gitbutler_branch_actions::squash(&project, branch_id, target_commit_oid)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -530,7 +538,7 @@ pub mod commands {
) -> Result<BaseBranch, Error> { ) -> Result<BaseBranch, Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let project_data_last_fetched = VirtualBranchActions.fetch_from_remotes( let project_data_last_fetched = gitbutler_branch_actions::fetch_from_remotes(
&project, &project,
Some(action.unwrap_or_else(|| "unknown".to_string())), Some(action.unwrap_or_else(|| "unknown".to_string())),
)?; )?;
@ -550,7 +558,7 @@ pub mod commands {
return Err(anyhow!(error).into()); return Err(anyhow!(error).into());
} }
let base_branch = VirtualBranchActions::get_base_branch_data(&project)?; let base_branch = gitbutler_branch_actions::get_base_branch_data(&project)?;
Ok(base_branch) Ok(base_branch)
} }
@ -565,7 +573,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
VirtualBranchActions.move_commit(&project, target_branch_id, commit_oid)?; gitbutler_branch_actions::move_commit(&project, target_branch_id, commit_oid)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }
@ -582,7 +590,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
VirtualBranchActions.update_commit_message(&project, branch_id, commit_oid, message)?; gitbutler_branch_actions::update_commit_message(&project, branch_id, commit_oid, message)?;
emit_vbranches(&windows, project_id); emit_vbranches(&windows, project_id);
Ok(()) Ok(())
} }

View File

@ -2,7 +2,7 @@ use std::{path::PathBuf, sync::Arc};
use super::{events, Change}; use super::{events, Change};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use gitbutler_branch_actions::{RemoteBranchFile, VirtualBranchActions, VirtualBranches}; use gitbutler_branch_actions::{RemoteBranchFile, VirtualBranches};
use gitbutler_command_context::CommandContext; use gitbutler_command_context::CommandContext;
use gitbutler_diff::DiffByPathMap; use gitbutler_diff::DiffByPathMap;
use gitbutler_error::error::Marker; use gitbutler_error::error::Marker;
@ -106,7 +106,7 @@ impl Handler {
.projects .projects
.get(project_id) .get(project_id)
.context("failed to get project")?; .context("failed to get project")?;
match VirtualBranchActions.list_virtual_branches_cached(&project, worktree_changes) { match gitbutler_branch_actions::list_virtual_branches_cached(&project, worktree_changes) {
Ok((branches, skipped_files)) => self.emit_app_event(Change::VirtualBranches { Ok((branches, skipped_files)) => self.emit_app_event(Change::VirtualBranches {
project_id: project.id, project_id: project.id,
virtual_branches: VirtualBranches { virtual_branches: VirtualBranches {
@ -142,7 +142,7 @@ impl Handler {
/// Try to emit uncommited files. Swollow errors if they arrise. /// Try to emit uncommited files. Swollow errors if they arrise.
fn emit_uncommited_files(&self, project: &Project) -> Result<DiffByPathMap> { fn emit_uncommited_files(&self, project: &Project) -> Result<DiffByPathMap> {
let files = VirtualBranchActions.get_uncommited_files_reusable(project)?; let files = gitbutler_branch_actions::get_uncommited_files_reusable(project)?;
let _ = self.emit_app_event(Change::UncommitedFiles { let _ = self.emit_app_event(Change::UncommitedFiles {
project_id: project.id, project_id: project.id,