mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-25 02:26:14 +03:00
Remove unnecessary VirtualBranchActions struct
This commit is contained in:
parent
32d766c2d6
commit
95e946b8a1
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,6 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::r#virtual as vbranch;
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use gitbutler_branch::{self, dedup, Branch, BranchCreateRequest, BranchId, BranchOwnershipClaims};
|
||||
use gitbutler_commit::commit_headers::HasCommitHeaders;
|
||||
@ -14,10 +15,9 @@ use tracing::instrument;
|
||||
use super::BranchManager;
|
||||
use crate::{
|
||||
conflicts::{self, RepoConflictsExt},
|
||||
ensure_selected_for_changes,
|
||||
hunk::VirtualBranchHunk,
|
||||
integration::update_workspace_commit,
|
||||
set_ownership, undo_commit, VirtualBranchesExt,
|
||||
VirtualBranchesExt,
|
||||
};
|
||||
|
||||
impl BranchManager<'_> {
|
||||
@ -118,7 +118,8 @@ impl BranchManager<'_> {
|
||||
};
|
||||
|
||||
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())?;
|
||||
@ -489,7 +490,8 @@ impl BranchManager<'_> {
|
||||
// apply the branch
|
||||
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
|
||||
repo.checkout_index_builder(&mut merge_index)
|
||||
.force()
|
||||
@ -505,7 +507,7 @@ impl BranchManager<'_> {
|
||||
|
||||
if let Some(headers) = potential_wip_commit.gitbutler_headers() {
|
||||
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)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,10 @@ use gitbutler_repo::{RepoActionsExt, RepositoryExt};
|
||||
use tracing::instrument;
|
||||
|
||||
use super::BranchManager;
|
||||
use crate::r#virtual as vbranch;
|
||||
use crate::{
|
||||
conflicts::{self},
|
||||
ensure_selected_for_changes, get_applied_status,
|
||||
get_applied_status,
|
||||
hunk::VirtualBranchHunk,
|
||||
VirtualBranchesExt,
|
||||
};
|
||||
@ -47,7 +48,8 @@ impl BranchManager<'_> {
|
||||
vb_state.update_ordering()?;
|
||||
|
||||
// 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)?;
|
||||
|
||||
@ -132,7 +134,8 @@ impl BranchManager<'_> {
|
||||
|
||||
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(())
|
||||
}
|
||||
|
@ -1,9 +1,27 @@
|
||||
//! GitButler internal library containing functionality related to branches, i.e. the virtual branches implementation
|
||||
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;
|
||||
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;
|
||||
pub use branch_manager::{BranchManager, BranchManagerExt};
|
||||
@ -18,7 +36,7 @@ mod file;
|
||||
pub use file::{Get, RemoteBranchFile};
|
||||
|
||||
mod remote;
|
||||
pub use remote::{list_local_branches, RemoteBranch, RemoteBranchData, RemoteCommit};
|
||||
pub use remote::{RemoteBranch, RemoteBranchData, RemoteCommit};
|
||||
|
||||
pub mod conflicts;
|
||||
|
||||
|
@ -16,9 +16,7 @@ use gitbutler_branch::{
|
||||
BranchCreateRequest, BranchOwnershipClaims, BranchUpdateRequest, Target, VirtualBranchesHandle,
|
||||
};
|
||||
use gitbutler_branch_actions::{
|
||||
commit, get_applied_status, integrate_upstream_commits, is_remote_branch_mergeable,
|
||||
list_virtual_branches, unapply_ownership, update_branch, update_workspace_commit,
|
||||
verify_branch, BranchManagerExt, Get,
|
||||
get_applied_status, internal, update_workspace_commit, verify_branch, BranchManagerExt, Get,
|
||||
};
|
||||
use gitbutler_commit::{commit_ext::CommitExt, commit_headers::CommitHeadersV2};
|
||||
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",
|
||||
)?;
|
||||
|
||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
||||
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||
let branch = &branches[0];
|
||||
assert_eq!(branch.files.len(), 1);
|
||||
assert_eq!(branch.commits.len(), 0);
|
||||
|
||||
// commit
|
||||
commit(ctx, branch1_id, "test commit", None, false)?;
|
||||
internal::commit(ctx, branch1_id, "test commit", None, false)?;
|
||||
|
||||
// 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];
|
||||
assert_eq!(branch.files.len(), 0);
|
||||
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
|
||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
||||
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||
let branch = &branches[0];
|
||||
assert_eq!(branch.files.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"))?;
|
||||
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];
|
||||
assert_eq!(branch.files.len(), 2);
|
||||
let img_file = &branch
|
||||
@ -144,10 +142,10 @@ fn track_binary_files() -> Result<()> {
|
||||
);
|
||||
|
||||
// commit
|
||||
commit(ctx, branch1_id, "test commit", None, false)?;
|
||||
internal::commit(ctx, branch1_id, "test commit", None, false)?;
|
||||
|
||||
// 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_obj = ctx.repository().find_commit(commit_id.to_owned())?;
|
||||
let tree = commit_obj.tree()?;
|
||||
@ -168,9 +166,9 @@ fn track_binary_files() -> Result<()> {
|
||||
file.write_all(&image_data)?;
|
||||
|
||||
// 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;
|
||||
// get tree from commit_id
|
||||
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);
|
||||
|
||||
// even though selected branch has changed
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
id: branch1_id,
|
||||
@ -343,7 +341,7 @@ fn hunk_expantion() -> Result<()> {
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
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[&branch3_id].len(), 0);
|
||||
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
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[&branch2_id].len(), 0);
|
||||
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
id: branch2_id,
|
||||
@ -828,7 +826,7 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
|
||||
vb_state.set_branch(branch.clone())?;
|
||||
|
||||
// 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);
|
||||
let branch1 = &branches[0];
|
||||
assert_eq!(
|
||||
@ -840,9 +838,9 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
|
||||
assert_eq!(branch1.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 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;
|
||||
vb_state.set_branch(branch.clone())?;
|
||||
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
id: branch.id,
|
||||
@ -944,16 +942,16 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
|
||||
.unwrap();
|
||||
|
||||
// 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];
|
||||
|
||||
assert_eq!(branch1.files.len(), 1);
|
||||
assert_eq!(branch1.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 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
|
||||
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);
|
||||
|
||||
// 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];
|
||||
assert!(!branch1.conflicted);
|
||||
assert_eq!(branch1.files.len(), 0);
|
||||
@ -1015,7 +1013,7 @@ fn unapply_ownership_partial() -> Result<()> {
|
||||
.create_virtual_branch(&BranchCreateRequest::default(), guard.write_permission())
|
||||
.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[0].files.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"
|
||||
);
|
||||
|
||||
unapply_ownership(
|
||||
internal::unapply_ownership(
|
||||
ctx,
|
||||
&"test.txt:2-6".parse().unwrap(),
|
||||
guard.write_permission(),
|
||||
)
|
||||
.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[0].files.len(), 0);
|
||||
assert_eq!(branches[0].ownership.claims.len(), 0);
|
||||
@ -1078,7 +1076,7 @@ fn unapply_branch() -> Result<()> {
|
||||
.expect("failed to create virtual branch")
|
||||
.id;
|
||||
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
id: branch2_id,
|
||||
@ -1095,7 +1093,7 @@ fn unapply_branch() -> Result<()> {
|
||||
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
|
||||
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();
|
||||
assert_eq!(branch.files.len(), 1);
|
||||
assert!(branch.active);
|
||||
@ -1109,7 +1107,7 @@ fn unapply_branch() -> Result<()> {
|
||||
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
|
||||
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));
|
||||
|
||||
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))?;
|
||||
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();
|
||||
// TODO: expect there to be 0 branches
|
||||
assert_eq!(branch.files.len(), 0);
|
||||
@ -1165,7 +1163,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
|
||||
.expect("failed to create virtual branch")
|
||||
.id;
|
||||
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
id: branch2_id,
|
||||
@ -1173,7 +1171,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
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 real_branch_2 =
|
||||
@ -1257,7 +1255,7 @@ fn detect_mergeable_branch() -> Result<()> {
|
||||
.expect("failed to create virtual branch")
|
||||
.id;
|
||||
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
id: branch2_id,
|
||||
@ -1344,13 +1342,13 @@ fn detect_mergeable_branch() -> Result<()> {
|
||||
};
|
||||
vb_state.set_branch(branch4.clone())?;
|
||||
|
||||
let remotes =
|
||||
gitbutler_branch_actions::list_local_branches(ctx).expect("failed to list remotes");
|
||||
let remotes = gitbutler_branch_actions::internal::list_local_branches(ctx)
|
||||
.expect("failed to list remotes");
|
||||
let _remote1 = &remotes
|
||||
.iter()
|
||||
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch")
|
||||
.unwrap();
|
||||
assert!(!is_remote_branch_mergeable(
|
||||
assert!(!internal::is_remote_branch_mergeable(
|
||||
ctx,
|
||||
&"refs/remotes/origin/remote_branch".parse().unwrap()
|
||||
)
|
||||
@ -1361,7 +1359,7 @@ fn detect_mergeable_branch() -> Result<()> {
|
||||
.iter()
|
||||
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch2")
|
||||
.unwrap();
|
||||
assert!(is_remote_branch_mergeable(
|
||||
assert!(internal::is_remote_branch_mergeable(
|
||||
ctx,
|
||||
&"refs/remotes/origin/remote_branch2".parse().unwrap()
|
||||
)
|
||||
@ -1437,7 +1435,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
||||
"file3\nversion2\n",
|
||||
)?;
|
||||
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
id: branch1_id,
|
||||
@ -1447,7 +1445,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
||||
},
|
||||
)?;
|
||||
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
id: branch2_id,
|
||||
@ -1457,7 +1455,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
||||
},
|
||||
)?;
|
||||
|
||||
update_branch(
|
||||
internal::update_branch(
|
||||
ctx,
|
||||
&BranchUpdateRequest {
|
||||
id: branch3_id,
|
||||
@ -1468,10 +1466,10 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
||||
)?;
|
||||
|
||||
// create a new virtual branch from the remote branch
|
||||
commit(ctx, branch1_id, "integrated commit", None, false)?;
|
||||
commit(ctx, branch2_id, "non-integrated commit", None, false)?;
|
||||
internal::commit(ctx, branch1_id, "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();
|
||||
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",
|
||||
)?;
|
||||
|
||||
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();
|
||||
|
||||
assert_eq!(branch.files.len(), 1);
|
||||
@ -1525,9 +1523,9 @@ fn commit_same_hunk_twice() -> Result<()> {
|
||||
assert_eq!(branch.commits.len(), 0);
|
||||
|
||||
// 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();
|
||||
|
||||
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",
|
||||
)?;
|
||||
|
||||
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();
|
||||
|
||||
assert_eq!(branch.files.len(), 1, "one file should be changed");
|
||||
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();
|
||||
|
||||
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",
|
||||
)?;
|
||||
|
||||
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();
|
||||
|
||||
assert_eq!(branch.files.len(), 1);
|
||||
@ -1607,9 +1605,9 @@ fn commit_same_file_twice() -> Result<()> {
|
||||
assert_eq!(branch.commits.len(), 0);
|
||||
|
||||
// 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();
|
||||
|
||||
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",
|
||||
)?;
|
||||
|
||||
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();
|
||||
|
||||
assert_eq!(branch.files.len(), 1, "one file should be changed");
|
||||
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();
|
||||
|
||||
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",
|
||||
)?;
|
||||
|
||||
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();
|
||||
|
||||
assert_eq!(branch.files.len(), 1);
|
||||
@ -1689,7 +1687,7 @@ fn commit_partial_by_hunk() -> Result<()> {
|
||||
assert_eq!(branch.commits.len(), 0);
|
||||
|
||||
// commit
|
||||
commit(
|
||||
internal::commit(
|
||||
ctx,
|
||||
branch1_id,
|
||||
"first commit to test.txt",
|
||||
@ -1697,7 +1695,7 @@ fn commit_partial_by_hunk() -> Result<()> {
|
||||
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();
|
||||
|
||||
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[0].hunks.len(), 1);
|
||||
|
||||
commit(
|
||||
internal::commit(
|
||||
ctx,
|
||||
branch1_id,
|
||||
"second commit to test.txt",
|
||||
@ -1714,7 +1712,7 @@ fn commit_partial_by_hunk() -> Result<()> {
|
||||
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();
|
||||
|
||||
assert_eq!(branch.files.len(), 0);
|
||||
@ -1754,9 +1752,9 @@ fn commit_partial_by_file() -> Result<()> {
|
||||
.id;
|
||||
|
||||
// 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();
|
||||
|
||||
// branch one test.txt has just the 1st and 3rd hunks applied
|
||||
@ -1805,9 +1803,9 @@ fn commit_add_and_delete_files() -> Result<()> {
|
||||
.id;
|
||||
|
||||
// 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();
|
||||
|
||||
// branch one test.txt has just the 1st and 3rd hunks applied
|
||||
@ -1862,9 +1860,9 @@ fn commit_executable_and_symlinks() -> Result<()> {
|
||||
.id;
|
||||
|
||||
// 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 commit = &branch1.commits[0].id;
|
||||
@ -1960,7 +1958,7 @@ fn verify_branch_commits_to_workspace() -> Result<()> {
|
||||
verify_branch(ctx, guard.write_permission()).unwrap();
|
||||
|
||||
// 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);
|
||||
|
||||
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);
|
||||
|
||||
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();
|
||||
assert_eq!(
|
||||
@ -2064,7 +2062,7 @@ fn post_commit_hook() -> Result<()> {
|
||||
|
||||
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());
|
||||
|
||||
@ -2100,7 +2098,7 @@ fn commit_msg_hook_rejection() -> Result<()> {
|
||||
|
||||
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();
|
||||
assert_eq!(
|
||||
|
@ -8,7 +8,6 @@ fn forcepush_allowed() {
|
||||
repository,
|
||||
project_id,
|
||||
project,
|
||||
controller,
|
||||
projects,
|
||||
..
|
||||
} = &Test::default();
|
||||
@ -20,9 +19,11 @@ fn forcepush_allowed() {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
projects
|
||||
.update(&projects::UpdateRequest {
|
||||
@ -31,30 +32,25 @@ fn forcepush_allowed() {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let commit_id = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let commit_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.push_virtual_branch(project, branch_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||
|
||||
{
|
||||
// amend another hunk
|
||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||
controller
|
||||
.amend(project, branch_id, commit_id, &to_amend)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::amend(project, branch_id, commit_id, &to_amend).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -72,45 +68,42 @@ fn forcepush_forbidden() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch_id,
|
||||
allow_rebasing: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch_id,
|
||||
allow_rebasing: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let commit_oid = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.push_virtual_branch(project, branch_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||
assert_eq!(
|
||||
controller
|
||||
.amend(project, branch_id, commit_oid, &to_amend)
|
||||
gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"force-push is not allowed"
|
||||
@ -123,26 +116,26 @@ fn non_locked_hunk() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let commit_oid = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -156,12 +149,9 @@ fn non_locked_hunk() {
|
||||
// amend another hunk
|
||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||
controller
|
||||
.amend(project, branch_id, commit_oid, &to_amend)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -178,26 +168,26 @@ fn locked_hunk() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let commit_oid = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -215,12 +205,9 @@ fn locked_hunk() {
|
||||
// amend another hunk
|
||||
fs::write(repository.path().join("file.txt"), "more content").unwrap();
|
||||
let to_amend: BranchOwnershipClaims = "file.txt:1-2".parse().unwrap();
|
||||
controller
|
||||
.amend(project, branch_id, commit_oid, &to_amend)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -242,26 +229,26 @@ fn non_existing_ownership() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let commit_oid = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -275,8 +262,7 @@ fn non_existing_ownership() {
|
||||
// amend non existing hunk
|
||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||
assert_eq!(
|
||||
controller
|
||||
.amend(project, branch_id, commit_oid, &to_amend)
|
||||
gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"target ownership not found"
|
||||
|
@ -8,7 +8,6 @@ fn rebase_commit() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -23,22 +22,25 @@ fn rebase_commit() {
|
||||
repository.reset_hard(Some(first_commit_oid));
|
||||
}
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut branch1_id = {
|
||||
// create a branch with some commited work
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest::default(),
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(repository.path().join("another_file.txt"), "virtual").unwrap();
|
||||
|
||||
controller
|
||||
.create_commit(project, branch1_id, "virtual commit", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "virtual commit", 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[0].id, branch1_id);
|
||||
assert!(branches[0].active);
|
||||
@ -50,9 +52,8 @@ fn rebase_commit() {
|
||||
|
||||
let unapplied_branch = {
|
||||
// unapply first vbranch
|
||||
let unapplied_branch = controller
|
||||
.convert_to_real_branch(project, branch1_id)
|
||||
.unwrap();
|
||||
let unapplied_branch =
|
||||
gitbutler_branch_actions::convert_to_real_branch(project, branch1_id).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
fs::read_to_string(repository.path().join("another_file.txt")).unwrap(),
|
||||
@ -63,7 +64,7 @@ fn rebase_commit() {
|
||||
"one"
|
||||
);
|
||||
|
||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
||||
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||
assert_eq!(branches.len(), 0);
|
||||
|
||||
Refname::from_str(&unapplied_branch).unwrap()
|
||||
@ -71,10 +72,10 @@ fn rebase_commit() {
|
||||
|
||||
{
|
||||
// fetch remote
|
||||
controller.update_base_branch(project).unwrap();
|
||||
gitbutler_branch_actions::update_base_branch(project).unwrap();
|
||||
|
||||
// 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!(
|
||||
@ -89,12 +90,15 @@ fn rebase_commit() {
|
||||
|
||||
{
|
||||
// apply first vbranch again
|
||||
branch1_id = controller
|
||||
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
||||
.unwrap();
|
||||
branch1_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||
project,
|
||||
&unapplied_branch,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// 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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].files.len(), 0);
|
||||
@ -119,7 +123,6 @@ fn rebase_work() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -132,18 +135,22 @@ fn rebase_work() {
|
||||
repository.reset_hard(Some(first_commit_oid));
|
||||
}
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut branch1_id = {
|
||||
// make a branch with some work
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest::default(),
|
||||
)
|
||||
.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[0].id, branch1_id);
|
||||
assert!(branches[0].active);
|
||||
@ -155,11 +162,10 @@ fn rebase_work() {
|
||||
|
||||
let unapplied_branch = {
|
||||
// unapply first vbranch
|
||||
let unapplied_branch = controller
|
||||
.convert_to_real_branch(project, branch1_id)
|
||||
.unwrap();
|
||||
let unapplied_branch =
|
||||
gitbutler_branch_actions::convert_to_real_branch(project, branch1_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!(!repository.path().join("another_file.txt").exists());
|
||||
@ -170,10 +176,10 @@ fn rebase_work() {
|
||||
|
||||
{
|
||||
// fetch remote
|
||||
controller.update_base_branch(project).unwrap();
|
||||
gitbutler_branch_actions::update_base_branch(project).unwrap();
|
||||
|
||||
// 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!(!repository.path().join("another_file.txt").exists());
|
||||
@ -182,12 +188,15 @@ fn rebase_work() {
|
||||
|
||||
{
|
||||
// apply first vbranch again
|
||||
branch1_id = controller
|
||||
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
||||
.unwrap();
|
||||
branch1_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||
project,
|
||||
&unapplied_branch,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// 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[0].id, branch1_id);
|
||||
// TODO: Should be 1
|
||||
|
@ -4,27 +4,26 @@ use super::*;
|
||||
fn unapply_with_data() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.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);
|
||||
|
||||
controller
|
||||
.convert_to_real_branch(project, branches[0].id)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::convert_to_real_branch(project, branches[0].id).unwrap();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -32,7 +31,6 @@ fn unapply_with_data() {
|
||||
fn conflicting() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
@ -47,16 +45,18 @@ fn conflicting() {
|
||||
repository.reset_hard(Some(first_commit_oid));
|
||||
}
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let unapplied_branch = {
|
||||
// make a conflicting branch, and stash it
|
||||
|
||||
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);
|
||||
let branch = &branches[0];
|
||||
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"
|
||||
);
|
||||
|
||||
let unapplied_branch = controller
|
||||
.convert_to_real_branch(project, branch.id)
|
||||
.unwrap();
|
||||
let unapplied_branch =
|
||||
gitbutler_branch_actions::convert_to_real_branch(project, branch.id).unwrap();
|
||||
|
||||
Refname::from_str(&unapplied_branch).unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
// update base branch, causing conflict
|
||||
controller.update_base_branch(project).unwrap();
|
||||
gitbutler_branch_actions::update_base_branch(project).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
||||
@ -89,9 +88,12 @@ fn conflicting() {
|
||||
|
||||
let branch_id = {
|
||||
// apply branch, it should conflict
|
||||
let branch_id = controller
|
||||
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
||||
.unwrap();
|
||||
let branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||
project,
|
||||
&unapplied_branch,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
||||
@ -101,7 +103,7 @@ fn conflicting() {
|
||||
let vb_state = VirtualBranchesHandle::new(project.gb_dir());
|
||||
let ctx = CommandContext::open(project).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);
|
||||
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
|
||||
controller
|
||||
.convert_to_real_branch(project, branch_id)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::convert_to_real_branch(project, branch_id).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
||||
@ -129,27 +129,22 @@ fn conflicting() {
|
||||
|
||||
#[test]
|
||||
fn delete_if_empty() {
|
||||
let Test {
|
||||
let Test { project, .. } = &Test::default();
|
||||
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
||||
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||
assert_eq!(branches.len(), 1);
|
||||
|
||||
controller
|
||||
.convert_to_real_branch(project, branches[0].id)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::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);
|
||||
}
|
||||
|
@ -8,40 +8,38 @@ use super::*;
|
||||
fn should_lock_updated_hunks() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
// by default, hunks are not locked
|
||||
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[0].path.display().to_string(), "file.txt");
|
||||
assert_eq!(branch.files[0].hunks.len(), 1);
|
||||
assert!(!branch.files[0].hunks[0].locked);
|
||||
}
|
||||
|
||||
controller
|
||||
.create_commit(project, branch_id, "test", None, false)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "test", None, false).unwrap();
|
||||
|
||||
{
|
||||
// change in the committed hunks leads to hunk locking
|
||||
repository.write_file("file.txt", &["updated content".to_string()]);
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -58,7 +56,6 @@ fn should_lock_updated_hunks() {
|
||||
fn should_reset_into_same_branch() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
@ -66,51 +63,54 @@ fn should_reset_into_same_branch() {
|
||||
let mut lines = repository.gen_file("file.txt", 7);
|
||||
commit_and_push_initial(repository);
|
||||
|
||||
let base_branch = controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
let base_branch = gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let branch_2_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch_2_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
lines[0] = "change 1".to_string();
|
||||
repository.write_file("file.txt", &lines);
|
||||
|
||||
controller
|
||||
.create_commit(project, branch_2_id, "commit to branch 2", None, false)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::create_commit(
|
||||
project,
|
||||
branch_2_id,
|
||||
"commit to branch 2",
|
||||
None,
|
||||
false,
|
||||
)
|
||||
.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);
|
||||
|
||||
// Set target to branch 1 and verify the file resets into branch 2.
|
||||
controller
|
||||
.update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch_2_id,
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
gitbutler_branch_actions::update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch_2_id,
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
gitbutler_branch_actions::reset_virtual_branch(project, branch_2_id, base_branch.base_sha)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.reset_virtual_branch(project, branch_2_id, base_branch.base_sha)
|
||||
.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);
|
||||
}
|
||||
|
||||
@ -119,13 +119,8 @@ fn commit_and_push_initial(repository: &TestProject) {
|
||||
repository.push();
|
||||
}
|
||||
|
||||
fn get_virtual_branch(
|
||||
controller: &VirtualBranchActions,
|
||||
project: &Project,
|
||||
branch_id: Id<Branch>,
|
||||
) -> VirtualBranch {
|
||||
controller
|
||||
.list_virtual_branches(project)
|
||||
fn get_virtual_branch(project: &Project, branch_id: Id<Branch>) -> VirtualBranch {
|
||||
gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
|
@ -8,31 +8,29 @@ fn integration() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_name = {
|
||||
// make a remote branch
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest::default(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
std::fs::write(repository.path().join("file.txt"), "first\n").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "first", None, false)
|
||||
.unwrap();
|
||||
controller
|
||||
.push_virtual_branch(project, branch_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "first", None, false).unwrap();
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -41,25 +39,21 @@ fn integration() {
|
||||
|
||||
let name = branch.upstream.unwrap().name;
|
||||
|
||||
controller
|
||||
.delete_virtual_branch(project, branch_id)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::delete_virtual_branch(project, branch_id).unwrap();
|
||||
|
||||
name
|
||||
};
|
||||
|
||||
// checkout a existing remote branch
|
||||
let branch_id = controller
|
||||
.create_virtual_branch_from_branch(project, &branch_name, None)
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch_from_branch(project, &branch_name, None)
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
// add a commit
|
||||
std::fs::write(repository.path().join("file.txt"), "first\nsecond").unwrap();
|
||||
|
||||
controller
|
||||
.create_commit(project, branch_id, "second", None, false)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "second", None, false).unwrap();
|
||||
}
|
||||
|
||||
{
|
||||
@ -73,12 +67,9 @@ fn integration() {
|
||||
|
||||
{
|
||||
// merge branch into master
|
||||
controller
|
||||
.push_virtual_branch(project, branch_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -95,10 +86,9 @@ fn integration() {
|
||||
|
||||
{
|
||||
// should mark commits as integrated
|
||||
controller.fetch_from_remotes(project, None).unwrap();
|
||||
gitbutler_branch_actions::fetch_from_remotes(project, None).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -117,7 +107,6 @@ fn no_conflicts() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -131,22 +120,23 @@ fn no_conflicts() {
|
||||
repository.checkout(&"refs/heads/master".parse().unwrap());
|
||||
}
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
||||
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||
assert!(branches.is_empty());
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||
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[0].id, branch_id);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
@ -158,7 +148,6 @@ fn conflicts_with_uncommited() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -172,29 +161,29 @@ fn conflicts_with_uncommited() {
|
||||
repository.checkout(&"refs/heads/master".parse().unwrap());
|
||||
}
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// create a local branch that conflicts with remote
|
||||
{
|
||||
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);
|
||||
};
|
||||
|
||||
// branch should be created unapplied, because of the conflict
|
||||
|
||||
let new_branch_id = controller
|
||||
.create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let new_branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let new_branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let new_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -210,7 +199,6 @@ fn conflicts_with_commited() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -224,33 +212,32 @@ fn conflicts_with_commited() {
|
||||
repository.checkout(&"refs/heads/master".parse().unwrap());
|
||||
}
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// create a local branch that conflicts with remote
|
||||
{
|
||||
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);
|
||||
|
||||
controller
|
||||
.create_commit(project, branches[0].id, "hej", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branches[0].id, "hej", None, false)
|
||||
.unwrap();
|
||||
};
|
||||
|
||||
// branch should be created unapplied, because of the conflict
|
||||
|
||||
let new_branch_id = controller
|
||||
.create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let new_branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let new_branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let new_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -263,54 +250,48 @@ fn conflicts_with_commited() {
|
||||
|
||||
#[test]
|
||||
fn from_default_target() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
let Test { project, .. } = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// branch should be created unapplied, because of the conflict
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
None
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
None
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"cannot create a branch from default target"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_non_existent_branch() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
let Test { project, .. } = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// branch should be created unapplied, because of the conflict
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||
None
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||
None
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"branch refs/remotes/origin/branch was not found"
|
||||
);
|
||||
}
|
||||
@ -320,7 +301,6 @@ fn from_state_remote_branch() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -339,19 +319,20 @@ fn from_state_remote_branch() {
|
||||
repository.push();
|
||||
}
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||
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[0].id, branch_id);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
|
@ -6,25 +6,24 @@ use super::*;
|
||||
fn should_unapply_diff() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// write some
|
||||
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
|
||||
.delete_virtual_branch(project, branches[0].id)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::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!(!repository.path().join("file.txt").exists());
|
||||
|
||||
@ -40,28 +39,28 @@ fn should_unapply_diff() {
|
||||
fn should_remove_reference() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.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);
|
||||
|
||||
let refnames = repository
|
||||
|
@ -7,33 +7,33 @@ fn twice() {
|
||||
|
||||
let test_project = TestProject::default();
|
||||
|
||||
let controller = VirtualBranchActions {};
|
||||
|
||||
{
|
||||
let project = projects
|
||||
.add(test_project.path())
|
||||
.expect("failed to add project");
|
||||
controller
|
||||
.set_base_branch(&project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
assert!(controller
|
||||
.list_virtual_branches(&project)
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
&project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(gitbutler_branch_actions::list_virtual_branches(&project)
|
||||
.unwrap()
|
||||
.0
|
||||
.is_empty());
|
||||
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();
|
||||
controller
|
||||
.set_base_branch(&project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
&project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// even though project is on gitbutler/workspace, we should not import it
|
||||
assert!(controller
|
||||
.list_virtual_branches(&project)
|
||||
assert!(gitbutler_branch_actions::list_virtual_branches(&project)
|
||||
.unwrap()
|
||||
.0
|
||||
.is_empty());
|
||||
@ -47,7 +47,6 @@ fn dirty_non_target() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -55,11 +54,13 @@ fn dirty_non_target() {
|
||||
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().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[0].files.len(), 1);
|
||||
assert_eq!(branches[0].files[0].hunks.len(), 1);
|
||||
@ -74,17 +75,18 @@ fn dirty_target() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().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[0].files.len(), 1);
|
||||
assert_eq!(branches[0].files[0].hunks.len(), 1);
|
||||
@ -97,7 +99,6 @@ fn commit_on_non_target_local() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -105,11 +106,13 @@ fn commit_on_non_target_local() {
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
repository.commit_all("commit on target");
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().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!(branches[0].files.is_empty());
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
@ -122,7 +125,6 @@ fn commit_on_non_target_remote() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -131,11 +133,13 @@ fn commit_on_non_target_remote() {
|
||||
repository.commit_all("commit on target");
|
||||
repository.push_branch(&"refs/heads/some-feature".parse().unwrap());
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().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!(branches[0].files.is_empty());
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
@ -148,18 +152,19 @@ fn commit_on_target() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
repository.commit_all("commit on target");
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().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!(branches[0].files.is_empty());
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
@ -172,7 +177,6 @@ fn submodule() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -181,11 +185,13 @@ fn submodule() {
|
||||
test_project.path().display().to_string().parse().unwrap();
|
||||
repository.add_submodule(&submodule_url, path::Path::new("submodule"));
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().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[0].files.len(), 1);
|
||||
assert_eq!(branches[0].files[0].hunks.len(), 1);
|
||||
|
@ -7,43 +7,41 @@ fn insert_blank_commit_down() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let _commit1_id = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let _commit1_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||
let commit2_id = controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
let commit2_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
||||
let _commit3_id = controller
|
||||
.create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap();
|
||||
let _commit3_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.insert_blank_commit(project, branch_id, commit2_id, 1)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::insert_blank_commit(project, branch_id, commit2_id, 1).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -72,43 +70,41 @@ fn insert_blank_commit_up() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let _commit1_id = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let _commit1_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||
let commit2_id = controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
let commit2_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
||||
let _commit3_id = controller
|
||||
.create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap();
|
||||
let _commit3_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.insert_blank_commit(project, branch_id, commit2_id, -1)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::insert_blank_commit(project, branch_id, commit2_id, -1).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::{fs, path, path::PathBuf, str::FromStr};
|
||||
|
||||
use gitbutler_branch::{BranchCreateRequest, VirtualBranchesHandle};
|
||||
use gitbutler_branch_actions::update_workspace_commit;
|
||||
use gitbutler_branch_actions::GITBUTLER_WORKSPACE_COMMIT_TITLE;
|
||||
use gitbutler_branch_actions::{update_workspace_commit, VirtualBranchActions};
|
||||
use gitbutler_command_context::CommandContext;
|
||||
use gitbutler_error::error::Marker;
|
||||
use gitbutler_project::{self as projects, Project, ProjectId};
|
||||
@ -15,7 +15,6 @@ struct Test {
|
||||
project_id: ProjectId,
|
||||
project: Project,
|
||||
projects: projects::Controller,
|
||||
controller: VirtualBranchActions,
|
||||
data_dir: Option<TempDir>,
|
||||
}
|
||||
|
||||
@ -40,7 +39,6 @@ impl Default for Test {
|
||||
Self {
|
||||
repository: test_project,
|
||||
project_id: project.id,
|
||||
controller: VirtualBranchActions {},
|
||||
projects,
|
||||
project,
|
||||
data_dir: Some(data_dir),
|
||||
@ -89,7 +87,6 @@ fn resolve_conflict_flow() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -105,18 +102,22 @@ fn resolve_conflict_flow() {
|
||||
repository.reset_hard(Some(first_commit_oid));
|
||||
}
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
// make a branch that conflicts with the remote branch, but doesn't know about it yet
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest::default(),
|
||||
)
|
||||
.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[0].id, branch1_id);
|
||||
assert!(branches[0].active);
|
||||
@ -124,11 +125,11 @@ fn resolve_conflict_flow() {
|
||||
|
||||
let unapplied_branch = {
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
|
||||
Refname::from_str(&unapplied_branches[0]).unwrap()
|
||||
@ -136,14 +137,17 @@ fn resolve_conflict_flow() {
|
||||
|
||||
let branch1_id = {
|
||||
// when we apply conflicted branch, it has conflict
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
||||
.unwrap();
|
||||
let branch1_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||
project,
|
||||
&unapplied_branch,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let vb_state = VirtualBranchesHandle::new(project.gb_dir());
|
||||
let ctx = CommandContext::open(project).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!(branches[0].active);
|
||||
assert!(branches[0].conflicted);
|
||||
@ -161,10 +165,15 @@ fn resolve_conflict_flow() {
|
||||
{
|
||||
// can't commit conflicts
|
||||
assert!(matches!(
|
||||
controller
|
||||
.create_commit(project, branch1_id, "commit conflicts", None, false)
|
||||
.unwrap_err()
|
||||
.downcast_ref(),
|
||||
gitbutler_branch_actions::create_commit(
|
||||
project,
|
||||
branch1_id,
|
||||
"commit conflicts",
|
||||
None,
|
||||
false
|
||||
)
|
||||
.unwrap_err()
|
||||
.downcast_ref(),
|
||||
Some(Marker::ProjectConflict)
|
||||
));
|
||||
}
|
||||
@ -172,15 +181,15 @@ fn resolve_conflict_flow() {
|
||||
{
|
||||
// fixing the conflict removes conflicted mark
|
||||
fs::write(repository.path().join("file.txt"), "resolved").unwrap();
|
||||
controller.list_virtual_branches(project).unwrap();
|
||||
let commit_oid = controller
|
||||
.create_commit(project, branch1_id, "resolution", None, false)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||
let commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "resolution", None, false)
|
||||
.unwrap();
|
||||
|
||||
let commit = repository.find_commit(commit_oid).unwrap();
|
||||
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[0].id, branch1_id);
|
||||
assert!(branches[0].active);
|
||||
|
@ -8,41 +8,42 @@ fn move_file_down() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let commit1_id = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let commit1_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let commit1 = repository.find_commit(commit1_id).unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||
let commit2_id = controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
let commit2_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
let commit2 = repository.find_commit(commit2_id).unwrap();
|
||||
|
||||
// amend another hunk
|
||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||
controller
|
||||
.move_commit_file(project, branch_id, commit2_id, commit1_id, &to_amend)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::move_commit_file(
|
||||
project, branch_id, commit2_id, commit1_id, &to_amend,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -66,39 +67,40 @@ fn move_file_up() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||
let commit1_id = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let commit1_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||
let commit2_id = controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
let commit2_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
|
||||
// amend another hunk
|
||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||
controller
|
||||
.move_commit_file(project, branch_id, commit1_id, commit2_id, &to_amend)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::move_commit_file(
|
||||
project, branch_id, commit1_id, commit2_id, &to_amend,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -119,32 +121,28 @@ fn move_file_up_overlapping_hunks() {
|
||||
let Test {
|
||||
repository,
|
||||
project_id,
|
||||
controller,
|
||||
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
gitbutler_branch_actions::set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
let branch_id = gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
|
||||
.unwrap();
|
||||
|
||||
// create bottom commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
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)
|
||||
|
||||
.unwrap();
|
||||
|
||||
// create middle commit one
|
||||
fs::write(repository.path().join("file2.txt"), "content2\ncontent2a\n").unwrap();
|
||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||
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)
|
||||
|
||||
.unwrap();
|
||||
|
||||
@ -155,27 +153,23 @@ fn move_file_up_overlapping_hunks() {
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
||||
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)
|
||||
|
||||
.unwrap();
|
||||
|
||||
// create top commit
|
||||
fs::write(repository.path().join("file5.txt"), "content5").unwrap();
|
||||
let _commit4_id = controller
|
||||
.create_commit(project, branch_id, "commit four", None, false)
|
||||
let _commit4_id = gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
|
||||
|
||||
.unwrap();
|
||||
|
||||
// move one line from middle commit two up to middle commit one
|
||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-6".parse().unwrap();
|
||||
controller
|
||||
.move_commit_file(project, branch_id, commit2_id, commit3_id, &to_amend)
|
||||
gitbutler_branch_actions::move_commit_file(project, branch_id, commit2_id, commit3_id, &to_amend)
|
||||
|
||||
.unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
|
||||
.unwrap()
|
||||
.0
|
||||
|
@ -7,43 +7,40 @@ fn no_diffs() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.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);
|
||||
|
||||
let source_branch_id = branches[0].id;
|
||||
|
||||
let commit_oid = controller
|
||||
.create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
let commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
|
||||
let target_branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let target_branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.move_commit(project, target_branch_id, commit_oid)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid).unwrap();
|
||||
|
||||
let destination_branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let destination_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
.find(|b| b.id == target_branch_id)
|
||||
.unwrap();
|
||||
|
||||
let source_branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let source_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -61,24 +58,25 @@ fn diffs_on_source_branch() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.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);
|
||||
|
||||
let source_branch_id = branches[0].id;
|
||||
|
||||
let commit_oid = controller
|
||||
.create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
let commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
|
||||
std::fs::write(
|
||||
repository.path().join("another file.txt"),
|
||||
@ -86,24 +84,20 @@ fn diffs_on_source_branch() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let target_branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let target_branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.move_commit(project, target_branch_id, commit_oid)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid).unwrap();
|
||||
|
||||
let destination_branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let destination_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
.find(|b| b.id == target_branch_id)
|
||||
.unwrap();
|
||||
|
||||
let source_branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let source_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -121,34 +115,34 @@ fn diffs_on_target_branch() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.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);
|
||||
|
||||
let source_branch_id = branches[0].id;
|
||||
|
||||
let commit_oid = controller
|
||||
.create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
let commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
|
||||
let target_branch_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let target_branch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
std::fs::write(
|
||||
repository.path().join("another file.txt"),
|
||||
@ -156,20 +150,16 @@ fn diffs_on_target_branch() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.move_commit(project, target_branch_id, commit_oid)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid).unwrap();
|
||||
|
||||
let destination_branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let destination_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
.find(|b| b.id == target_branch_id)
|
||||
.unwrap();
|
||||
|
||||
let source_branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let source_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -187,34 +177,34 @@ fn locked_hunks_on_source_branch() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.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);
|
||||
|
||||
let source_branch_id = branches[0].id;
|
||||
|
||||
let commit_oid = controller
|
||||
.create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
let commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
|
||||
std::fs::write(repository.path().join("file.txt"), "locked content").unwrap();
|
||||
|
||||
let target_branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let target_branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.move_commit(project, target_branch_id, commit_oid)
|
||||
gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"the source branch contains hunks locked to the target commit"
|
||||
@ -226,39 +216,38 @@ fn no_commit() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.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);
|
||||
|
||||
let source_branch_id = branches[0].id;
|
||||
|
||||
controller
|
||||
.create_commit(project, source_branch_id, "commit", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
|
||||
let target_branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let target_branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let commit_id_hex = "a99c95cca7a60f1a2180c2f86fb18af97333c192";
|
||||
assert_eq!(
|
||||
controller
|
||||
.move_commit(
|
||||
project,
|
||||
target_branch_id,
|
||||
git2::Oid::from_str(commit_id_hex).unwrap()
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
gitbutler_branch_actions::move_commit(
|
||||
project,
|
||||
target_branch_id,
|
||||
git2::Oid::from_str(commit_id_hex).unwrap()
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
format!("commit {commit_id_hex} to be moved could not be found")
|
||||
);
|
||||
}
|
||||
@ -268,29 +257,29 @@ fn no_branch() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.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);
|
||||
|
||||
let source_branch_id = branches[0].id;
|
||||
|
||||
let commit_oid = controller
|
||||
.create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
let commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||
.unwrap();
|
||||
|
||||
let id = BranchId::generate();
|
||||
assert_eq!(
|
||||
controller
|
||||
.move_commit(project, id, commit_oid)
|
||||
gitbutler_branch_actions::move_commit(project, id, commit_oid)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
format!("branch {id} is not among applied branches")
|
||||
|
@ -11,14 +11,16 @@ fn workdir_vbranch_restore() -> anyhow::Result<()> {
|
||||
let test = Test::default();
|
||||
let Test {
|
||||
repository,
|
||||
controller,
|
||||
|
||||
project,
|
||||
..
|
||||
} = &test;
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let worktree_dir = repository.path();
|
||||
for round in 0..3 {
|
||||
@ -27,14 +29,14 @@ fn workdir_vbranch_restore() -> anyhow::Result<()> {
|
||||
worktree_dir.join(format!("file{round}.txt")),
|
||||
make_lines(line_count),
|
||||
)?;
|
||||
let branch_id = controller.create_virtual_branch(
|
||||
let branch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some(round.to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
controller.create_commit(
|
||||
gitbutler_branch_actions::create_commit(
|
||||
project,
|
||||
branch_id,
|
||||
&format!("commit {round}"),
|
||||
@ -51,7 +53,7 @@ fn workdir_vbranch_restore() -> anyhow::Result<()> {
|
||||
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)?;
|
||||
assert_eq!(
|
||||
@ -96,18 +98,20 @@ fn make_lines(count: usize) -> Vec<u8> {
|
||||
fn basic_oplog() -> anyhow::Result<()> {
|
||||
let Test {
|
||||
repository,
|
||||
controller,
|
||||
|
||||
project,
|
||||
..
|
||||
} = &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
|
||||
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
|
||||
let file_path = repository.path().join("large.txt");
|
||||
@ -121,7 +125,8 @@ fn basic_oplog() -> anyhow::Result<()> {
|
||||
// create commit with large file
|
||||
fs::write(repository.path().join("file2.txt"), "content2")?;
|
||||
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
|
||||
let conflicts_path = repository.path().join(".git").join("conflicts");
|
||||
@ -131,22 +136,22 @@ fn basic_oplog() -> anyhow::Result<()> {
|
||||
|
||||
// create state with conflict state
|
||||
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(&conflicts_path)?;
|
||||
|
||||
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
|
||||
.list_virtual_branches(project)?
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)?
|
||||
.0
|
||||
.into_iter()
|
||||
.find(|b| b.id == branch_id)
|
||||
.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!(branch.commits.len(), 3);
|
||||
@ -185,7 +190,7 @@ fn basic_oplog() -> anyhow::Result<()> {
|
||||
project.restore_snapshot(snapshots[2].clone().commit_id)?;
|
||||
|
||||
// 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 that the conflicts file was removed
|
||||
@ -233,12 +238,12 @@ fn basic_oplog() -> anyhow::Result<()> {
|
||||
fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
||||
let Test {
|
||||
repository,
|
||||
controller,
|
||||
|
||||
project,
|
||||
..
|
||||
} = &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!(
|
||||
VirtualBranchesHandle::new(project.gb_dir())
|
||||
@ -246,7 +251,8 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
||||
.len(),
|
||||
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!(
|
||||
VirtualBranchesHandle::new(project.gb_dir())
|
||||
.list_branches_in_workspace()?
|
||||
@ -256,7 +262,8 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
||||
|
||||
// create commit
|
||||
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)?;
|
||||
|
||||
@ -269,7 +276,8 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
||||
|
||||
// create second commit
|
||||
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
|
||||
let head = repo.head().expect("never unborn");
|
||||
@ -347,17 +355,21 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
||||
fn head_corrupt_is_recreated_automatically() {
|
||||
let Test {
|
||||
repository,
|
||||
controller,
|
||||
|
||||
project,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let snapshots = project.list_snapshots(10, None).unwrap();
|
||||
assert_eq!(
|
||||
@ -374,9 +386,11 @@ fn head_corrupt_is_recreated_automatically() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.expect("the snapshot doesn't fail despite the corrupt head");
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.expect("the snapshot doesn't fail despite the corrupt head");
|
||||
|
||||
let snapshots = project.list_snapshots(10, None).unwrap();
|
||||
assert_eq!(
|
||||
|
@ -9,20 +9,24 @@ mod create_virtual_branch {
|
||||
fn simple() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest::default(),
|
||||
)
|
||||
.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[0].id, branch_id);
|
||||
assert_eq!(branches[0].name, "Virtual branch");
|
||||
@ -39,36 +43,36 @@ mod create_virtual_branch {
|
||||
fn duplicate_name() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch2_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch2_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
||||
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||
assert_eq!(branches.len(), 2);
|
||||
assert_eq!(branches[0].id, branch1_id);
|
||||
assert_eq!(branches[0].name, "name");
|
||||
@ -94,37 +98,37 @@ mod update_virtual_branch {
|
||||
fn simple() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch_id,
|
||||
name: Some("new name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch_id,
|
||||
name: Some("new name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
||||
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||
assert_eq!(branches.len(), 1);
|
||||
assert_eq!(branches[0].id, branch_id);
|
||||
assert_eq!(branches[0].name, "new name");
|
||||
@ -142,46 +146,45 @@ mod update_virtual_branch {
|
||||
fn duplicate_name() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch2_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch2_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch2_id,
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch2_id,
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].name, "name");
|
||||
@ -207,35 +210,32 @@ mod push_virtual_branch {
|
||||
fn simple() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
|
||||
controller
|
||||
.create_commit(project, branch1_id, "test", None, false)
|
||||
.unwrap();
|
||||
controller
|
||||
.push_virtual_branch(project, branch1_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "test", None, false).unwrap();
|
||||
gitbutler_branch_actions::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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].name, "name");
|
||||
@ -256,70 +256,65 @@ mod push_virtual_branch {
|
||||
fn duplicate_names() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = {
|
||||
// create and push branch with some work
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch1_id, "test", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "test", None, false)
|
||||
.unwrap();
|
||||
controller
|
||||
.push_virtual_branch(project, branch1_id, false, None)
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None)
|
||||
.unwrap();
|
||||
branch1_id
|
||||
};
|
||||
|
||||
// rename first branch
|
||||
controller
|
||||
.update_virtual_branch(
|
||||
gitbutler_branch_actions::update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch1_id,
|
||||
name: Some("updated name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch2_id = {
|
||||
// create another branch with first branch's old name and push it
|
||||
let branch2_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch1_id,
|
||||
name: Some("updated name".to_string()),
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch2_id = {
|
||||
// create another branch with first branch's old name and push it
|
||||
let branch2_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
name: Some("name".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(repository.path().join("file.txt"), "updated content").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch2_id, "test", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch2_id, "test", None, false)
|
||||
.unwrap();
|
||||
controller
|
||||
.push_virtual_branch(project, branch2_id, false, None)
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch2_id, false, None)
|
||||
.unwrap();
|
||||
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);
|
||||
// first branch is pushing to old ref remotely
|
||||
assert_eq!(branches[0].id, branch1_id);
|
||||
|
@ -7,37 +7,35 @@ fn reorder_commit_down() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let _commit1_id = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let _commit1_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||
let commit2_id = controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
let commit2_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.reorder_commit(project, branch_id, commit2_id, 1)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::reorder_commit(project, branch_id, commit2_id, 1).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -62,37 +60,35 @@ fn reorder_commit_up() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let commit1_id = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let commit1_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||
let _commit2_id = controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
let _commit2_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.reorder_commit(project, branch_id, commit1_id, -1)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::reorder_commit(project, branch_id, commit1_id, -1).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
|
@ -9,27 +9,28 @@ fn to_head() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch1_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let oid = {
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
|
||||
// commit changes
|
||||
let oid = controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap();
|
||||
let oid =
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", 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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
@ -45,11 +46,9 @@ fn to_head() {
|
||||
|
||||
{
|
||||
// reset changes to head
|
||||
controller
|
||||
.reset_virtual_branch(project, branch1_id, oid)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
@ -67,27 +66,28 @@ fn to_target() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
let base_branch = controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
let base_branch = gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch1_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
|
||||
// commit changes
|
||||
let oid = controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap();
|
||||
let oid =
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", 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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
@ -101,11 +101,10 @@ fn to_target() {
|
||||
|
||||
{
|
||||
// reset changes to head
|
||||
controller
|
||||
.reset_virtual_branch(project, branch1_id, base_branch.base_sha)
|
||||
gitbutler_branch_actions::reset_virtual_branch(project, branch1_id, base_branch.base_sha)
|
||||
.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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 0);
|
||||
@ -122,28 +121,29 @@ fn to_commit() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch1_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let first_commit_oid = {
|
||||
// commit some changes
|
||||
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
|
||||
let oid = controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap();
|
||||
let oid =
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", 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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
@ -161,11 +161,11 @@ fn to_commit() {
|
||||
// commit some more
|
||||
fs::write(repository.path().join("file.txt"), "more content").unwrap();
|
||||
|
||||
let second_commit_oid = controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap();
|
||||
let second_commit_oid =
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", 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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 2);
|
||||
@ -180,11 +180,10 @@ fn to_commit() {
|
||||
|
||||
{
|
||||
// reset changes to the first commit
|
||||
controller
|
||||
.reset_virtual_branch(project, branch1_id, first_commit_oid)
|
||||
gitbutler_branch_actions::reset_virtual_branch(project, branch1_id, first_commit_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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
@ -202,27 +201,28 @@ fn to_non_existing() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch1_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
|
||||
// commit changes
|
||||
let oid = controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap();
|
||||
let oid =
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", 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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 1);
|
||||
@ -237,14 +237,13 @@ fn to_non_existing() {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.reset_virtual_branch(
|
||||
project,
|
||||
branch1_id,
|
||||
"fe14df8c66b73c6276f7bb26102ad91da680afcb".parse().unwrap()
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
gitbutler_branch_actions::reset_virtual_branch(
|
||||
project,
|
||||
branch1_id,
|
||||
"fe14df8c66b73c6276f7bb26102ad91da680afcb".parse().unwrap()
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"commit fe14df8c66b73c6276f7bb26102ad91da680afcb not in the branch"
|
||||
);
|
||||
}
|
||||
|
@ -7,27 +7,28 @@ fn unapplying_selected_branch_selects_anther() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
std::fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
|
||||
// first branch should be created as default
|
||||
let b_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let b_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// if default branch exists, new branch should not be created as default
|
||||
let b2_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let b2_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.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();
|
||||
|
||||
@ -36,9 +37,9 @@ fn unapplying_selected_branch_selects_anther() {
|
||||
assert!(b.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[0].id, b2.id);
|
||||
@ -48,27 +49,25 @@ fn unapplying_selected_branch_selects_anther() {
|
||||
|
||||
#[test]
|
||||
fn deleting_selected_branch_selects_anther() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
let Test { project, .. } = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// first branch should be created as default
|
||||
let b_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let b_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// if default branch exists, new branch should not be created as default
|
||||
let b2_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let b2_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.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();
|
||||
|
||||
@ -77,9 +76,9 @@ fn deleting_selected_branch_selects_anther() {
|
||||
assert!(b.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[0].id, b2.id);
|
||||
@ -88,22 +87,19 @@ fn deleting_selected_branch_selects_anther() {
|
||||
|
||||
#[test]
|
||||
fn create_virtual_branch_should_set_selected_for_changes() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
let Test { project, .. } = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// first branch should be created as default
|
||||
let b_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let b_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -112,11 +108,10 @@ fn create_virtual_branch_should_set_selected_for_changes() {
|
||||
assert!(branch.selected_for_changes);
|
||||
|
||||
// if default branch exists, new branch should not be created as default
|
||||
let b_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let b_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -125,17 +120,15 @@ fn create_virtual_branch_should_set_selected_for_changes() {
|
||||
assert!(!branch.selected_for_changes);
|
||||
|
||||
// explicitly don't make this one default
|
||||
let b_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let b_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -144,17 +137,15 @@ fn create_virtual_branch_should_set_selected_for_changes() {
|
||||
assert!(!branch.selected_for_changes);
|
||||
|
||||
// explicitly make this one default
|
||||
let b_id = controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let b_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -165,21 +156,18 @@ fn create_virtual_branch_should_set_selected_for_changes() {
|
||||
|
||||
#[test]
|
||||
fn update_virtual_branch_should_reset_selected_for_changes() {
|
||||
let Test {
|
||||
let Test { project, .. } = &Test::default();
|
||||
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
|
||||
let b1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let b1 = controller
|
||||
.list_virtual_branches(project)
|
||||
let b1_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let b1 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -187,11 +175,10 @@ fn update_virtual_branch_should_reset_selected_for_changes() {
|
||||
.unwrap();
|
||||
assert!(b1.selected_for_changes);
|
||||
|
||||
let b2_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let b2 = controller
|
||||
.list_virtual_branches(project)
|
||||
let b2_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let b2 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -199,19 +186,17 @@ fn update_virtual_branch_should_reset_selected_for_changes() {
|
||||
.unwrap();
|
||||
assert!(!b2.selected_for_changes);
|
||||
|
||||
controller
|
||||
.update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: b2_id,
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: b2_id,
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let b1 = controller
|
||||
.list_virtual_branches(project)
|
||||
let b1 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -219,8 +204,7 @@ fn update_virtual_branch_should_reset_selected_for_changes() {
|
||||
.unwrap();
|
||||
assert!(!b1.selected_for_changes);
|
||||
|
||||
let b2 = controller
|
||||
.list_virtual_branches(project)
|
||||
let b2 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -234,21 +218,21 @@ fn unapply_virtual_branch_should_reset_selected_for_changes() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let b1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let b1_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
|
||||
let b1 = controller
|
||||
.list_virtual_branches(project)
|
||||
let b1 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -256,12 +240,11 @@ fn unapply_virtual_branch_should_reset_selected_for_changes() {
|
||||
.unwrap();
|
||||
assert!(b1.selected_for_changes);
|
||||
|
||||
let b2_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let b2_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let b2 = controller
|
||||
.list_virtual_branches(project)
|
||||
let b2 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -269,10 +252,9 @@ fn unapply_virtual_branch_should_reset_selected_for_changes() {
|
||||
.unwrap();
|
||||
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
|
||||
.list_virtual_branches(project)
|
||||
assert!(gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -284,30 +266,30 @@ fn hunks_distribution() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.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);
|
||||
|
||||
controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.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[1].files.len(), 1);
|
||||
}
|
||||
@ -317,28 +299,27 @@ fn applying_first_branch() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.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);
|
||||
|
||||
let unapplied_branch = controller
|
||||
.convert_to_real_branch(project, branches[0].id)
|
||||
.unwrap();
|
||||
let unapplied_branch =
|
||||
gitbutler_branch_actions::convert_to_real_branch(project, branches[0].id).unwrap();
|
||||
let unapplied_branch = Refname::from_str(&unapplied_branch).unwrap();
|
||||
controller
|
||||
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
||||
gitbutler_branch_actions::create_virtual_branch_from_branch(project, &unapplied_branch, 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!(branches[0].active);
|
||||
assert!(branches[0].selected_for_changes);
|
||||
@ -351,7 +332,6 @@ fn new_locked_hunk_without_modifying_existing() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -359,44 +339,44 @@ fn new_locked_hunk_without_modifying_existing() {
|
||||
repository.commit_all("first commit");
|
||||
repository.push();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
lines[0] = "modification 1".to_string();
|
||||
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);
|
||||
|
||||
controller
|
||||
.create_commit(project, branches[0].id, "second commit", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branches[0].id, "second commit", None, false)
|
||||
.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].commits.len(), 1);
|
||||
|
||||
controller
|
||||
.create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest {
|
||||
selected_for_changes: Some(true),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
lines[8] = "modification 2".to_string();
|
||||
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[1].files.len(), 1);
|
||||
|
||||
lines[0] = "modification 3".to_string();
|
||||
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[1].files.len(), 1);
|
||||
}
|
||||
|
@ -2,15 +2,13 @@ use super::*;
|
||||
|
||||
#[test]
|
||||
fn success() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
let Test { project, .. } = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
mod error {
|
||||
@ -20,20 +18,15 @@ mod error {
|
||||
|
||||
#[test]
|
||||
fn missing() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
let Test { project, .. } = &Test::default();
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.set_base_branch(
|
||||
project,
|
||||
&RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(),
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(),
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"remote branch 'refs/remotes/origin/missing' not found"
|
||||
);
|
||||
}
|
||||
@ -50,7 +43,6 @@ mod go_back_to_workspace {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -60,29 +52,33 @@ mod go_back_to_workspace {
|
||||
repository.commit_all("two");
|
||||
repository.push();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let vbranch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let vbranch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||
project,
|
||||
&BranchCreateRequest::default(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
std::fs::write(repository.path().join("another file.txt"), "content").unwrap();
|
||||
controller
|
||||
.create_commit(project, vbranch_id, "one", None, false)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::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);
|
||||
|
||||
repository.checkout_commit(oid_one);
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().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[0].id, vbranch_id);
|
||||
assert!(branches[0].active);
|
||||
@ -93,7 +89,6 @@ mod go_back_to_workspace {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -103,21 +98,25 @@ mod go_back_to_workspace {
|
||||
repository.commit_all("two");
|
||||
repository.push();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
||||
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||
assert!(branches.is_empty());
|
||||
|
||||
repository.checkout_commit(oid_one);
|
||||
std::fs::write(repository.path().join("file.txt"), "tree").unwrap();
|
||||
|
||||
assert!(matches!(
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap_err()
|
||||
.downcast_ref(),
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap()
|
||||
)
|
||||
.unwrap_err()
|
||||
.downcast_ref(),
|
||||
Some(Marker::ProjectConflict)
|
||||
));
|
||||
}
|
||||
@ -127,7 +126,6 @@ mod go_back_to_workspace {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -137,21 +135,25 @@ mod go_back_to_workspace {
|
||||
repository.commit_all("two");
|
||||
repository.push();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
||||
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||
assert!(branches.is_empty());
|
||||
|
||||
repository.checkout_commit(oid_one);
|
||||
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
|
||||
|
||||
assert!(matches!(
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap_err()
|
||||
.downcast_ref(),
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap()
|
||||
)
|
||||
.unwrap_err()
|
||||
.downcast_ref(),
|
||||
Some(Marker::ProjectConflict)
|
||||
));
|
||||
}
|
||||
@ -161,7 +163,6 @@ mod go_back_to_workspace {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -171,22 +172,26 @@ mod go_back_to_workspace {
|
||||
repository.commit_all("two");
|
||||
repository.push();
|
||||
|
||||
let base = controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
let base = gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
||||
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||
assert!(branches.is_empty());
|
||||
|
||||
repository.checkout_commit(oid_one);
|
||||
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
|
||||
repository.commit_all("three");
|
||||
|
||||
let base_two = controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
let base_two = gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().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!(base_two, base);
|
||||
}
|
||||
@ -196,7 +201,6 @@ mod go_back_to_workspace {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
@ -206,20 +210,24 @@ mod go_back_to_workspace {
|
||||
repository.commit_all("two");
|
||||
repository.push();
|
||||
|
||||
let base = controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
let base = gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
||||
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||
assert!(branches.is_empty());
|
||||
|
||||
repository.checkout_commit(oid_one);
|
||||
|
||||
let base_two = controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
let base_two = gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().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!(base_two, base);
|
||||
}
|
||||
|
@ -7,52 +7,46 @@ fn head() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit three", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let commit_four_oid = {
|
||||
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit four", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
controller
|
||||
.squash(project, branch_id, commit_four_oid)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::squash(project, branch_id, commit_four_oid).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -75,52 +69,46 @@ fn middle() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let commit_two_oid = {
|
||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit three", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit four", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
controller
|
||||
.squash(project, branch_id, commit_two_oid)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::squash(project, branch_id, commit_two_oid).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -144,7 +132,6 @@ fn forcepush_allowed() {
|
||||
repository,
|
||||
project_id,
|
||||
project,
|
||||
controller,
|
||||
projects,
|
||||
..
|
||||
} = &Test::default();
|
||||
@ -156,52 +143,45 @@ fn forcepush_allowed() {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
controller
|
||||
.push_virtual_branch(project, branch_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||
|
||||
let commit_two_oid = {
|
||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit three", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit four", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
controller
|
||||
.squash(project, branch_id, commit_two_oid)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::squash(project, branch_id, commit_two_oid).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -225,64 +205,57 @@ fn forcepush_forbidden() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch_id,
|
||||
allow_rebasing: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch_id,
|
||||
allow_rebasing: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
controller
|
||||
.push_virtual_branch(project, branch_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||
|
||||
let commit_two_oid = {
|
||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit three", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit four", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.squash(project, branch_id, commit_two_oid)
|
||||
gitbutler_branch_actions::squash(project, branch_id, commit_two_oid)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"force push not allowed"
|
||||
@ -294,28 +267,27 @@ fn root_forbidden() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let commit_one_oid = {
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.squash(project, branch_id, commit_one_oid)
|
||||
gitbutler_branch_actions::squash(project, branch_id, commit_one_oid)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"can not squash root commit"
|
||||
|
@ -8,27 +8,26 @@ use super::Test;
|
||||
fn should_unapply_with_commits() {
|
||||
let Test {
|
||||
project,
|
||||
controller,
|
||||
repository,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
fs::write(
|
||||
repository.path().join("file.txt"),
|
||||
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n",
|
||||
)
|
||||
.unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "test", None, false)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "test", None, false).unwrap();
|
||||
|
||||
// change in the committed hunks leads to hunk locking
|
||||
fs::write(
|
||||
@ -37,17 +36,15 @@ fn should_unapply_with_commits() {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.unapply_ownership(
|
||||
project,
|
||||
&"file.txt:1-5,7-11"
|
||||
.parse::<BranchOwnershipClaims>()
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap_or_else(|err| panic!("{err:?}"));
|
||||
gitbutler_branch_actions::unapply_ownership(
|
||||
project,
|
||||
&"file.txt:1-5,7-11"
|
||||
.parse::<BranchOwnershipClaims>()
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap_or_else(|err| panic!("{err:?}"));
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
|
@ -7,43 +7,41 @@ fn undo_commit_simple() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
let _commit1_id = controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
let _commit1_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||
let commit2_id = controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
let commit2_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap();
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
||||
let _commit3_id = controller
|
||||
.create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap();
|
||||
let _commit3_id =
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.undo_commit(project, branch_id, commit2_id)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::undo_commit(project, branch_id, commit2_id).unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -8,47 +8,48 @@ fn head() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let commit_three_oid = {
|
||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit three", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
let commit_three = repository.find_commit(commit_three_oid).unwrap();
|
||||
let before_change_id = &commit_three.change_id();
|
||||
|
||||
controller
|
||||
.update_commit_message(project, branch_id, commit_three_oid, "commit three updated")
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::update_commit_message(
|
||||
project,
|
||||
branch_id,
|
||||
commit_three_oid,
|
||||
"commit three updated",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -79,45 +80,46 @@ fn middle() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let commit_two_oid = {
|
||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit three", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
controller
|
||||
.update_commit_message(project, branch_id, commit_two_oid, "commit two updated")
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::update_commit_message(
|
||||
project,
|
||||
branch_id,
|
||||
commit_two_oid,
|
||||
"commit two updated",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -141,14 +143,15 @@ fn forcepush_allowed() {
|
||||
repository,
|
||||
project_id,
|
||||
project,
|
||||
controller,
|
||||
projects,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
projects
|
||||
.update(&projects::UpdateRequest {
|
||||
@ -157,27 +160,27 @@ fn forcepush_allowed() {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let commit_one_oid = {
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
controller
|
||||
.push_virtual_branch(project, branch_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||
|
||||
controller
|
||||
.update_commit_message(project, branch_id, commit_one_oid, "commit one updated")
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::update_commit_message(
|
||||
project,
|
||||
branch_id,
|
||||
commit_one_oid,
|
||||
"commit one updated",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -198,45 +201,46 @@ fn forcepush_forbidden() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
controller
|
||||
.update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch_id,
|
||||
allow_rebasing: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
id: branch_id,
|
||||
allow_rebasing: Some(false),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let commit_one_oid = {
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
controller
|
||||
.push_virtual_branch(project, branch_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.update_commit_message(project, branch_id, commit_one_oid, "commit one updated",)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
gitbutler_branch_actions::update_commit_message(
|
||||
project,
|
||||
branch_id,
|
||||
commit_one_oid,
|
||||
"commit one updated",
|
||||
)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"force push not allowed"
|
||||
);
|
||||
}
|
||||
@ -246,45 +250,46 @@ fn root() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let commit_one_oid = {
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit two", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit three", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
controller
|
||||
.update_commit_message(project, branch_id, commit_one_oid, "commit one updated")
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::update_commit_message(
|
||||
project,
|
||||
branch_id,
|
||||
commit_one_oid,
|
||||
"commit one updated",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -307,28 +312,27 @@ fn empty() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let commit_one_oid = {
|
||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch_id, "commit one", None, false)
|
||||
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.update_commit_message(project, branch_id, commit_one_oid, "",)
|
||||
gitbutler_branch_actions::update_commit_message(project, branch_id, commit_one_oid, "",)
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
"commit message can not be empty"
|
||||
|
@ -7,50 +7,43 @@ fn detect_upstream_commits() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch1_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let oid1 = {
|
||||
// create first commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap()
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||
};
|
||||
|
||||
let oid2 = {
|
||||
// create second commit
|
||||
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap()
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||
};
|
||||
|
||||
// push
|
||||
controller
|
||||
.push_virtual_branch(project, branch1_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None).unwrap();
|
||||
|
||||
let oid3 = {
|
||||
// create third commit
|
||||
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap()
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
// 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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 3);
|
||||
@ -68,43 +61,37 @@ fn detect_integrated_commits() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::set_base_branch(
|
||||
project,
|
||||
&"refs/remotes/origin/master".parse().unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
let branch1_id =
|
||||
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||
.unwrap();
|
||||
|
||||
let oid1 = {
|
||||
// create first commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap()
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||
};
|
||||
|
||||
let oid2 = {
|
||||
// create second commit
|
||||
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap()
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||
};
|
||||
|
||||
// push
|
||||
controller
|
||||
.push_virtual_branch(project, branch1_id, false, None)
|
||||
.unwrap();
|
||||
gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None).unwrap();
|
||||
|
||||
{
|
||||
// merge branch upstream
|
||||
let branch = controller
|
||||
.list_virtual_branches(project)
|
||||
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||
.unwrap()
|
||||
.0
|
||||
.into_iter()
|
||||
@ -117,14 +104,12 @@ fn detect_integrated_commits() {
|
||||
let oid3 = {
|
||||
// create third commit
|
||||
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
||||
controller
|
||||
.create_commit(project, branch1_id, "commit", None, false)
|
||||
.unwrap()
|
||||
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
// 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[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 3);
|
||||
|
@ -8,13 +8,12 @@ fn should_fail_on_incorrect_branch() {
|
||||
let Test {
|
||||
repository,
|
||||
project,
|
||||
controller,
|
||||
..
|
||||
} = &Test::default();
|
||||
|
||||
let branch_name: LocalRefname = "refs/heads/somebranch".parse().unwrap();
|
||||
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();
|
||||
assert_eq!(
|
||||
|
@ -1,7 +1,6 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use gitbutler_branch_actions::VirtualBranchActions;
|
||||
use gitbutler_project::Project;
|
||||
use gitbutler_reference::RemoteRefname;
|
||||
|
||||
@ -31,11 +30,13 @@ pub fn add(
|
||||
.canonicalize()?;
|
||||
let project = ctrl.add(path)?;
|
||||
if let Some(refname) = refname {
|
||||
VirtualBranchActions.set_base_branch(&project, &refname)?;
|
||||
gitbutler_branch_actions::set_base_branch(&project, &refname)?;
|
||||
};
|
||||
debug_print(project)
|
||||
}
|
||||
|
||||
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,
|
||||
)?)
|
||||
}
|
||||
|
@ -2,14 +2,14 @@ use anyhow::{bail, Result};
|
||||
use gitbutler_branch::{
|
||||
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_project::Project;
|
||||
|
||||
use crate::command::debug_print;
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ pub fn list_all(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<()> {
|
||||
@ -45,16 +45,18 @@ pub fn list(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<()> {
|
||||
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<()> {
|
||||
let new = VirtualBranchActions.create_virtual_branch(
|
||||
let new = gitbutler_branch_actions::create_virtual_branch(
|
||||
&project,
|
||||
&BranchCreateRequest {
|
||||
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<()> {
|
||||
VirtualBranchActions.update_virtual_branch(
|
||||
gitbutler_branch_actions::update_virtual_branch(
|
||||
project,
|
||||
BranchUpdateRequest {
|
||||
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<()> {
|
||||
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() {
|
||||
eprintln!(
|
||||
@ -129,7 +131,7 @@ pub fn commit(project: Project, branch_name: String, message: String) -> Result<
|
||||
}
|
||||
|
||||
let run_hooks = false;
|
||||
debug_print(VirtualBranchActions.create_commit(
|
||||
debug_print(gitbutler_branch_actions::create_commit(
|
||||
&project,
|
||||
branch.id,
|
||||
&message,
|
||||
|
@ -4,7 +4,8 @@ use anyhow::{bail, Context, Result};
|
||||
use bstr::ByteSlice;
|
||||
use git2::build::CheckoutBuilder;
|
||||
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_command_context::CommandContext;
|
||||
use gitbutler_commit::{
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub mod commands {
|
||||
use anyhow::{Context, Result};
|
||||
use gitbutler_branch_actions::{RemoteBranchFile, VirtualBranchActions};
|
||||
use gitbutler_branch_actions::RemoteBranchFile;
|
||||
use gitbutler_project as projects;
|
||||
use gitbutler_project::ProjectId;
|
||||
use gitbutler_repo::RepoCommands;
|
||||
@ -69,6 +69,6 @@ pub mod commands {
|
||||
) -> Result<Vec<RemoteBranchFile>, Error> {
|
||||
let project = projects.get(id)?;
|
||||
|
||||
Ok(VirtualBranchActions.get_uncommited_files(&project)?)
|
||||
Ok(gitbutler_branch_actions::get_uncommited_files(&project)?)
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ pub mod commands {
|
||||
};
|
||||
use gitbutler_branch_actions::{
|
||||
BaseBranch, BranchListing, BranchListingDetails, BranchListingFilter, RemoteBranch,
|
||||
RemoteBranchData, RemoteBranchFile, VirtualBranchActions, VirtualBranches,
|
||||
RemoteBranchData, RemoteBranchFile, VirtualBranches,
|
||||
};
|
||||
use gitbutler_command_context::CommandContext;
|
||||
use gitbutler_error::error::Code;
|
||||
@ -38,7 +38,7 @@ pub mod commands {
|
||||
run_hooks: bool,
|
||||
) -> Result<String, Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
let oid = VirtualBranchActions.create_commit(
|
||||
let oid = gitbutler_branch_actions::create_commit(
|
||||
&project,
|
||||
branch,
|
||||
message,
|
||||
@ -56,8 +56,7 @@ pub mod commands {
|
||||
project_id: ProjectId,
|
||||
) -> Result<VirtualBranches, Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
VirtualBranchActions
|
||||
.list_virtual_branches(&project)
|
||||
gitbutler_branch_actions::list_virtual_branches(&project)
|
||||
.map_err(Into::into)
|
||||
.map(|(branches, skipped_files)| VirtualBranches {
|
||||
branches,
|
||||
@ -74,7 +73,7 @@ pub mod commands {
|
||||
branch: BranchCreateRequest,
|
||||
) -> Result<BranchId, Error> {
|
||||
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);
|
||||
Ok(branch_id)
|
||||
}
|
||||
@ -89,7 +88,7 @@ pub mod commands {
|
||||
given_name: String,
|
||||
) -> Result<(), Error> {
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -105,7 +104,7 @@ pub mod commands {
|
||||
) -> Result<BranchId, Error> {
|
||||
let project = projects.get(project_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);
|
||||
Ok(branch_id)
|
||||
}
|
||||
@ -119,7 +118,7 @@ pub mod commands {
|
||||
branch: BranchId,
|
||||
) -> Result<(), Error> {
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -131,7 +130,7 @@ pub mod commands {
|
||||
project_id: ProjectId,
|
||||
) -> Result<Option<BaseBranch>, Error> {
|
||||
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))
|
||||
} else {
|
||||
Ok(None)
|
||||
@ -151,11 +150,11 @@ pub mod commands {
|
||||
let branch_name = format!("refs/remotes/{}", branch)
|
||||
.parse()
|
||||
.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 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);
|
||||
Ok(base_branch)
|
||||
@ -169,7 +168,7 @@ pub mod commands {
|
||||
project_id: ProjectId,
|
||||
) -> Result<Vec<ReferenceName>, Error> {
|
||||
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);
|
||||
Ok(unapplied_branches)
|
||||
}
|
||||
@ -183,7 +182,7 @@ pub mod commands {
|
||||
branch: BranchUpdateRequest,
|
||||
) -> Result<(), Error> {
|
||||
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);
|
||||
Ok(())
|
||||
@ -198,7 +197,7 @@ pub mod commands {
|
||||
branches: Vec<BranchUpdateRequest>,
|
||||
) -> Result<(), Error> {
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -212,7 +211,7 @@ pub mod commands {
|
||||
branch_id: BranchId,
|
||||
) -> Result<(), Error> {
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -226,7 +225,7 @@ pub mod commands {
|
||||
branch: BranchId,
|
||||
) -> Result<(), Error> {
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -240,7 +239,7 @@ pub mod commands {
|
||||
ownership: BranchOwnershipClaims,
|
||||
) -> Result<(), Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
VirtualBranchActions.unapply_ownership(&project, &ownership)?;
|
||||
gitbutler_branch_actions::unapply_ownership(&project, &ownership)?;
|
||||
emit_vbranches(&windows, project_id);
|
||||
Ok(())
|
||||
}
|
||||
@ -255,7 +254,7 @@ pub mod commands {
|
||||
files: Vec<PathBuf>,
|
||||
) -> Result<(), Error> {
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -270,9 +269,13 @@ pub mod commands {
|
||||
with_force: bool,
|
||||
) -> Result<(), Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
VirtualBranchActions
|
||||
.push_virtual_branch(&project, branch_id, with_force, Some(Some(branch_id)))
|
||||
.map_err(|err| err.context(Code::Unknown))?;
|
||||
gitbutler_branch_actions::push_virtual_branch(
|
||||
&project,
|
||||
branch_id,
|
||||
with_force,
|
||||
Some(Some(branch_id)),
|
||||
)
|
||||
.map_err(|err| err.context(Code::Unknown))?;
|
||||
emit_vbranches(&windows, project_id);
|
||||
Ok(())
|
||||
}
|
||||
@ -285,7 +288,9 @@ pub mod commands {
|
||||
branch: RemoteRefname,
|
||||
) -> Result<bool, Error> {
|
||||
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)]
|
||||
@ -297,9 +302,7 @@ pub mod commands {
|
||||
) -> Result<Vec<RemoteBranchFile>, Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||
VirtualBranchActions
|
||||
.list_remote_commit_files(&project, commit_oid)
|
||||
.map_err(Into::into)
|
||||
gitbutler_branch_actions::list_remote_commit_files(&project, commit_oid).map_err(Into::into)
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
@ -313,7 +316,7 @@ pub mod commands {
|
||||
) -> Result<(), Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -330,7 +333,7 @@ pub mod commands {
|
||||
) -> Result<String, Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
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);
|
||||
Ok(oid.to_string())
|
||||
}
|
||||
@ -349,7 +352,7 @@ pub mod commands {
|
||||
let project = projects.get(project_id)?;
|
||||
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 oid = VirtualBranchActions.move_commit_file(
|
||||
let oid = gitbutler_branch_actions::move_commit_file(
|
||||
&project,
|
||||
branch_id,
|
||||
from_commit_oid,
|
||||
@ -371,7 +374,7 @@ pub mod commands {
|
||||
) -> Result<(), Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -388,7 +391,7 @@ pub mod commands {
|
||||
) -> Result<(), Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -404,7 +407,7 @@ pub mod commands {
|
||||
change_id: String,
|
||||
) -> Result<(), Error> {
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -420,7 +423,7 @@ pub mod commands {
|
||||
with_force: bool,
|
||||
) -> Result<(), Error> {
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -436,7 +439,12 @@ pub mod commands {
|
||||
new_change_id: String,
|
||||
) -> Result<(), Error> {
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -453,7 +461,7 @@ pub mod commands {
|
||||
) -> Result<(), Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -465,7 +473,7 @@ pub mod commands {
|
||||
project_id: ProjectId,
|
||||
) -> Result<Vec<RemoteBranch>, Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
let branches = VirtualBranchActions::list_local_branches(project)?;
|
||||
let branches = gitbutler_branch_actions::list_local_branches(project)?;
|
||||
Ok(branches)
|
||||
}
|
||||
|
||||
@ -501,7 +509,7 @@ pub mod commands {
|
||||
refname: Refname,
|
||||
) -> Result<RemoteBranchData, Error> {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -516,7 +524,7 @@ pub mod commands {
|
||||
) -> Result<(), Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -530,7 +538,7 @@ pub mod commands {
|
||||
) -> Result<BaseBranch, Error> {
|
||||
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,
|
||||
Some(action.unwrap_or_else(|| "unknown".to_string())),
|
||||
)?;
|
||||
@ -550,7 +558,7 @@ pub mod commands {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -565,7 +573,7 @@ pub mod commands {
|
||||
) -> Result<(), Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
@ -582,7 +590,7 @@ pub mod commands {
|
||||
) -> Result<(), Error> {
|
||||
let project = projects.get(project_id)?;
|
||||
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);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use super::{events, Change};
|
||||
use anyhow::{Context, Result};
|
||||
use gitbutler_branch_actions::{RemoteBranchFile, VirtualBranchActions, VirtualBranches};
|
||||
use gitbutler_branch_actions::{RemoteBranchFile, VirtualBranches};
|
||||
use gitbutler_command_context::CommandContext;
|
||||
use gitbutler_diff::DiffByPathMap;
|
||||
use gitbutler_error::error::Marker;
|
||||
@ -106,7 +106,7 @@ impl Handler {
|
||||
.projects
|
||||
.get(project_id)
|
||||
.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 {
|
||||
project_id: project.id,
|
||||
virtual_branches: VirtualBranches {
|
||||
@ -142,7 +142,7 @@ impl Handler {
|
||||
|
||||
/// Try to emit uncommited files. Swollow errors if they arrise.
|
||||
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 {
|
||||
project_id: project.id,
|
||||
|
Loading…
Reference in New Issue
Block a user