mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-26 02:51:57 +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 std::borrow::Cow;
|
||||||
|
|
||||||
|
use crate::r#virtual as vbranch;
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
use gitbutler_branch::{self, dedup, Branch, BranchCreateRequest, BranchId, BranchOwnershipClaims};
|
use gitbutler_branch::{self, dedup, Branch, BranchCreateRequest, BranchId, BranchOwnershipClaims};
|
||||||
use gitbutler_commit::commit_headers::HasCommitHeaders;
|
use gitbutler_commit::commit_headers::HasCommitHeaders;
|
||||||
@ -14,10 +15,9 @@ use tracing::instrument;
|
|||||||
use super::BranchManager;
|
use super::BranchManager;
|
||||||
use crate::{
|
use crate::{
|
||||||
conflicts::{self, RepoConflictsExt},
|
conflicts::{self, RepoConflictsExt},
|
||||||
ensure_selected_for_changes,
|
|
||||||
hunk::VirtualBranchHunk,
|
hunk::VirtualBranchHunk,
|
||||||
integration::update_workspace_commit,
|
integration::update_workspace_commit,
|
||||||
set_ownership, undo_commit, VirtualBranchesExt,
|
VirtualBranchesExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl BranchManager<'_> {
|
impl BranchManager<'_> {
|
||||||
@ -118,7 +118,8 @@ impl BranchManager<'_> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ownership) = &create.ownership {
|
if let Some(ownership) = &create.ownership {
|
||||||
set_ownership(&vb_state, &mut branch, ownership).context("failed to set ownership")?;
|
vbranch::set_ownership(&vb_state, &mut branch, ownership)
|
||||||
|
.context("failed to set ownership")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
vb_state.set_branch(branch.clone())?;
|
vb_state.set_branch(branch.clone())?;
|
||||||
@ -489,7 +490,8 @@ impl BranchManager<'_> {
|
|||||||
// apply the branch
|
// apply the branch
|
||||||
vb_state.set_branch(branch.clone())?;
|
vb_state.set_branch(branch.clone())?;
|
||||||
|
|
||||||
ensure_selected_for_changes(&vb_state).context("failed to ensure selected for changes")?;
|
vbranch::ensure_selected_for_changes(&vb_state)
|
||||||
|
.context("failed to ensure selected for changes")?;
|
||||||
// checkout the merge index
|
// checkout the merge index
|
||||||
repo.checkout_index_builder(&mut merge_index)
|
repo.checkout_index_builder(&mut merge_index)
|
||||||
.force()
|
.force()
|
||||||
@ -505,7 +507,7 @@ impl BranchManager<'_> {
|
|||||||
|
|
||||||
if let Some(headers) = potential_wip_commit.gitbutler_headers() {
|
if let Some(headers) = potential_wip_commit.gitbutler_headers() {
|
||||||
if headers.change_id == wip_commit_to_unapply {
|
if headers.change_id == wip_commit_to_unapply {
|
||||||
undo_commit(self.ctx, branch.id, branch.head)?;
|
vbranch::undo_commit(self.ctx, branch.id, branch.head)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,10 @@ use gitbutler_repo::{RepoActionsExt, RepositoryExt};
|
|||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use super::BranchManager;
|
use super::BranchManager;
|
||||||
|
use crate::r#virtual as vbranch;
|
||||||
use crate::{
|
use crate::{
|
||||||
conflicts::{self},
|
conflicts::{self},
|
||||||
ensure_selected_for_changes, get_applied_status,
|
get_applied_status,
|
||||||
hunk::VirtualBranchHunk,
|
hunk::VirtualBranchHunk,
|
||||||
VirtualBranchesExt,
|
VirtualBranchesExt,
|
||||||
};
|
};
|
||||||
@ -47,7 +48,8 @@ impl BranchManager<'_> {
|
|||||||
vb_state.update_ordering()?;
|
vb_state.update_ordering()?;
|
||||||
|
|
||||||
// Ensure we still have a default target
|
// Ensure we still have a default target
|
||||||
ensure_selected_for_changes(&vb_state).context("failed to ensure selected for changes")?;
|
vbranch::ensure_selected_for_changes(&vb_state)
|
||||||
|
.context("failed to ensure selected for changes")?;
|
||||||
|
|
||||||
crate::integration::update_workspace_commit(&vb_state, self.ctx)?;
|
crate::integration::update_workspace_commit(&vb_state, self.ctx)?;
|
||||||
|
|
||||||
@ -132,7 +134,8 @@ impl BranchManager<'_> {
|
|||||||
|
|
||||||
self.ctx.delete_branch_reference(&branch)?;
|
self.ctx.delete_branch_reference(&branch)?;
|
||||||
|
|
||||||
ensure_selected_for_changes(&vb_state).context("failed to ensure selected for changes")?;
|
vbranch::ensure_selected_for_changes(&vb_state)
|
||||||
|
.context("failed to ensure selected for changes")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,27 @@
|
|||||||
//! GitButler internal library containing functionality related to branches, i.e. the virtual branches implementation
|
//! GitButler internal library containing functionality related to branches, i.e. the virtual branches implementation
|
||||||
mod actions;
|
mod actions;
|
||||||
pub use actions::VirtualBranchActions;
|
// This is our API
|
||||||
|
pub use actions::{
|
||||||
|
amend, can_apply_remote_branch, convert_to_real_branch, create_change_reference, create_commit,
|
||||||
|
create_virtual_branch, create_virtual_branch_from_branch, delete_local_branch,
|
||||||
|
delete_virtual_branch, fetch_from_remotes, get_base_branch_data, get_remote_branch_data,
|
||||||
|
get_uncommited_files, get_uncommited_files_reusable, insert_blank_commit,
|
||||||
|
integrate_upstream_commits, list_local_branches, list_remote_commit_files,
|
||||||
|
list_virtual_branches, list_virtual_branches_cached, move_commit, move_commit_file,
|
||||||
|
push_change_reference, push_virtual_branch, reorder_commit, reset_files, reset_virtual_branch,
|
||||||
|
set_base_branch, set_target_push_remote, squash, unapply_ownership, undo_commit,
|
||||||
|
update_base_branch, update_branch_order, update_change_reference, update_commit_message,
|
||||||
|
update_virtual_branch,
|
||||||
|
};
|
||||||
|
|
||||||
mod r#virtual;
|
mod r#virtual;
|
||||||
pub use r#virtual::*;
|
pub use r#virtual::{BranchStatus, VirtualBranch, VirtualBranchHunksByPathMap, VirtualBranches};
|
||||||
|
/// Avoid using these!
|
||||||
|
/// This was previously `pub use r#virtual::*;`
|
||||||
|
pub mod internal {
|
||||||
|
pub use super::r#virtual::*;
|
||||||
|
pub use super::remote::list_local_branches;
|
||||||
|
}
|
||||||
|
|
||||||
mod branch_manager;
|
mod branch_manager;
|
||||||
pub use branch_manager::{BranchManager, BranchManagerExt};
|
pub use branch_manager::{BranchManager, BranchManagerExt};
|
||||||
@ -18,7 +36,7 @@ mod file;
|
|||||||
pub use file::{Get, RemoteBranchFile};
|
pub use file::{Get, RemoteBranchFile};
|
||||||
|
|
||||||
mod remote;
|
mod remote;
|
||||||
pub use remote::{list_local_branches, RemoteBranch, RemoteBranchData, RemoteCommit};
|
pub use remote::{RemoteBranch, RemoteBranchData, RemoteCommit};
|
||||||
|
|
||||||
pub mod conflicts;
|
pub mod conflicts;
|
||||||
|
|
||||||
|
@ -16,9 +16,7 @@ use gitbutler_branch::{
|
|||||||
BranchCreateRequest, BranchOwnershipClaims, BranchUpdateRequest, Target, VirtualBranchesHandle,
|
BranchCreateRequest, BranchOwnershipClaims, BranchUpdateRequest, Target, VirtualBranchesHandle,
|
||||||
};
|
};
|
||||||
use gitbutler_branch_actions::{
|
use gitbutler_branch_actions::{
|
||||||
commit, get_applied_status, integrate_upstream_commits, is_remote_branch_mergeable,
|
get_applied_status, internal, update_workspace_commit, verify_branch, BranchManagerExt, Get,
|
||||||
list_virtual_branches, unapply_ownership, update_branch, update_workspace_commit,
|
|
||||||
verify_branch, BranchManagerExt, Get,
|
|
||||||
};
|
};
|
||||||
use gitbutler_commit::{commit_ext::CommitExt, commit_headers::CommitHeadersV2};
|
use gitbutler_commit::{commit_ext::CommitExt, commit_headers::CommitHeadersV2};
|
||||||
use gitbutler_reference::{Refname, RemoteRefname};
|
use gitbutler_reference::{Refname, RemoteRefname};
|
||||||
@ -48,16 +46,16 @@ fn commit_on_branch_then_change_file_then_get_status() -> Result<()> {
|
|||||||
"line0\nline1\nline2\nline3\nline4\n",
|
"line0\nline1\nline2\nline3\nline4\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches[0];
|
let branch = &branches[0];
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
assert_eq!(branch.commits.len(), 0);
|
assert_eq!(branch.commits.len(), 0);
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
commit(ctx, branch1_id, "test commit", None, false)?;
|
internal::commit(ctx, branch1_id, "test commit", None, false)?;
|
||||||
|
|
||||||
// status (no files)
|
// status (no files)
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches[0];
|
let branch = &branches[0];
|
||||||
assert_eq!(branch.files.len(), 0);
|
assert_eq!(branch.files.len(), 0);
|
||||||
assert_eq!(branch.commits.len(), 1);
|
assert_eq!(branch.commits.len(), 1);
|
||||||
@ -68,7 +66,7 @@ fn commit_on_branch_then_change_file_then_get_status() -> Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// should have just the last change now, the other line is committed
|
// should have just the last change now, the other line is committed
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches[0];
|
let branch = &branches[0];
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
assert_eq!(branch.commits.len(), 1);
|
assert_eq!(branch.commits.len(), 1);
|
||||||
@ -127,7 +125,7 @@ fn track_binary_files() -> Result<()> {
|
|||||||
let mut file = std::fs::File::create(Path::new(&project.path).join("image.bin"))?;
|
let mut file = std::fs::File::create(Path::new(&project.path).join("image.bin"))?;
|
||||||
file.write_all(&image_data)?;
|
file.write_all(&image_data)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches[0];
|
let branch = &branches[0];
|
||||||
assert_eq!(branch.files.len(), 2);
|
assert_eq!(branch.files.len(), 2);
|
||||||
let img_file = &branch
|
let img_file = &branch
|
||||||
@ -144,10 +142,10 @@ fn track_binary_files() -> Result<()> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
commit(ctx, branch1_id, "test commit", None, false)?;
|
internal::commit(ctx, branch1_id, "test commit", None, false)?;
|
||||||
|
|
||||||
// status (no files)
|
// status (no files)
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission()).unwrap();
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission()).unwrap();
|
||||||
let commit_id = &branches[0].commits[0].id;
|
let commit_id = &branches[0].commits[0].id;
|
||||||
let commit_obj = ctx.repository().find_commit(commit_id.to_owned())?;
|
let commit_obj = ctx.repository().find_commit(commit_id.to_owned())?;
|
||||||
let tree = commit_obj.tree()?;
|
let tree = commit_obj.tree()?;
|
||||||
@ -168,9 +166,9 @@ fn track_binary_files() -> Result<()> {
|
|||||||
file.write_all(&image_data)?;
|
file.write_all(&image_data)?;
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
commit(ctx, branch1_id, "test commit", None, false)?;
|
internal::commit(ctx, branch1_id, "test commit", None, false)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission()).unwrap();
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission()).unwrap();
|
||||||
let commit_id = &branches[0].commits[0].id;
|
let commit_id = &branches[0].commits[0].id;
|
||||||
// get tree from commit_id
|
// get tree from commit_id
|
||||||
let commit_obj = ctx.repository().find_commit(commit_id.to_owned())?;
|
let commit_obj = ctx.repository().find_commit(commit_id.to_owned())?;
|
||||||
@ -335,7 +333,7 @@ fn hunk_expantion() -> Result<()> {
|
|||||||
assert_eq!(files_by_branch_id[&branch2_id].len(), 0);
|
assert_eq!(files_by_branch_id[&branch2_id].len(), 0);
|
||||||
|
|
||||||
// even though selected branch has changed
|
// even though selected branch has changed
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch1_id,
|
id: branch1_id,
|
||||||
@ -343,7 +341,7 @@ fn hunk_expantion() -> Result<()> {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch2_id,
|
id: branch2_id,
|
||||||
@ -483,7 +481,7 @@ fn move_hunks_multiple_sources() -> Result<()> {
|
|||||||
// assert_eq!(files_by_branch_id[&branch2_id][0].hunks.len(), 1);
|
// assert_eq!(files_by_branch_id[&branch2_id][0].hunks.len(), 1);
|
||||||
assert_eq!(files_by_branch_id[&branch3_id].len(), 0);
|
assert_eq!(files_by_branch_id[&branch3_id].len(), 0);
|
||||||
|
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch3_id,
|
id: branch3_id,
|
||||||
@ -576,7 +574,7 @@ fn move_hunks_partial_explicitly() -> Result<()> {
|
|||||||
// assert_eq!(files_by_branch_id[&branch1_id][0].hunks.len(), 2);
|
// assert_eq!(files_by_branch_id[&branch1_id][0].hunks.len(), 2);
|
||||||
assert_eq!(files_by_branch_id[&branch2_id].len(), 0);
|
assert_eq!(files_by_branch_id[&branch2_id].len(), 0);
|
||||||
|
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch2_id,
|
id: branch2_id,
|
||||||
@ -828,7 +826,7 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
|
|||||||
vb_state.set_branch(branch.clone())?;
|
vb_state.set_branch(branch.clone())?;
|
||||||
|
|
||||||
// create the branch
|
// create the branch
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
let branch1 = &branches[0];
|
let branch1 = &branches[0];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -840,9 +838,9 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
|
|||||||
assert_eq!(branch1.commits.len(), 1);
|
assert_eq!(branch1.commits.len(), 1);
|
||||||
// assert_eq!(branch1.upstream.as_ref().unwrap().commits.len(), 1);
|
// assert_eq!(branch1.upstream.as_ref().unwrap().commits.len(), 1);
|
||||||
|
|
||||||
integrate_upstream_commits(ctx, branch1.id)?;
|
internal::integrate_upstream_commits(ctx, branch1.id)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch1 = &branches[0];
|
let branch1 = &branches[0];
|
||||||
|
|
||||||
let contents = std::fs::read(Path::new(&project.path).join(file_path))?;
|
let contents = std::fs::read(Path::new(&project.path).join(file_path))?;
|
||||||
@ -933,7 +931,7 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
|
|||||||
branch.head = last_push;
|
branch.head = last_push;
|
||||||
vb_state.set_branch(branch.clone())?;
|
vb_state.set_branch(branch.clone())?;
|
||||||
|
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch.id,
|
id: branch.id,
|
||||||
@ -944,16 +942,16 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create the branch
|
// create the branch
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch1 = &branches[0];
|
let branch1 = &branches[0];
|
||||||
|
|
||||||
assert_eq!(branch1.files.len(), 1);
|
assert_eq!(branch1.files.len(), 1);
|
||||||
assert_eq!(branch1.commits.len(), 1);
|
assert_eq!(branch1.commits.len(), 1);
|
||||||
// assert_eq!(branch1.upstream.as_ref().unwrap().commits.len(), 1);
|
// assert_eq!(branch1.upstream.as_ref().unwrap().commits.len(), 1);
|
||||||
|
|
||||||
integrate_upstream_commits(ctx, branch1.id)?;
|
internal::integrate_upstream_commits(ctx, branch1.id)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch1 = &branches[0];
|
let branch1 = &branches[0];
|
||||||
let contents = std::fs::read(Path::new(&project.path).join(file_path))?;
|
let contents = std::fs::read(Path::new(&project.path).join(file_path))?;
|
||||||
|
|
||||||
@ -974,13 +972,13 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
|
|||||||
|
|
||||||
// make gb see the conflict resolution
|
// make gb see the conflict resolution
|
||||||
update_workspace_commit(&vb_state, ctx)?;
|
update_workspace_commit(&vb_state, ctx)?;
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
assert!(branches[0].conflicted);
|
assert!(branches[0].conflicted);
|
||||||
|
|
||||||
// commit the merge resolution
|
// commit the merge resolution
|
||||||
commit(ctx, branch1.id, "fix merge conflict", None, false)?;
|
internal::commit(ctx, branch1.id, "fix merge conflict", None, false)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch1 = &branches[0];
|
let branch1 = &branches[0];
|
||||||
assert!(!branch1.conflicted);
|
assert!(!branch1.conflicted);
|
||||||
assert_eq!(branch1.files.len(), 0);
|
assert_eq!(branch1.files.len(), 0);
|
||||||
@ -1015,7 +1013,7 @@ fn unapply_ownership_partial() -> Result<()> {
|
|||||||
.create_virtual_branch(&BranchCreateRequest::default(), guard.write_permission())
|
.create_virtual_branch(&BranchCreateRequest::default(), guard.write_permission())
|
||||||
.expect("failed to create virtual branch");
|
.expect("failed to create virtual branch");
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].files.len(), 1);
|
assert_eq!(branches[0].files.len(), 1);
|
||||||
assert_eq!(branches[0].ownership.claims.len(), 1);
|
assert_eq!(branches[0].ownership.claims.len(), 1);
|
||||||
@ -1026,14 +1024,14 @@ fn unapply_ownership_partial() -> Result<()> {
|
|||||||
"line1\nline2\nline3\nline4\nbranch1\n"
|
"line1\nline2\nline3\nline4\nbranch1\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
unapply_ownership(
|
internal::unapply_ownership(
|
||||||
ctx,
|
ctx,
|
||||||
&"test.txt:2-6".parse().unwrap(),
|
&"test.txt:2-6".parse().unwrap(),
|
||||||
guard.write_permission(),
|
guard.write_permission(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].files.len(), 0);
|
assert_eq!(branches[0].files.len(), 0);
|
||||||
assert_eq!(branches[0].ownership.claims.len(), 0);
|
assert_eq!(branches[0].ownership.claims.len(), 0);
|
||||||
@ -1078,7 +1076,7 @@ fn unapply_branch() -> Result<()> {
|
|||||||
.expect("failed to create virtual branch")
|
.expect("failed to create virtual branch")
|
||||||
.id;
|
.id;
|
||||||
|
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch2_id,
|
id: branch2_id,
|
||||||
@ -1095,7 +1093,7 @@ fn unapply_branch() -> Result<()> {
|
|||||||
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
|
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
|
||||||
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
assert!(branch.active);
|
assert!(branch.active);
|
||||||
@ -1109,7 +1107,7 @@ fn unapply_branch() -> Result<()> {
|
|||||||
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
|
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
|
||||||
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
assert!(!branches.iter().any(|b| b.id == branch1_id));
|
assert!(!branches.iter().any(|b| b.id == branch1_id));
|
||||||
|
|
||||||
let branch_manager = ctx.branch_manager();
|
let branch_manager = ctx.branch_manager();
|
||||||
@ -1126,7 +1124,7 @@ fn unapply_branch() -> Result<()> {
|
|||||||
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
|
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
|
||||||
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
// TODO: expect there to be 0 branches
|
// TODO: expect there to be 0 branches
|
||||||
assert_eq!(branch.files.len(), 0);
|
assert_eq!(branch.files.len(), 0);
|
||||||
@ -1165,7 +1163,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
|
|||||||
.expect("failed to create virtual branch")
|
.expect("failed to create virtual branch")
|
||||||
.id;
|
.id;
|
||||||
|
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch2_id,
|
id: branch2_id,
|
||||||
@ -1173,7 +1171,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch3_id,
|
id: branch3_id,
|
||||||
@ -1182,7 +1180,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
|
|||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
list_virtual_branches(ctx, guard.write_permission()).unwrap();
|
internal::list_virtual_branches(ctx, guard.write_permission()).unwrap();
|
||||||
|
|
||||||
let branch_manager = ctx.branch_manager();
|
let branch_manager = ctx.branch_manager();
|
||||||
let real_branch_2 =
|
let real_branch_2 =
|
||||||
@ -1257,7 +1255,7 @@ fn detect_mergeable_branch() -> Result<()> {
|
|||||||
.expect("failed to create virtual branch")
|
.expect("failed to create virtual branch")
|
||||||
.id;
|
.id;
|
||||||
|
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch2_id,
|
id: branch2_id,
|
||||||
@ -1344,13 +1342,13 @@ fn detect_mergeable_branch() -> Result<()> {
|
|||||||
};
|
};
|
||||||
vb_state.set_branch(branch4.clone())?;
|
vb_state.set_branch(branch4.clone())?;
|
||||||
|
|
||||||
let remotes =
|
let remotes = gitbutler_branch_actions::internal::list_local_branches(ctx)
|
||||||
gitbutler_branch_actions::list_local_branches(ctx).expect("failed to list remotes");
|
.expect("failed to list remotes");
|
||||||
let _remote1 = &remotes
|
let _remote1 = &remotes
|
||||||
.iter()
|
.iter()
|
||||||
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch")
|
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!is_remote_branch_mergeable(
|
assert!(!internal::is_remote_branch_mergeable(
|
||||||
ctx,
|
ctx,
|
||||||
&"refs/remotes/origin/remote_branch".parse().unwrap()
|
&"refs/remotes/origin/remote_branch".parse().unwrap()
|
||||||
)
|
)
|
||||||
@ -1361,7 +1359,7 @@ fn detect_mergeable_branch() -> Result<()> {
|
|||||||
.iter()
|
.iter()
|
||||||
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch2")
|
.find(|b| b.name.to_string() == "refs/remotes/origin/remote_branch2")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(is_remote_branch_mergeable(
|
assert!(internal::is_remote_branch_mergeable(
|
||||||
ctx,
|
ctx,
|
||||||
&"refs/remotes/origin/remote_branch2".parse().unwrap()
|
&"refs/remotes/origin/remote_branch2".parse().unwrap()
|
||||||
)
|
)
|
||||||
@ -1437,7 +1435,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
|||||||
"file3\nversion2\n",
|
"file3\nversion2\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch1_id,
|
id: branch1_id,
|
||||||
@ -1447,7 +1445,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
|||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch2_id,
|
id: branch2_id,
|
||||||
@ -1457,7 +1455,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
|||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
update_branch(
|
internal::update_branch(
|
||||||
ctx,
|
ctx,
|
||||||
&BranchUpdateRequest {
|
&BranchUpdateRequest {
|
||||||
id: branch3_id,
|
id: branch3_id,
|
||||||
@ -1468,10 +1466,10 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// create a new virtual branch from the remote branch
|
// create a new virtual branch from the remote branch
|
||||||
commit(ctx, branch1_id, "integrated commit", None, false)?;
|
internal::commit(ctx, branch1_id, "integrated commit", None, false)?;
|
||||||
commit(ctx, branch2_id, "non-integrated commit", None, false)?;
|
internal::commit(ctx, branch2_id, "non-integrated commit", None, false)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
|
|
||||||
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
assert!(branch1.commits.iter().any(|c| c.is_integrated));
|
assert!(branch1.commits.iter().any(|c| c.is_integrated));
|
||||||
@ -1517,7 +1515,7 @@ fn commit_same_hunk_twice() -> Result<()> {
|
|||||||
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
@ -1525,9 +1523,9 @@ fn commit_same_hunk_twice() -> Result<()> {
|
|||||||
assert_eq!(branch.commits.len(), 0);
|
assert_eq!(branch.commits.len(), 0);
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
commit(ctx, branch1_id, "first commit to test.txt", None, false)?;
|
internal::commit(ctx, branch1_id, "first commit to test.txt", None, false)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 0, "no files expected");
|
assert_eq!(branch.files.len(), 0, "no files expected");
|
||||||
@ -1547,15 +1545,15 @@ fn commit_same_hunk_twice() -> Result<()> {
|
|||||||
"line1\nPATCH1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
"line1\nPATCH1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1, "one file should be changed");
|
assert_eq!(branch.files.len(), 1, "one file should be changed");
|
||||||
assert_eq!(branch.commits.len(), 1, "commit is still there");
|
assert_eq!(branch.commits.len(), 1, "commit is still there");
|
||||||
|
|
||||||
commit(ctx, branch1_id, "second commit to test.txt", None, false)?;
|
internal::commit(ctx, branch1_id, "second commit to test.txt", None, false)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -1599,7 +1597,7 @@ fn commit_same_file_twice() -> Result<()> {
|
|||||||
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
@ -1607,9 +1605,9 @@ fn commit_same_file_twice() -> Result<()> {
|
|||||||
assert_eq!(branch.commits.len(), 0);
|
assert_eq!(branch.commits.len(), 0);
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
commit(ctx, branch1_id, "first commit to test.txt", None, false)?;
|
internal::commit(ctx, branch1_id, "first commit to test.txt", None, false)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 0, "no files expected");
|
assert_eq!(branch.files.len(), 0, "no files expected");
|
||||||
@ -1629,15 +1627,15 @@ fn commit_same_file_twice() -> Result<()> {
|
|||||||
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n",
|
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1, "one file should be changed");
|
assert_eq!(branch.files.len(), 1, "one file should be changed");
|
||||||
assert_eq!(branch.commits.len(), 1, "commit is still there");
|
assert_eq!(branch.commits.len(), 1, "commit is still there");
|
||||||
|
|
||||||
commit(ctx, branch1_id, "second commit to test.txt", None, false)?;
|
internal::commit(ctx, branch1_id, "second commit to test.txt", None, false)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -1681,7 +1679,7 @@ fn commit_partial_by_hunk() -> Result<()> {
|
|||||||
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n",
|
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
@ -1689,7 +1687,7 @@ fn commit_partial_by_hunk() -> Result<()> {
|
|||||||
assert_eq!(branch.commits.len(), 0);
|
assert_eq!(branch.commits.len(), 0);
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
commit(
|
internal::commit(
|
||||||
ctx,
|
ctx,
|
||||||
branch1_id,
|
branch1_id,
|
||||||
"first commit to test.txt",
|
"first commit to test.txt",
|
||||||
@ -1697,7 +1695,7 @@ fn commit_partial_by_hunk() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
@ -1706,7 +1704,7 @@ fn commit_partial_by_hunk() -> Result<()> {
|
|||||||
assert_eq!(branch.commits[0].files.len(), 1);
|
assert_eq!(branch.commits[0].files.len(), 1);
|
||||||
assert_eq!(branch.commits[0].files[0].hunks.len(), 1);
|
assert_eq!(branch.commits[0].files[0].hunks.len(), 1);
|
||||||
|
|
||||||
commit(
|
internal::commit(
|
||||||
ctx,
|
ctx,
|
||||||
branch1_id,
|
branch1_id,
|
||||||
"second commit to test.txt",
|
"second commit to test.txt",
|
||||||
@ -1714,7 +1712,7 @@ fn commit_partial_by_hunk() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 0);
|
assert_eq!(branch.files.len(), 0);
|
||||||
@ -1754,9 +1752,9 @@ fn commit_partial_by_file() -> Result<()> {
|
|||||||
.id;
|
.id;
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
commit(ctx, branch1_id, "branch1 commit", None, false)?;
|
internal::commit(ctx, branch1_id, "branch1 commit", None, false)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
// branch one test.txt has just the 1st and 3rd hunks applied
|
// branch one test.txt has just the 1st and 3rd hunks applied
|
||||||
@ -1805,9 +1803,9 @@ fn commit_add_and_delete_files() -> Result<()> {
|
|||||||
.id;
|
.id;
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
commit(ctx, branch1_id, "branch1 commit", None, false)?;
|
internal::commit(ctx, branch1_id, "branch1 commit", None, false)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
// branch one test.txt has just the 1st and 3rd hunks applied
|
// branch one test.txt has just the 1st and 3rd hunks applied
|
||||||
@ -1862,9 +1860,9 @@ fn commit_executable_and_symlinks() -> Result<()> {
|
|||||||
.id;
|
.id;
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
commit(ctx, branch1_id, "branch1 commit", None, false)?;
|
internal::commit(ctx, branch1_id, "branch1 commit", None, false)?;
|
||||||
|
|
||||||
let (branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
let commit = &branch1.commits[0].id;
|
let commit = &branch1.commits[0].id;
|
||||||
@ -1960,7 +1958,7 @@ fn verify_branch_commits_to_workspace() -> Result<()> {
|
|||||||
verify_branch(ctx, guard.write_permission()).unwrap();
|
verify_branch(ctx, guard.write_permission()).unwrap();
|
||||||
|
|
||||||
// one virtual branch with two commits was created
|
// one virtual branch with two commits was created
|
||||||
let (virtual_branches, _) = list_virtual_branches(ctx, guard.write_permission())?;
|
let (virtual_branches, _) = internal::list_virtual_branches(ctx, guard.write_permission())?;
|
||||||
assert_eq!(virtual_branches.len(), 1);
|
assert_eq!(virtual_branches.len(), 1);
|
||||||
|
|
||||||
let branch = &virtual_branches.first().unwrap();
|
let branch = &virtual_branches.first().unwrap();
|
||||||
@ -2021,7 +2019,7 @@ fn pre_commit_hook_rejection() -> Result<()> {
|
|||||||
|
|
||||||
git2_hooks::create_hook(ctx.repository(), git2_hooks::HOOK_PRE_COMMIT, hook);
|
git2_hooks::create_hook(ctx.repository(), git2_hooks::HOOK_PRE_COMMIT, hook);
|
||||||
|
|
||||||
let res = commit(ctx, branch1_id, "test commit", None, true);
|
let res = internal::commit(ctx, branch1_id, "test commit", None, true);
|
||||||
|
|
||||||
let err = res.unwrap_err();
|
let err = res.unwrap_err();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -2064,7 +2062,7 @@ fn post_commit_hook() -> Result<()> {
|
|||||||
|
|
||||||
assert!(!hook_ran_proof.exists());
|
assert!(!hook_ran_proof.exists());
|
||||||
|
|
||||||
commit(ctx, branch1_id, "test commit", None, true)?;
|
internal::commit(ctx, branch1_id, "test commit", None, true)?;
|
||||||
|
|
||||||
assert!(hook_ran_proof.exists());
|
assert!(hook_ran_proof.exists());
|
||||||
|
|
||||||
@ -2100,7 +2098,7 @@ fn commit_msg_hook_rejection() -> Result<()> {
|
|||||||
|
|
||||||
git2_hooks::create_hook(ctx.repository(), git2_hooks::HOOK_COMMIT_MSG, hook);
|
git2_hooks::create_hook(ctx.repository(), git2_hooks::HOOK_COMMIT_MSG, hook);
|
||||||
|
|
||||||
let res = commit(ctx, branch1_id, "test commit", None, true);
|
let res = internal::commit(ctx, branch1_id, "test commit", None, true);
|
||||||
|
|
||||||
let err = res.unwrap_err();
|
let err = res.unwrap_err();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -8,7 +8,6 @@ fn forcepush_allowed() {
|
|||||||
repository,
|
repository,
|
||||||
project_id,
|
project_id,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
projects,
|
projects,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
@ -20,9 +19,11 @@ fn forcepush_allowed() {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
projects
|
projects
|
||||||
.update(&projects::UpdateRequest {
|
.update(&projects::UpdateRequest {
|
||||||
@ -31,30 +32,25 @@ fn forcepush_allowed() {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let commit_id = controller
|
let commit_id =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||||
.push_virtual_branch(project, branch_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// amend another hunk
|
// amend another hunk
|
||||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||||
controller
|
gitbutler_branch_actions::amend(project, branch_id, commit_id, &to_amend).unwrap();
|
||||||
.amend(project, branch_id, commit_id, &to_amend)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -72,45 +68,42 @@ fn forcepush_forbidden() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::update_virtual_branch(
|
||||||
.update_virtual_branch(
|
project,
|
||||||
project,
|
BranchUpdateRequest {
|
||||||
BranchUpdateRequest {
|
id: branch_id,
|
||||||
id: branch_id,
|
allow_rebasing: Some(false),
|
||||||
allow_rebasing: Some(false),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let commit_oid = controller
|
let commit_oid =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||||
.push_virtual_branch(project, branch_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend)
|
||||||
.amend(project, branch_id, commit_oid, &to_amend)
|
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"force-push is not allowed"
|
"force-push is not allowed"
|
||||||
@ -123,26 +116,26 @@ fn non_locked_hunk() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let commit_oid = controller
|
let commit_oid =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -156,12 +149,9 @@ fn non_locked_hunk() {
|
|||||||
// amend another hunk
|
// amend another hunk
|
||||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||||
controller
|
gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend).unwrap();
|
||||||
.amend(project, branch_id, commit_oid, &to_amend)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -178,26 +168,26 @@ fn locked_hunk() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let commit_oid = controller
|
let commit_oid =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -215,12 +205,9 @@ fn locked_hunk() {
|
|||||||
// amend another hunk
|
// amend another hunk
|
||||||
fs::write(repository.path().join("file.txt"), "more content").unwrap();
|
fs::write(repository.path().join("file.txt"), "more content").unwrap();
|
||||||
let to_amend: BranchOwnershipClaims = "file.txt:1-2".parse().unwrap();
|
let to_amend: BranchOwnershipClaims = "file.txt:1-2".parse().unwrap();
|
||||||
controller
|
gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend).unwrap();
|
||||||
.amend(project, branch_id, commit_oid, &to_amend)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -242,26 +229,26 @@ fn non_existing_ownership() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let commit_oid = controller
|
let commit_oid =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -275,8 +262,7 @@ fn non_existing_ownership() {
|
|||||||
// amend non existing hunk
|
// amend non existing hunk
|
||||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::amend(project, branch_id, commit_oid, &to_amend)
|
||||||
.amend(project, branch_id, commit_oid, &to_amend)
|
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"target ownership not found"
|
"target ownership not found"
|
||||||
|
@ -8,7 +8,6 @@ fn rebase_commit() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -23,22 +22,25 @@ fn rebase_commit() {
|
|||||||
repository.reset_hard(Some(first_commit_oid));
|
repository.reset_hard(Some(first_commit_oid));
|
||||||
}
|
}
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut branch1_id = {
|
let mut branch1_id = {
|
||||||
// create a branch with some commited work
|
// create a branch with some commited work
|
||||||
let branch1_id = controller
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
project,
|
||||||
.unwrap();
|
&BranchCreateRequest::default(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
fs::write(repository.path().join("another_file.txt"), "virtual").unwrap();
|
fs::write(repository.path().join("another_file.txt"), "virtual").unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch1_id, "virtual commit", None, false)
|
||||||
.create_commit(project, branch1_id, "virtual commit", None, false)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert!(branches[0].active);
|
assert!(branches[0].active);
|
||||||
@ -50,9 +52,8 @@ fn rebase_commit() {
|
|||||||
|
|
||||||
let unapplied_branch = {
|
let unapplied_branch = {
|
||||||
// unapply first vbranch
|
// unapply first vbranch
|
||||||
let unapplied_branch = controller
|
let unapplied_branch =
|
||||||
.convert_to_real_branch(project, branch1_id)
|
gitbutler_branch_actions::convert_to_real_branch(project, branch1_id).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
fs::read_to_string(repository.path().join("another_file.txt")).unwrap(),
|
fs::read_to_string(repository.path().join("another_file.txt")).unwrap(),
|
||||||
@ -63,7 +64,7 @@ fn rebase_commit() {
|
|||||||
"one"
|
"one"
|
||||||
);
|
);
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 0);
|
assert_eq!(branches.len(), 0);
|
||||||
|
|
||||||
Refname::from_str(&unapplied_branch).unwrap()
|
Refname::from_str(&unapplied_branch).unwrap()
|
||||||
@ -71,10 +72,10 @@ fn rebase_commit() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// fetch remote
|
// fetch remote
|
||||||
controller.update_base_branch(project).unwrap();
|
gitbutler_branch_actions::update_base_branch(project).unwrap();
|
||||||
|
|
||||||
// branch is stil unapplied
|
// branch is stil unapplied
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 0);
|
assert_eq!(branches.len(), 0);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -89,12 +90,15 @@ fn rebase_commit() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// apply first vbranch again
|
// apply first vbranch again
|
||||||
branch1_id = controller
|
branch1_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||||
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
project,
|
||||||
.unwrap();
|
&unapplied_branch,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// it should be rebased
|
// it should be rebased
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].files.len(), 0);
|
assert_eq!(branches[0].files.len(), 0);
|
||||||
@ -119,7 +123,6 @@ fn rebase_work() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -132,18 +135,22 @@ fn rebase_work() {
|
|||||||
repository.reset_hard(Some(first_commit_oid));
|
repository.reset_hard(Some(first_commit_oid));
|
||||||
}
|
}
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut branch1_id = {
|
let mut branch1_id = {
|
||||||
// make a branch with some work
|
// make a branch with some work
|
||||||
let branch1_id = controller
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
project,
|
||||||
.unwrap();
|
&BranchCreateRequest::default(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
fs::write(repository.path().join("another_file.txt"), "").unwrap();
|
fs::write(repository.path().join("another_file.txt"), "").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert!(branches[0].active);
|
assert!(branches[0].active);
|
||||||
@ -155,11 +162,10 @@ fn rebase_work() {
|
|||||||
|
|
||||||
let unapplied_branch = {
|
let unapplied_branch = {
|
||||||
// unapply first vbranch
|
// unapply first vbranch
|
||||||
let unapplied_branch = controller
|
let unapplied_branch =
|
||||||
.convert_to_real_branch(project, branch1_id)
|
gitbutler_branch_actions::convert_to_real_branch(project, branch1_id).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 0);
|
assert_eq!(branches.len(), 0);
|
||||||
|
|
||||||
assert!(!repository.path().join("another_file.txt").exists());
|
assert!(!repository.path().join("another_file.txt").exists());
|
||||||
@ -170,10 +176,10 @@ fn rebase_work() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// fetch remote
|
// fetch remote
|
||||||
controller.update_base_branch(project).unwrap();
|
gitbutler_branch_actions::update_base_branch(project).unwrap();
|
||||||
|
|
||||||
// first branch is stil unapplied
|
// first branch is stil unapplied
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 0);
|
assert_eq!(branches.len(), 0);
|
||||||
|
|
||||||
assert!(!repository.path().join("another_file.txt").exists());
|
assert!(!repository.path().join("another_file.txt").exists());
|
||||||
@ -182,12 +188,15 @@ fn rebase_work() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// apply first vbranch again
|
// apply first vbranch again
|
||||||
branch1_id = controller
|
branch1_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||||
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
project,
|
||||||
.unwrap();
|
&unapplied_branch,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// workdir should be rebased, and work should be restored
|
// workdir should be rebased, and work should be restored
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
// TODO: Should be 1
|
// TODO: Should be 1
|
||||||
|
@ -4,27 +4,26 @@ use super::*;
|
|||||||
fn unapply_with_data() {
|
fn unapply_with_data() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::convert_to_real_branch(project, branches[0].id).unwrap();
|
||||||
.convert_to_real_branch(project, branches[0].id)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert!(!repository.path().join("file.txt").exists());
|
assert!(!repository.path().join("file.txt").exists());
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 0);
|
assert_eq!(branches.len(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +31,6 @@ fn unapply_with_data() {
|
|||||||
fn conflicting() {
|
fn conflicting() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
@ -47,16 +45,18 @@ fn conflicting() {
|
|||||||
repository.reset_hard(Some(first_commit_oid));
|
repository.reset_hard(Some(first_commit_oid));
|
||||||
}
|
}
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let unapplied_branch = {
|
let unapplied_branch = {
|
||||||
// make a conflicting branch, and stash it
|
// make a conflicting branch, and stash it
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
let branch = &branches[0];
|
let branch = &branches[0];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -70,16 +70,15 @@ fn conflicting() {
|
|||||||
"@@ -1 +1 @@\n-first\n\\ No newline at end of file\n+conflict\n\\ No newline at end of file\n"
|
"@@ -1 +1 @@\n-first\n\\ No newline at end of file\n+conflict\n\\ No newline at end of file\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
let unapplied_branch = controller
|
let unapplied_branch =
|
||||||
.convert_to_real_branch(project, branch.id)
|
gitbutler_branch_actions::convert_to_real_branch(project, branch.id).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Refname::from_str(&unapplied_branch).unwrap()
|
Refname::from_str(&unapplied_branch).unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
// update base branch, causing conflict
|
// update base branch, causing conflict
|
||||||
controller.update_base_branch(project).unwrap();
|
gitbutler_branch_actions::update_base_branch(project).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
||||||
@ -89,9 +88,12 @@ fn conflicting() {
|
|||||||
|
|
||||||
let branch_id = {
|
let branch_id = {
|
||||||
// apply branch, it should conflict
|
// apply branch, it should conflict
|
||||||
let branch_id = controller
|
let branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||||
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
project,
|
||||||
.unwrap();
|
&unapplied_branch,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
||||||
@ -101,7 +103,7 @@ fn conflicting() {
|
|||||||
let vb_state = VirtualBranchesHandle::new(project.gb_dir());
|
let vb_state = VirtualBranchesHandle::new(project.gb_dir());
|
||||||
let ctx = CommandContext::open(project).unwrap();
|
let ctx = CommandContext::open(project).unwrap();
|
||||||
update_workspace_commit(&vb_state, &ctx).unwrap();
|
update_workspace_commit(&vb_state, &ctx).unwrap();
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
|
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
let branch = &branches[0];
|
let branch = &branches[0];
|
||||||
@ -116,9 +118,7 @@ fn conflicting() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// Converting the branch to a real branch should put us back in an unconflicted state
|
// Converting the branch to a real branch should put us back in an unconflicted state
|
||||||
controller
|
gitbutler_branch_actions::convert_to_real_branch(project, branch_id).unwrap();
|
||||||
.convert_to_real_branch(project, branch_id)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
std::fs::read_to_string(repository.path().join("file.txt")).unwrap(),
|
||||||
@ -129,27 +129,22 @@ fn conflicting() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn delete_if_empty() {
|
fn delete_if_empty() {
|
||||||
let Test {
|
let Test { project, .. } = &Test::default();
|
||||||
|
|
||||||
|
gitbutler_branch_actions::set_base_branch(
|
||||||
project,
|
project,
|
||||||
controller,
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
..
|
)
|
||||||
} = &Test::default();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::convert_to_real_branch(project, branches[0].id).unwrap();
|
||||||
.convert_to_real_branch(project, branches[0].id)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 0);
|
assert_eq!(branches.len(), 0);
|
||||||
}
|
}
|
||||||
|
@ -8,40 +8,38 @@ use super::*;
|
|||||||
fn should_lock_updated_hunks() {
|
fn should_lock_updated_hunks() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
// by default, hunks are not locked
|
// by default, hunks are not locked
|
||||||
repository.write_file("file.txt", &["content".to_string()]);
|
repository.write_file("file.txt", &["content".to_string()]);
|
||||||
|
|
||||||
let branch = get_virtual_branch(controller, project, branch_id);
|
let branch = get_virtual_branch(project, branch_id);
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
assert_eq!(branch.files[0].path.display().to_string(), "file.txt");
|
assert_eq!(branch.files[0].path.display().to_string(), "file.txt");
|
||||||
assert_eq!(branch.files[0].hunks.len(), 1);
|
assert_eq!(branch.files[0].hunks.len(), 1);
|
||||||
assert!(!branch.files[0].hunks[0].locked);
|
assert!(!branch.files[0].hunks[0].locked);
|
||||||
}
|
}
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "test", None, false).unwrap();
|
||||||
.create_commit(project, branch_id, "test", None, false)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// change in the committed hunks leads to hunk locking
|
// change in the committed hunks leads to hunk locking
|
||||||
repository.write_file("file.txt", &["updated content".to_string()]);
|
repository.write_file("file.txt", &["updated content".to_string()]);
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -58,7 +56,6 @@ fn should_lock_updated_hunks() {
|
|||||||
fn should_reset_into_same_branch() {
|
fn should_reset_into_same_branch() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
@ -66,51 +63,54 @@ fn should_reset_into_same_branch() {
|
|||||||
let mut lines = repository.gen_file("file.txt", 7);
|
let mut lines = repository.gen_file("file.txt", 7);
|
||||||
commit_and_push_initial(repository);
|
commit_and_push_initial(repository);
|
||||||
|
|
||||||
let base_branch = controller
|
let base_branch = gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
let branch_2_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
project,
|
||||||
.unwrap();
|
&BranchCreateRequest {
|
||||||
|
selected_for_changes: Some(true),
|
||||||
let branch_2_id = controller
|
..Default::default()
|
||||||
.create_virtual_branch(
|
},
|
||||||
project,
|
)
|
||||||
&BranchCreateRequest {
|
.unwrap();
|
||||||
selected_for_changes: Some(true),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
lines[0] = "change 1".to_string();
|
lines[0] = "change 1".to_string();
|
||||||
repository.write_file("file.txt", &lines);
|
repository.write_file("file.txt", &lines);
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_commit(
|
||||||
.create_commit(project, branch_2_id, "commit to branch 2", None, false)
|
project,
|
||||||
.unwrap();
|
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);
|
assert_eq!(files.len(), 0);
|
||||||
|
|
||||||
// Set target to branch 1 and verify the file resets into branch 2.
|
// Set target to branch 1 and verify the file resets into branch 2.
|
||||||
controller
|
gitbutler_branch_actions::update_virtual_branch(
|
||||||
.update_virtual_branch(
|
project,
|
||||||
project,
|
BranchUpdateRequest {
|
||||||
BranchUpdateRequest {
|
id: branch_2_id,
|
||||||
id: branch_2_id,
|
selected_for_changes: Some(true),
|
||||||
selected_for_changes: Some(true),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
|
|
||||||
|
gitbutler_branch_actions::reset_virtual_branch(project, branch_2_id, base_branch.base_sha)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
let files = get_virtual_branch(project, branch_2_id).files;
|
||||||
.reset_virtual_branch(project, branch_2_id, base_branch.base_sha)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let files = get_virtual_branch(controller, project, branch_2_id).files;
|
|
||||||
assert_eq!(files.len(), 1);
|
assert_eq!(files.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,13 +119,8 @@ fn commit_and_push_initial(repository: &TestProject) {
|
|||||||
repository.push();
|
repository.push();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_virtual_branch(
|
fn get_virtual_branch(project: &Project, branch_id: Id<Branch>) -> VirtualBranch {
|
||||||
controller: &VirtualBranchActions,
|
gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
project: &Project,
|
|
||||||
branch_id: Id<Branch>,
|
|
||||||
) -> VirtualBranch {
|
|
||||||
controller
|
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -8,31 +8,29 @@ fn integration() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_name = {
|
let branch_name = {
|
||||||
// make a remote branch
|
// make a remote branch
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
project,
|
||||||
.unwrap();
|
&BranchCreateRequest::default(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "first\n").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "first\n").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "first", None, false).unwrap();
|
||||||
.create_commit(project, branch_id, "first", None, false)
|
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||||
.unwrap();
|
|
||||||
controller
|
|
||||||
.push_virtual_branch(project, branch_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -41,25 +39,21 @@ fn integration() {
|
|||||||
|
|
||||||
let name = branch.upstream.unwrap().name;
|
let name = branch.upstream.unwrap().name;
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::delete_virtual_branch(project, branch_id).unwrap();
|
||||||
.delete_virtual_branch(project, branch_id)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
name
|
name
|
||||||
};
|
};
|
||||||
|
|
||||||
// checkout a existing remote branch
|
// checkout a existing remote branch
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch_from_branch(project, &branch_name, None)
|
gitbutler_branch_actions::create_virtual_branch_from_branch(project, &branch_name, None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
// add a commit
|
// add a commit
|
||||||
std::fs::write(repository.path().join("file.txt"), "first\nsecond").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "first\nsecond").unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "second", None, false).unwrap();
|
||||||
.create_commit(project, branch_id, "second", None, false)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -73,12 +67,9 @@ fn integration() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// merge branch into master
|
// merge branch into master
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||||
.push_virtual_branch(project, branch_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -95,10 +86,9 @@ fn integration() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// should mark commits as integrated
|
// should mark commits as integrated
|
||||||
controller.fetch_from_remotes(project, None).unwrap();
|
gitbutler_branch_actions::fetch_from_remotes(project, None).unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -117,7 +107,6 @@ fn no_conflicts() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -131,22 +120,23 @@ fn no_conflicts() {
|
|||||||
repository.checkout(&"refs/heads/master".parse().unwrap());
|
repository.checkout(&"refs/heads/master".parse().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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());
|
assert!(branches.is_empty());
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||||
.create_virtual_branch_from_branch(
|
project,
|
||||||
project,
|
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
None,
|
||||||
None,
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch_id);
|
assert_eq!(branches[0].id, branch_id);
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
@ -158,7 +148,6 @@ fn conflicts_with_uncommited() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -172,29 +161,29 @@ fn conflicts_with_uncommited() {
|
|||||||
repository.checkout(&"refs/heads/master".parse().unwrap());
|
repository.checkout(&"refs/heads/master".parse().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// create a local branch that conflicts with remote
|
// create a local branch that conflicts with remote
|
||||||
{
|
{
|
||||||
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
// branch should be created unapplied, because of the conflict
|
// branch should be created unapplied, because of the conflict
|
||||||
|
|
||||||
let new_branch_id = controller
|
let new_branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||||
.create_virtual_branch_from_branch(
|
project,
|
||||||
project,
|
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
None,
|
||||||
None,
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
let new_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
let new_branch = controller
|
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -210,7 +199,6 @@ fn conflicts_with_commited() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -224,33 +212,32 @@ fn conflicts_with_commited() {
|
|||||||
repository.checkout(&"refs/heads/master".parse().unwrap());
|
repository.checkout(&"refs/heads/master".parse().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// create a local branch that conflicts with remote
|
// create a local branch that conflicts with remote
|
||||||
{
|
{
|
||||||
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branches[0].id, "hej", None, false)
|
||||||
.create_commit(project, branches[0].id, "hej", None, false)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
};
|
};
|
||||||
|
|
||||||
// branch should be created unapplied, because of the conflict
|
// branch should be created unapplied, because of the conflict
|
||||||
|
|
||||||
let new_branch_id = controller
|
let new_branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||||
.create_virtual_branch_from_branch(
|
project,
|
||||||
project,
|
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
None,
|
||||||
None,
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
let new_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
let new_branch = controller
|
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -263,54 +250,48 @@ fn conflicts_with_commited() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_default_target() {
|
fn from_default_target() {
|
||||||
let Test {
|
let Test { project, .. } = &Test::default();
|
||||||
project,
|
|
||||||
controller,
|
|
||||||
..
|
|
||||||
} = &Test::default();
|
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// branch should be created unapplied, because of the conflict
|
// branch should be created unapplied, because of the conflict
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||||
.create_virtual_branch_from_branch(
|
project,
|
||||||
project,
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
&"refs/remotes/origin/master".parse().unwrap(),
|
None
|
||||||
None
|
)
|
||||||
)
|
.unwrap_err()
|
||||||
.unwrap_err()
|
.to_string(),
|
||||||
.to_string(),
|
|
||||||
"cannot create a branch from default target"
|
"cannot create a branch from default target"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_non_existent_branch() {
|
fn from_non_existent_branch() {
|
||||||
let Test {
|
let Test { project, .. } = &Test::default();
|
||||||
project,
|
|
||||||
controller,
|
|
||||||
..
|
|
||||||
} = &Test::default();
|
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// branch should be created unapplied, because of the conflict
|
// branch should be created unapplied, because of the conflict
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||||
.create_virtual_branch_from_branch(
|
project,
|
||||||
project,
|
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
None
|
||||||
None
|
)
|
||||||
)
|
.unwrap_err()
|
||||||
.unwrap_err()
|
.to_string(),
|
||||||
.to_string(),
|
|
||||||
"branch refs/remotes/origin/branch was not found"
|
"branch refs/remotes/origin/branch was not found"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -320,7 +301,6 @@ fn from_state_remote_branch() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -339,19 +319,20 @@ fn from_state_remote_branch() {
|
|||||||
repository.push();
|
repository.push();
|
||||||
}
|
}
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||||
.create_virtual_branch_from_branch(
|
project,
|
||||||
project,
|
&"refs/remotes/origin/branch".parse().unwrap(),
|
||||||
&"refs/remotes/origin/branch".parse().unwrap(),
|
None,
|
||||||
None,
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch_id);
|
assert_eq!(branches[0].id, branch_id);
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
|
@ -6,25 +6,24 @@ use super::*;
|
|||||||
fn should_unapply_diff() {
|
fn should_unapply_diff() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// write some
|
// write some
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::delete_virtual_branch(project, branches[0].id).unwrap();
|
||||||
.delete_virtual_branch(project, branches[0].id)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 0);
|
assert_eq!(branches.len(), 0);
|
||||||
assert!(!repository.path().join("file.txt").exists());
|
assert!(!repository.path().join("file.txt").exists());
|
||||||
|
|
||||||
@ -40,28 +39,28 @@ fn should_unapply_diff() {
|
|||||||
fn should_remove_reference() {
|
fn should_remove_reference() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let id = controller
|
let id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
name: Some("name".to_string()),
|
||||||
name: Some("name".to_string()),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
controller.delete_virtual_branch(project, id).unwrap();
|
gitbutler_branch_actions::delete_virtual_branch(project, id).unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 0);
|
assert_eq!(branches.len(), 0);
|
||||||
|
|
||||||
let refnames = repository
|
let refnames = repository
|
||||||
|
@ -7,33 +7,33 @@ fn twice() {
|
|||||||
|
|
||||||
let test_project = TestProject::default();
|
let test_project = TestProject::default();
|
||||||
|
|
||||||
let controller = VirtualBranchActions {};
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let project = projects
|
let project = projects
|
||||||
.add(test_project.path())
|
.add(test_project.path())
|
||||||
.expect("failed to add project");
|
.expect("failed to add project");
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(&project, &"refs/remotes/origin/master".parse().unwrap())
|
&project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
assert!(controller
|
)
|
||||||
.list_virtual_branches(&project)
|
.unwrap();
|
||||||
|
assert!(gitbutler_branch_actions::list_virtual_branches(&project)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.is_empty());
|
.is_empty());
|
||||||
projects.delete(project.id).unwrap();
|
projects.delete(project.id).unwrap();
|
||||||
controller.list_virtual_branches(&project).unwrap_err();
|
gitbutler_branch_actions::list_virtual_branches(&project).unwrap_err();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let project = projects.add(test_project.path()).unwrap();
|
let project = projects.add(test_project.path()).unwrap();
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(&project, &"refs/remotes/origin/master".parse().unwrap())
|
&project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// even though project is on gitbutler/workspace, we should not import it
|
// even though project is on gitbutler/workspace, we should not import it
|
||||||
assert!(controller
|
assert!(gitbutler_branch_actions::list_virtual_branches(&project)
|
||||||
.list_virtual_branches(&project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.is_empty());
|
.is_empty());
|
||||||
@ -47,7 +47,6 @@ fn dirty_non_target() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -55,11 +54,13 @@ fn dirty_non_target() {
|
|||||||
|
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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.len(), 1);
|
||||||
assert_eq!(branches[0].files.len(), 1);
|
assert_eq!(branches[0].files.len(), 1);
|
||||||
assert_eq!(branches[0].files[0].hunks.len(), 1);
|
assert_eq!(branches[0].files[0].hunks.len(), 1);
|
||||||
@ -74,17 +75,18 @@ fn dirty_target() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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.len(), 1);
|
||||||
assert_eq!(branches[0].files.len(), 1);
|
assert_eq!(branches[0].files.len(), 1);
|
||||||
assert_eq!(branches[0].files[0].hunks.len(), 1);
|
assert_eq!(branches[0].files[0].hunks.len(), 1);
|
||||||
@ -97,7 +99,6 @@ fn commit_on_non_target_local() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -105,11 +106,13 @@ fn commit_on_non_target_local() {
|
|||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
repository.commit_all("commit on target");
|
repository.commit_all("commit on target");
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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.len(), 1);
|
||||||
assert!(branches[0].files.is_empty());
|
assert!(branches[0].files.is_empty());
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
@ -122,7 +125,6 @@ fn commit_on_non_target_remote() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -131,11 +133,13 @@ fn commit_on_non_target_remote() {
|
|||||||
repository.commit_all("commit on target");
|
repository.commit_all("commit on target");
|
||||||
repository.push_branch(&"refs/heads/some-feature".parse().unwrap());
|
repository.push_branch(&"refs/heads/some-feature".parse().unwrap());
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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.len(), 1);
|
||||||
assert!(branches[0].files.is_empty());
|
assert!(branches[0].files.is_empty());
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
@ -148,18 +152,19 @@ fn commit_on_target() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
repository.commit_all("commit on target");
|
repository.commit_all("commit on target");
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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.len(), 1);
|
||||||
assert!(branches[0].files.is_empty());
|
assert!(branches[0].files.is_empty());
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
@ -172,7 +177,6 @@ fn submodule() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -181,11 +185,13 @@ fn submodule() {
|
|||||||
test_project.path().display().to_string().parse().unwrap();
|
test_project.path().display().to_string().parse().unwrap();
|
||||||
repository.add_submodule(&submodule_url, path::Path::new("submodule"));
|
repository.add_submodule(&submodule_url, path::Path::new("submodule"));
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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.len(), 1);
|
||||||
assert_eq!(branches[0].files.len(), 1);
|
assert_eq!(branches[0].files.len(), 1);
|
||||||
assert_eq!(branches[0].files[0].hunks.len(), 1);
|
assert_eq!(branches[0].files[0].hunks.len(), 1);
|
||||||
|
@ -7,43 +7,41 @@ fn insert_blank_commit_down() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let _commit1_id = controller
|
let _commit1_id =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||||
let commit2_id = controller
|
let commit2_id =
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
||||||
let _commit3_id = controller
|
let _commit3_id =
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::insert_blank_commit(project, branch_id, commit2_id, 1).unwrap();
|
||||||
.insert_blank_commit(project, branch_id, commit2_id, 1)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -72,43 +70,41 @@ fn insert_blank_commit_up() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let _commit1_id = controller
|
let _commit1_id =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||||
let commit2_id = controller
|
let commit2_id =
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
||||||
let _commit3_id = controller
|
let _commit3_id =
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::insert_blank_commit(project, branch_id, commit2_id, -1).unwrap();
|
||||||
.insert_blank_commit(project, branch_id, commit2_id, -1)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use std::{fs, path, path::PathBuf, str::FromStr};
|
use std::{fs, path, path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
use gitbutler_branch::{BranchCreateRequest, VirtualBranchesHandle};
|
use gitbutler_branch::{BranchCreateRequest, VirtualBranchesHandle};
|
||||||
|
use gitbutler_branch_actions::update_workspace_commit;
|
||||||
use gitbutler_branch_actions::GITBUTLER_WORKSPACE_COMMIT_TITLE;
|
use gitbutler_branch_actions::GITBUTLER_WORKSPACE_COMMIT_TITLE;
|
||||||
use gitbutler_branch_actions::{update_workspace_commit, VirtualBranchActions};
|
|
||||||
use gitbutler_command_context::CommandContext;
|
use gitbutler_command_context::CommandContext;
|
||||||
use gitbutler_error::error::Marker;
|
use gitbutler_error::error::Marker;
|
||||||
use gitbutler_project::{self as projects, Project, ProjectId};
|
use gitbutler_project::{self as projects, Project, ProjectId};
|
||||||
@ -15,7 +15,6 @@ struct Test {
|
|||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
project: Project,
|
project: Project,
|
||||||
projects: projects::Controller,
|
projects: projects::Controller,
|
||||||
controller: VirtualBranchActions,
|
|
||||||
data_dir: Option<TempDir>,
|
data_dir: Option<TempDir>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +39,6 @@ impl Default for Test {
|
|||||||
Self {
|
Self {
|
||||||
repository: test_project,
|
repository: test_project,
|
||||||
project_id: project.id,
|
project_id: project.id,
|
||||||
controller: VirtualBranchActions {},
|
|
||||||
projects,
|
projects,
|
||||||
project,
|
project,
|
||||||
data_dir: Some(data_dir),
|
data_dir: Some(data_dir),
|
||||||
@ -89,7 +87,6 @@ fn resolve_conflict_flow() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -105,18 +102,22 @@ fn resolve_conflict_flow() {
|
|||||||
repository.reset_hard(Some(first_commit_oid));
|
repository.reset_hard(Some(first_commit_oid));
|
||||||
}
|
}
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
// make a branch that conflicts with the remote branch, but doesn't know about it yet
|
// make a branch that conflicts with the remote branch, but doesn't know about it yet
|
||||||
let branch1_id = controller
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
project,
|
||||||
.unwrap();
|
&BranchCreateRequest::default(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
fs::write(repository.path().join("file.txt"), "conflict").unwrap();
|
fs::write(repository.path().join("file.txt"), "conflict").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert!(branches[0].active);
|
assert!(branches[0].active);
|
||||||
@ -124,11 +125,11 @@ fn resolve_conflict_flow() {
|
|||||||
|
|
||||||
let unapplied_branch = {
|
let unapplied_branch = {
|
||||||
// fetch remote. There is now a conflict, so the branch will be unapplied
|
// fetch remote. There is now a conflict, so the branch will be unapplied
|
||||||
let unapplied_branches = controller.update_base_branch(project).unwrap();
|
let unapplied_branches = gitbutler_branch_actions::update_base_branch(project).unwrap();
|
||||||
assert_eq!(unapplied_branches.len(), 1);
|
assert_eq!(unapplied_branches.len(), 1);
|
||||||
|
|
||||||
// there is a conflict now, so the branch should be inactive
|
// there is a conflict now, so the branch should be inactive
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 0);
|
assert_eq!(branches.len(), 0);
|
||||||
|
|
||||||
Refname::from_str(&unapplied_branches[0]).unwrap()
|
Refname::from_str(&unapplied_branches[0]).unwrap()
|
||||||
@ -136,14 +137,17 @@ fn resolve_conflict_flow() {
|
|||||||
|
|
||||||
let branch1_id = {
|
let branch1_id = {
|
||||||
// when we apply conflicted branch, it has conflict
|
// when we apply conflicted branch, it has conflict
|
||||||
let branch1_id = controller
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch_from_branch(
|
||||||
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
project,
|
||||||
.unwrap();
|
&unapplied_branch,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let vb_state = VirtualBranchesHandle::new(project.gb_dir());
|
let vb_state = VirtualBranchesHandle::new(project.gb_dir());
|
||||||
let ctx = CommandContext::open(project).unwrap();
|
let ctx = CommandContext::open(project).unwrap();
|
||||||
update_workspace_commit(&vb_state, &ctx).unwrap();
|
update_workspace_commit(&vb_state, &ctx).unwrap();
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert!(branches[0].active);
|
assert!(branches[0].active);
|
||||||
assert!(branches[0].conflicted);
|
assert!(branches[0].conflicted);
|
||||||
@ -161,10 +165,15 @@ fn resolve_conflict_flow() {
|
|||||||
{
|
{
|
||||||
// can't commit conflicts
|
// can't commit conflicts
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
controller
|
gitbutler_branch_actions::create_commit(
|
||||||
.create_commit(project, branch1_id, "commit conflicts", None, false)
|
project,
|
||||||
.unwrap_err()
|
branch1_id,
|
||||||
.downcast_ref(),
|
"commit conflicts",
|
||||||
|
None,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
.unwrap_err()
|
||||||
|
.downcast_ref(),
|
||||||
Some(Marker::ProjectConflict)
|
Some(Marker::ProjectConflict)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -172,15 +181,15 @@ fn resolve_conflict_flow() {
|
|||||||
{
|
{
|
||||||
// fixing the conflict removes conflicted mark
|
// fixing the conflict removes conflicted mark
|
||||||
fs::write(repository.path().join("file.txt"), "resolved").unwrap();
|
fs::write(repository.path().join("file.txt"), "resolved").unwrap();
|
||||||
controller.list_virtual_branches(project).unwrap();
|
gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
let commit_oid = controller
|
let commit_oid =
|
||||||
.create_commit(project, branch1_id, "resolution", None, false)
|
gitbutler_branch_actions::create_commit(project, branch1_id, "resolution", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let commit = repository.find_commit(commit_oid).unwrap();
|
let commit = repository.find_commit(commit_oid).unwrap();
|
||||||
assert_eq!(commit.parent_count(), 2);
|
assert_eq!(commit.parent_count(), 2);
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert!(branches[0].active);
|
assert!(branches[0].active);
|
||||||
|
@ -8,41 +8,42 @@ fn move_file_down() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let commit1_id = controller
|
let commit1_id =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let commit1 = repository.find_commit(commit1_id).unwrap();
|
let commit1 = repository.find_commit(commit1_id).unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||||
let commit2_id = controller
|
let commit2_id =
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let commit2 = repository.find_commit(commit2_id).unwrap();
|
let commit2 = repository.find_commit(commit2_id).unwrap();
|
||||||
|
|
||||||
// amend another hunk
|
// amend another hunk
|
||||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||||
controller
|
gitbutler_branch_actions::move_commit_file(
|
||||||
.move_commit_file(project, branch_id, commit2_id, commit1_id, &to_amend)
|
project, branch_id, commit2_id, commit1_id, &to_amend,
|
||||||
.unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -66,39 +67,40 @@ fn move_file_up() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||||
let commit1_id = controller
|
let commit1_id =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||||
let commit2_id = controller
|
let commit2_id =
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// amend another hunk
|
// amend another hunk
|
||||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
let to_amend: BranchOwnershipClaims = "file2.txt:1-2".parse().unwrap();
|
||||||
controller
|
gitbutler_branch_actions::move_commit_file(
|
||||||
.move_commit_file(project, branch_id, commit1_id, commit2_id, &to_amend)
|
project, branch_id, commit1_id, commit2_id, &to_amend,
|
||||||
.unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -119,32 +121,28 @@ fn move_file_up_overlapping_hunks() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project_id,
|
project_id,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
|
||||||
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id = gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
|
||||||
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create bottom commit
|
// create bottom commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let _commit1_id = controller
|
let _commit1_id = gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create middle commit one
|
// create middle commit one
|
||||||
fs::write(repository.path().join("file2.txt"), "content2\ncontent2a\n").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2\ncontent2a\n").unwrap();
|
||||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||||
let commit2_id = controller
|
let commit2_id = gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
|
||||||
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -155,27 +153,23 @@ fn move_file_up_overlapping_hunks() {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
||||||
let commit3_id = controller
|
let commit3_id = gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
|
||||||
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create top commit
|
// create top commit
|
||||||
fs::write(repository.path().join("file5.txt"), "content5").unwrap();
|
fs::write(repository.path().join("file5.txt"), "content5").unwrap();
|
||||||
let _commit4_id = controller
|
let _commit4_id = gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
|
||||||
.create_commit(project, branch_id, "commit four", None, false)
|
|
||||||
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// move one line from middle commit two up to middle commit one
|
// move one line from middle commit two up to middle commit one
|
||||||
let to_amend: BranchOwnershipClaims = "file2.txt:1-6".parse().unwrap();
|
let to_amend: BranchOwnershipClaims = "file2.txt:1-6".parse().unwrap();
|
||||||
controller
|
gitbutler_branch_actions::move_commit_file(project, branch_id, commit2_id, commit3_id, &to_amend)
|
||||||
.move_commit_file(project, branch_id, commit2_id, commit3_id, &to_amend)
|
|
||||||
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
|
@ -7,43 +7,40 @@ fn no_diffs() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
let source_branch_id = branches[0].id;
|
let source_branch_id = branches[0].id;
|
||||||
|
|
||||||
let commit_oid = controller
|
let commit_oid =
|
||||||
.create_commit(project, source_branch_id, "commit", None, false)
|
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let target_branch_id = controller
|
let target_branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid).unwrap();
|
||||||
.move_commit(project, target_branch_id, commit_oid)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let destination_branch = controller
|
let destination_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|b| b.id == target_branch_id)
|
.find(|b| b.id == target_branch_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let source_branch = controller
|
let source_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -61,24 +58,25 @@ fn diffs_on_source_branch() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
let source_branch_id = branches[0].id;
|
let source_branch_id = branches[0].id;
|
||||||
|
|
||||||
let commit_oid = controller
|
let commit_oid =
|
||||||
.create_commit(project, source_branch_id, "commit", None, false)
|
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
repository.path().join("another file.txt"),
|
repository.path().join("another file.txt"),
|
||||||
@ -86,24 +84,20 @@ fn diffs_on_source_branch() {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let target_branch_id = controller
|
let target_branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid).unwrap();
|
||||||
.move_commit(project, target_branch_id, commit_oid)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let destination_branch = controller
|
let destination_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|b| b.id == target_branch_id)
|
.find(|b| b.id == target_branch_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let source_branch = controller
|
let source_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -121,34 +115,34 @@ fn diffs_on_target_branch() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
let source_branch_id = branches[0].id;
|
let source_branch_id = branches[0].id;
|
||||||
|
|
||||||
let commit_oid = controller
|
let commit_oid =
|
||||||
.create_commit(project, source_branch_id, "commit", None, false)
|
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let target_branch_id = controller
|
let target_branch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
selected_for_changes: Some(true),
|
||||||
selected_for_changes: Some(true),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
repository.path().join("another file.txt"),
|
repository.path().join("another file.txt"),
|
||||||
@ -156,20 +150,16 @@ fn diffs_on_target_branch() {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid).unwrap();
|
||||||
.move_commit(project, target_branch_id, commit_oid)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let destination_branch = controller
|
let destination_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|b| b.id == target_branch_id)
|
.find(|b| b.id == target_branch_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let source_branch = controller
|
let source_branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -187,34 +177,34 @@ fn locked_hunks_on_source_branch() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
let source_branch_id = branches[0].id;
|
let source_branch_id = branches[0].id;
|
||||||
|
|
||||||
let commit_oid = controller
|
let commit_oid =
|
||||||
.create_commit(project, source_branch_id, "commit", None, false)
|
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "locked content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "locked content").unwrap();
|
||||||
|
|
||||||
let target_branch_id = controller
|
let target_branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::move_commit(project, target_branch_id, commit_oid)
|
||||||
.move_commit(project, target_branch_id, commit_oid)
|
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"the source branch contains hunks locked to the target commit"
|
"the source branch contains hunks locked to the target commit"
|
||||||
@ -226,39 +216,38 @@ fn no_commit() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
let source_branch_id = branches[0].id;
|
let source_branch_id = branches[0].id;
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||||
.create_commit(project, source_branch_id, "commit", None, false)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let target_branch_id = controller
|
let target_branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let commit_id_hex = "a99c95cca7a60f1a2180c2f86fb18af97333c192";
|
let commit_id_hex = "a99c95cca7a60f1a2180c2f86fb18af97333c192";
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::move_commit(
|
||||||
.move_commit(
|
project,
|
||||||
project,
|
target_branch_id,
|
||||||
target_branch_id,
|
git2::Oid::from_str(commit_id_hex).unwrap()
|
||||||
git2::Oid::from_str(commit_id_hex).unwrap()
|
)
|
||||||
)
|
.unwrap_err()
|
||||||
.unwrap_err()
|
.to_string(),
|
||||||
.to_string(),
|
|
||||||
format!("commit {commit_id_hex} to be moved could not be found")
|
format!("commit {commit_id_hex} to be moved could not be found")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -268,29 +257,29 @@ fn no_branch() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
let source_branch_id = branches[0].id;
|
let source_branch_id = branches[0].id;
|
||||||
|
|
||||||
let commit_oid = controller
|
let commit_oid =
|
||||||
.create_commit(project, source_branch_id, "commit", None, false)
|
gitbutler_branch_actions::create_commit(project, source_branch_id, "commit", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let id = BranchId::generate();
|
let id = BranchId::generate();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::move_commit(project, id, commit_oid)
|
||||||
.move_commit(project, id, commit_oid)
|
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
format!("branch {id} is not among applied branches")
|
format!("branch {id} is not among applied branches")
|
||||||
|
@ -11,14 +11,16 @@ fn workdir_vbranch_restore() -> anyhow::Result<()> {
|
|||||||
let test = Test::default();
|
let test = Test::default();
|
||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
controller,
|
|
||||||
project,
|
project,
|
||||||
..
|
..
|
||||||
} = &test;
|
} = &test;
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let worktree_dir = repository.path();
|
let worktree_dir = repository.path();
|
||||||
for round in 0..3 {
|
for round in 0..3 {
|
||||||
@ -27,14 +29,14 @@ fn workdir_vbranch_restore() -> anyhow::Result<()> {
|
|||||||
worktree_dir.join(format!("file{round}.txt")),
|
worktree_dir.join(format!("file{round}.txt")),
|
||||||
make_lines(line_count),
|
make_lines(line_count),
|
||||||
)?;
|
)?;
|
||||||
let branch_id = controller.create_virtual_branch(
|
let branch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
project,
|
project,
|
||||||
&BranchCreateRequest {
|
&BranchCreateRequest {
|
||||||
name: Some(round.to_string()),
|
name: Some(round.to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
controller.create_commit(
|
gitbutler_branch_actions::create_commit(
|
||||||
project,
|
project,
|
||||||
branch_id,
|
branch_id,
|
||||||
&format!("commit {round}"),
|
&format!("commit {round}"),
|
||||||
@ -51,7 +53,7 @@ fn workdir_vbranch_restore() -> anyhow::Result<()> {
|
|||||||
line_count > 20
|
line_count > 20
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let _empty = controller.create_virtual_branch(project, &Default::default())?;
|
let _empty = gitbutler_branch_actions::create_virtual_branch(project, &Default::default())?;
|
||||||
|
|
||||||
let snapshots = project.list_snapshots(10, None)?;
|
let snapshots = project.list_snapshots(10, None)?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -96,18 +98,20 @@ fn make_lines(count: usize) -> Vec<u8> {
|
|||||||
fn basic_oplog() -> anyhow::Result<()> {
|
fn basic_oplog() -> anyhow::Result<()> {
|
||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
controller,
|
|
||||||
project,
|
project,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller.set_base_branch(project, &"refs/remotes/origin/master".parse()?)?;
|
gitbutler_branch_actions::set_base_branch(project, &"refs/remotes/origin/master".parse()?)?;
|
||||||
|
|
||||||
let branch_id = controller.create_virtual_branch(project, &BranchCreateRequest::default())?;
|
let branch_id =
|
||||||
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())?;
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content")?;
|
fs::write(repository.path().join("file.txt"), "content")?;
|
||||||
let _commit1_id = controller.create_commit(project, branch_id, "commit one", None, false)?;
|
let _commit1_id =
|
||||||
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)?;
|
||||||
|
|
||||||
// dont store large files
|
// dont store large files
|
||||||
let file_path = repository.path().join("large.txt");
|
let file_path = repository.path().join("large.txt");
|
||||||
@ -121,7 +125,8 @@ fn basic_oplog() -> anyhow::Result<()> {
|
|||||||
// create commit with large file
|
// create commit with large file
|
||||||
fs::write(repository.path().join("file2.txt"), "content2")?;
|
fs::write(repository.path().join("file2.txt"), "content2")?;
|
||||||
fs::write(repository.path().join("file3.txt"), "content3")?;
|
fs::write(repository.path().join("file3.txt"), "content3")?;
|
||||||
let commit2_id = controller.create_commit(project, branch_id, "commit two", None, false)?;
|
let commit2_id =
|
||||||
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)?;
|
||||||
|
|
||||||
// Create conflict state
|
// Create conflict state
|
||||||
let conflicts_path = repository.path().join(".git").join("conflicts");
|
let conflicts_path = repository.path().join(".git").join("conflicts");
|
||||||
@ -131,22 +136,22 @@ fn basic_oplog() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
// create state with conflict state
|
// create state with conflict state
|
||||||
let _empty_branch_id =
|
let _empty_branch_id =
|
||||||
controller.create_virtual_branch(project, &BranchCreateRequest::default())?;
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())?;
|
||||||
|
|
||||||
std::fs::remove_file(&base_merge_parent_path)?;
|
std::fs::remove_file(&base_merge_parent_path)?;
|
||||||
std::fs::remove_file(&conflicts_path)?;
|
std::fs::remove_file(&conflicts_path)?;
|
||||||
|
|
||||||
fs::write(repository.path().join("file4.txt"), "content4")?;
|
fs::write(repository.path().join("file4.txt"), "content4")?;
|
||||||
let _commit3_id = controller.create_commit(project, branch_id, "commit three", None, false)?;
|
let _commit3_id =
|
||||||
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)?;
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)?
|
||||||
.list_virtual_branches(project)?
|
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|b| b.id == branch_id)
|
.find(|b| b.id == branch_id)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let branches = controller.list_virtual_branches(project)?;
|
let branches = gitbutler_branch_actions::list_virtual_branches(project)?;
|
||||||
assert_eq!(branches.0.len(), 2);
|
assert_eq!(branches.0.len(), 2);
|
||||||
|
|
||||||
assert_eq!(branch.commits.len(), 3);
|
assert_eq!(branch.commits.len(), 3);
|
||||||
@ -185,7 +190,7 @@ fn basic_oplog() -> anyhow::Result<()> {
|
|||||||
project.restore_snapshot(snapshots[2].clone().commit_id)?;
|
project.restore_snapshot(snapshots[2].clone().commit_id)?;
|
||||||
|
|
||||||
// the restore removed our new branch
|
// the restore removed our new branch
|
||||||
let branches = controller.list_virtual_branches(project)?;
|
let branches = gitbutler_branch_actions::list_virtual_branches(project)?;
|
||||||
assert_eq!(branches.0.len(), 1);
|
assert_eq!(branches.0.len(), 1);
|
||||||
|
|
||||||
// assert that the conflicts file was removed
|
// assert that the conflicts file was removed
|
||||||
@ -233,12 +238,12 @@ fn basic_oplog() -> anyhow::Result<()> {
|
|||||||
fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
controller,
|
|
||||||
project,
|
project,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller.set_base_branch(project, &"refs/remotes/origin/master".parse()?)?;
|
gitbutler_branch_actions::set_base_branch(project, &"refs/remotes/origin/master".parse()?)?;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
VirtualBranchesHandle::new(project.gb_dir())
|
VirtualBranchesHandle::new(project.gb_dir())
|
||||||
@ -246,7 +251,8 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
|||||||
.len(),
|
.len(),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
let branch_id = controller.create_virtual_branch(project, &BranchCreateRequest::default())?;
|
let branch_id =
|
||||||
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
VirtualBranchesHandle::new(project.gb_dir())
|
VirtualBranchesHandle::new(project.gb_dir())
|
||||||
.list_branches_in_workspace()?
|
.list_branches_in_workspace()?
|
||||||
@ -256,7 +262,8 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content")?;
|
fs::write(repository.path().join("file.txt"), "content")?;
|
||||||
let _commit1_id = controller.create_commit(project, branch_id, "commit one", None, false)?;
|
let _commit1_id =
|
||||||
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)?;
|
||||||
|
|
||||||
let repo = git2::Repository::open(&project.path)?;
|
let repo = git2::Repository::open(&project.path)?;
|
||||||
|
|
||||||
@ -269,7 +276,8 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
// create second commit
|
// create second commit
|
||||||
fs::write(repository.path().join("file.txt"), "changed content")?;
|
fs::write(repository.path().join("file.txt"), "changed content")?;
|
||||||
let _commit2_id = controller.create_commit(project, branch_id, "commit two", None, false)?;
|
let _commit2_id =
|
||||||
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)?;
|
||||||
|
|
||||||
// check the workspace commit changed
|
// check the workspace commit changed
|
||||||
let head = repo.head().expect("never unborn");
|
let head = repo.head().expect("never unborn");
|
||||||
@ -347,17 +355,21 @@ fn restores_gitbutler_workspace() -> anyhow::Result<()> {
|
|||||||
fn head_corrupt_is_recreated_automatically() {
|
fn head_corrupt_is_recreated_automatically() {
|
||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
controller,
|
|
||||||
project,
|
project,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
controller
|
)
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
.unwrap();
|
||||||
.unwrap();
|
gitbutler_branch_actions::set_base_branch(
|
||||||
|
project,
|
||||||
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let snapshots = project.list_snapshots(10, None).unwrap();
|
let snapshots = project.list_snapshots(10, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -374,9 +386,11 @@ fn head_corrupt_is_recreated_automatically() {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.expect("the snapshot doesn't fail despite the corrupt head");
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.expect("the snapshot doesn't fail despite the corrupt head");
|
||||||
|
|
||||||
let snapshots = project.list_snapshots(10, None).unwrap();
|
let snapshots = project.list_snapshots(10, None).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -9,20 +9,24 @@ mod create_virtual_branch {
|
|||||||
fn simple() {
|
fn simple() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
project,
|
||||||
.unwrap();
|
&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.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch_id);
|
assert_eq!(branches[0].id, branch_id);
|
||||||
assert_eq!(branches[0].name, "Virtual branch");
|
assert_eq!(branches[0].name, "Virtual branch");
|
||||||
@ -39,36 +43,36 @@ mod create_virtual_branch {
|
|||||||
fn duplicate_name() {
|
fn duplicate_name() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch1_id = controller
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
name: Some("name".to_string()),
|
||||||
name: Some("name".to_string()),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch2_id = controller
|
let branch2_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
name: Some("name".to_string()),
|
||||||
name: Some("name".to_string()),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 2);
|
assert_eq!(branches.len(), 2);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].name, "name");
|
assert_eq!(branches[0].name, "name");
|
||||||
@ -94,37 +98,37 @@ mod update_virtual_branch {
|
|||||||
fn simple() {
|
fn simple() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
name: Some("name".to_string()),
|
||||||
name: Some("name".to_string()),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::update_virtual_branch(
|
||||||
.update_virtual_branch(
|
project,
|
||||||
project,
|
BranchUpdateRequest {
|
||||||
BranchUpdateRequest {
|
id: branch_id,
|
||||||
id: branch_id,
|
name: Some("new name".to_string()),
|
||||||
name: Some("new name".to_string()),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch_id);
|
assert_eq!(branches[0].id, branch_id);
|
||||||
assert_eq!(branches[0].name, "new name");
|
assert_eq!(branches[0].name, "new name");
|
||||||
@ -142,46 +146,45 @@ mod update_virtual_branch {
|
|||||||
fn duplicate_name() {
|
fn duplicate_name() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch1_id = controller
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
name: Some("name".to_string()),
|
||||||
name: Some("name".to_string()),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch2_id = controller
|
let branch2_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::update_virtual_branch(
|
||||||
.update_virtual_branch(
|
project,
|
||||||
project,
|
BranchUpdateRequest {
|
||||||
BranchUpdateRequest {
|
id: branch2_id,
|
||||||
id: branch2_id,
|
name: Some("name".to_string()),
|
||||||
name: Some("name".to_string()),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 2);
|
assert_eq!(branches.len(), 2);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].name, "name");
|
assert_eq!(branches[0].name, "name");
|
||||||
@ -207,35 +210,32 @@ mod push_virtual_branch {
|
|||||||
fn simple() {
|
fn simple() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch1_id = controller
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
name: Some("name".to_string()),
|
||||||
name: Some("name".to_string()),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch1_id, "test", None, false).unwrap();
|
||||||
.create_commit(project, branch1_id, "test", None, false)
|
gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None).unwrap();
|
||||||
.unwrap();
|
|
||||||
controller
|
|
||||||
.push_virtual_branch(project, branch1_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].name, "name");
|
assert_eq!(branches[0].name, "name");
|
||||||
@ -256,70 +256,65 @@ mod push_virtual_branch {
|
|||||||
fn duplicate_names() {
|
fn duplicate_names() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch1_id = {
|
let branch1_id = {
|
||||||
// create and push branch with some work
|
// create and push branch with some work
|
||||||
let branch1_id = controller
|
let branch1_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
name: Some("name".to_string()),
|
||||||
name: Some("name".to_string()),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch1_id, "test", None, false)
|
||||||
.create_commit(project, branch1_id, "test", None, false)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None)
|
||||||
.push_virtual_branch(project, branch1_id, false, None)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
branch1_id
|
branch1_id
|
||||||
};
|
};
|
||||||
|
|
||||||
// rename first branch
|
// rename first branch
|
||||||
controller
|
gitbutler_branch_actions::update_virtual_branch(
|
||||||
.update_virtual_branch(
|
project,
|
||||||
|
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,
|
project,
|
||||||
BranchUpdateRequest {
|
&BranchCreateRequest {
|
||||||
id: branch1_id,
|
name: Some("name".to_string()),
|
||||||
name: Some("updated name".to_string()),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.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();
|
fs::write(repository.path().join("file.txt"), "updated content").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch2_id, "test", None, false)
|
||||||
.create_commit(project, branch2_id, "test", None, false)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch2_id, false, None)
|
||||||
.push_virtual_branch(project, branch2_id, false, None)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
branch2_id
|
branch2_id
|
||||||
};
|
};
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 2);
|
assert_eq!(branches.len(), 2);
|
||||||
// first branch is pushing to old ref remotely
|
// first branch is pushing to old ref remotely
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
|
@ -7,37 +7,35 @@ fn reorder_commit_down() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let _commit1_id = controller
|
let _commit1_id =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||||
let commit2_id = controller
|
let commit2_id =
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::reorder_commit(project, branch_id, commit2_id, 1).unwrap();
|
||||||
.reorder_commit(project, branch_id, commit2_id, 1)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -62,37 +60,35 @@ fn reorder_commit_up() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let commit1_id = controller
|
let commit1_id =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||||
let _commit2_id = controller
|
let _commit2_id =
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::reorder_commit(project, branch_id, commit1_id, -1).unwrap();
|
||||||
.reorder_commit(project, branch_id, commit1_id, -1)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -9,27 +9,28 @@ fn to_head() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch1_id = controller
|
let branch1_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let oid = {
|
let oid = {
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
// commit changes
|
// commit changes
|
||||||
let oid = controller
|
let oid =
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
@ -45,11 +46,9 @@ fn to_head() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// reset changes to head
|
// reset changes to head
|
||||||
controller
|
gitbutler_branch_actions::reset_virtual_branch(project, branch1_id, oid).unwrap();
|
||||||
.reset_virtual_branch(project, branch1_id, oid)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
@ -67,27 +66,28 @@ fn to_target() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
let base_branch = controller
|
let base_branch = gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch1_id = controller
|
let branch1_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
// commit changes
|
// commit changes
|
||||||
let oid = controller
|
let oid =
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
@ -101,11 +101,10 @@ fn to_target() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// reset changes to head
|
// reset changes to head
|
||||||
controller
|
gitbutler_branch_actions::reset_virtual_branch(project, branch1_id, base_branch.base_sha)
|
||||||
.reset_virtual_branch(project, branch1_id, base_branch.base_sha)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].commits.len(), 0);
|
assert_eq!(branches[0].commits.len(), 0);
|
||||||
@ -122,28 +121,29 @@ fn to_commit() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch1_id = controller
|
let branch1_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let first_commit_oid = {
|
let first_commit_oid = {
|
||||||
// commit some changes
|
// commit some changes
|
||||||
|
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let oid = controller
|
let oid =
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
@ -161,11 +161,11 @@ fn to_commit() {
|
|||||||
// commit some more
|
// commit some more
|
||||||
fs::write(repository.path().join("file.txt"), "more content").unwrap();
|
fs::write(repository.path().join("file.txt"), "more content").unwrap();
|
||||||
|
|
||||||
let second_commit_oid = controller
|
let second_commit_oid =
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].commits.len(), 2);
|
assert_eq!(branches[0].commits.len(), 2);
|
||||||
@ -180,11 +180,10 @@ fn to_commit() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// reset changes to the first commit
|
// reset changes to the first commit
|
||||||
controller
|
gitbutler_branch_actions::reset_virtual_branch(project, branch1_id, first_commit_oid)
|
||||||
.reset_virtual_branch(project, branch1_id, first_commit_oid)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
@ -202,27 +201,28 @@ fn to_non_existing() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch1_id = controller
|
let branch1_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
// commit changes
|
// commit changes
|
||||||
let oid = controller
|
let oid =
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
@ -237,14 +237,13 @@ fn to_non_existing() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::reset_virtual_branch(
|
||||||
.reset_virtual_branch(
|
project,
|
||||||
project,
|
branch1_id,
|
||||||
branch1_id,
|
"fe14df8c66b73c6276f7bb26102ad91da680afcb".parse().unwrap()
|
||||||
"fe14df8c66b73c6276f7bb26102ad91da680afcb".parse().unwrap()
|
)
|
||||||
)
|
.unwrap_err()
|
||||||
.unwrap_err()
|
.to_string(),
|
||||||
.to_string(),
|
|
||||||
"commit fe14df8c66b73c6276f7bb26102ad91da680afcb not in the branch"
|
"commit fe14df8c66b73c6276f7bb26102ad91da680afcb not in the branch"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -7,27 +7,28 @@ fn unapplying_selected_branch_selects_anther() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file one.txt"), "").unwrap();
|
std::fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
|
|
||||||
// first branch should be created as default
|
// first branch should be created as default
|
||||||
let b_id = controller
|
let b_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// if default branch exists, new branch should not be created as default
|
// if default branch exists, new branch should not be created as default
|
||||||
let b2_id = controller
|
let b2_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
|
|
||||||
let b = branches.iter().find(|b| b.id == b_id).unwrap();
|
let b = branches.iter().find(|b| b.id == b_id).unwrap();
|
||||||
|
|
||||||
@ -36,9 +37,9 @@ fn unapplying_selected_branch_selects_anther() {
|
|||||||
assert!(b.selected_for_changes);
|
assert!(b.selected_for_changes);
|
||||||
assert!(!b2.selected_for_changes);
|
assert!(!b2.selected_for_changes);
|
||||||
|
|
||||||
controller.convert_to_real_branch(project, b_id).unwrap();
|
gitbutler_branch_actions::convert_to_real_branch(project, b_id).unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
|
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, b2.id);
|
assert_eq!(branches[0].id, b2.id);
|
||||||
@ -48,27 +49,25 @@ fn unapplying_selected_branch_selects_anther() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deleting_selected_branch_selects_anther() {
|
fn deleting_selected_branch_selects_anther() {
|
||||||
let Test {
|
let Test { project, .. } = &Test::default();
|
||||||
project,
|
|
||||||
controller,
|
|
||||||
..
|
|
||||||
} = &Test::default();
|
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// first branch should be created as default
|
// first branch should be created as default
|
||||||
let b_id = controller
|
let b_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// if default branch exists, new branch should not be created as default
|
// if default branch exists, new branch should not be created as default
|
||||||
let b2_id = controller
|
let b2_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
|
|
||||||
let b = branches.iter().find(|b| b.id == b_id).unwrap();
|
let b = branches.iter().find(|b| b.id == b_id).unwrap();
|
||||||
|
|
||||||
@ -77,9 +76,9 @@ fn deleting_selected_branch_selects_anther() {
|
|||||||
assert!(b.selected_for_changes);
|
assert!(b.selected_for_changes);
|
||||||
assert!(!b2.selected_for_changes);
|
assert!(!b2.selected_for_changes);
|
||||||
|
|
||||||
controller.delete_virtual_branch(project, b_id).unwrap();
|
gitbutler_branch_actions::delete_virtual_branch(project, b_id).unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
|
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, b2.id);
|
assert_eq!(branches[0].id, b2.id);
|
||||||
@ -88,22 +87,19 @@ fn deleting_selected_branch_selects_anther() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_virtual_branch_should_set_selected_for_changes() {
|
fn create_virtual_branch_should_set_selected_for_changes() {
|
||||||
let Test {
|
let Test { project, .. } = &Test::default();
|
||||||
project,
|
|
||||||
controller,
|
|
||||||
..
|
|
||||||
} = &Test::default();
|
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// first branch should be created as default
|
// first branch should be created as default
|
||||||
let b_id = controller
|
let b_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -112,11 +108,10 @@ fn create_virtual_branch_should_set_selected_for_changes() {
|
|||||||
assert!(branch.selected_for_changes);
|
assert!(branch.selected_for_changes);
|
||||||
|
|
||||||
// if default branch exists, new branch should not be created as default
|
// if default branch exists, new branch should not be created as default
|
||||||
let b_id = controller
|
let b_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -125,17 +120,15 @@ fn create_virtual_branch_should_set_selected_for_changes() {
|
|||||||
assert!(!branch.selected_for_changes);
|
assert!(!branch.selected_for_changes);
|
||||||
|
|
||||||
// explicitly don't make this one default
|
// explicitly don't make this one default
|
||||||
let b_id = controller
|
let b_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
selected_for_changes: Some(false),
|
||||||
selected_for_changes: Some(false),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
let branch = controller
|
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -144,17 +137,15 @@ fn create_virtual_branch_should_set_selected_for_changes() {
|
|||||||
assert!(!branch.selected_for_changes);
|
assert!(!branch.selected_for_changes);
|
||||||
|
|
||||||
// explicitly make this one default
|
// explicitly make this one default
|
||||||
let b_id = controller
|
let b_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
selected_for_changes: Some(true),
|
||||||
selected_for_changes: Some(true),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
let branch = controller
|
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -165,21 +156,18 @@ fn create_virtual_branch_should_set_selected_for_changes() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn update_virtual_branch_should_reset_selected_for_changes() {
|
fn update_virtual_branch_should_reset_selected_for_changes() {
|
||||||
let Test {
|
let Test { project, .. } = &Test::default();
|
||||||
|
|
||||||
|
gitbutler_branch_actions::set_base_branch(
|
||||||
project,
|
project,
|
||||||
controller,
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
..
|
)
|
||||||
} = &Test::default();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
let b1_id =
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let b1 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
let b1_id = controller
|
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
|
||||||
.unwrap();
|
|
||||||
let b1 = controller
|
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -187,11 +175,10 @@ fn update_virtual_branch_should_reset_selected_for_changes() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(b1.selected_for_changes);
|
assert!(b1.selected_for_changes);
|
||||||
|
|
||||||
let b2_id = controller
|
let b2_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let b2 = controller
|
let b2 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -199,19 +186,17 @@ fn update_virtual_branch_should_reset_selected_for_changes() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!b2.selected_for_changes);
|
assert!(!b2.selected_for_changes);
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::update_virtual_branch(
|
||||||
.update_virtual_branch(
|
project,
|
||||||
project,
|
BranchUpdateRequest {
|
||||||
BranchUpdateRequest {
|
id: b2_id,
|
||||||
id: b2_id,
|
selected_for_changes: Some(true),
|
||||||
selected_for_changes: Some(true),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let b1 = controller
|
let b1 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -219,8 +204,7 @@ fn update_virtual_branch_should_reset_selected_for_changes() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!b1.selected_for_changes);
|
assert!(!b1.selected_for_changes);
|
||||||
|
|
||||||
let b2 = controller
|
let b2 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -234,21 +218,21 @@ fn unapply_virtual_branch_should_reset_selected_for_changes() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let b1_id = controller
|
let b1_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let b1 = controller
|
let b1 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -256,12 +240,11 @@ fn unapply_virtual_branch_should_reset_selected_for_changes() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(b1.selected_for_changes);
|
assert!(b1.selected_for_changes);
|
||||||
|
|
||||||
let b2_id = controller
|
let b2_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let b2 = controller
|
let b2 = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -269,10 +252,9 @@ fn unapply_virtual_branch_should_reset_selected_for_changes() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(!b2.selected_for_changes);
|
assert!(!b2.selected_for_changes);
|
||||||
|
|
||||||
controller.convert_to_real_branch(project, b1_id).unwrap();
|
gitbutler_branch_actions::convert_to_real_branch(project, b1_id).unwrap();
|
||||||
|
|
||||||
assert!(controller
|
assert!(gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -284,30 +266,30 @@ fn hunks_distribution() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches[0].files.len(), 1);
|
assert_eq!(branches[0].files.len(), 1);
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
selected_for_changes: Some(true),
|
||||||
selected_for_changes: Some(true),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
std::fs::write(repository.path().join("another_file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("another_file.txt"), "content").unwrap();
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches[0].files.len(), 1);
|
assert_eq!(branches[0].files.len(), 1);
|
||||||
assert_eq!(branches[1].files.len(), 1);
|
assert_eq!(branches[1].files.len(), 1);
|
||||||
}
|
}
|
||||||
@ -317,28 +299,27 @@ fn applying_first_branch() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
let unapplied_branch = controller
|
let unapplied_branch =
|
||||||
.convert_to_real_branch(project, branches[0].id)
|
gitbutler_branch_actions::convert_to_real_branch(project, branches[0].id).unwrap();
|
||||||
.unwrap();
|
|
||||||
let unapplied_branch = Refname::from_str(&unapplied_branch).unwrap();
|
let unapplied_branch = Refname::from_str(&unapplied_branch).unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
||||||
.create_virtual_branch_from_branch(project, &unapplied_branch, None)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert!(branches[0].active);
|
assert!(branches[0].active);
|
||||||
assert!(branches[0].selected_for_changes);
|
assert!(branches[0].selected_for_changes);
|
||||||
@ -351,7 +332,6 @@ fn new_locked_hunk_without_modifying_existing() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -359,44 +339,44 @@ fn new_locked_hunk_without_modifying_existing() {
|
|||||||
repository.commit_all("first commit");
|
repository.commit_all("first commit");
|
||||||
repository.push();
|
repository.push();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
lines[0] = "modification 1".to_string();
|
lines[0] = "modification 1".to_string();
|
||||||
repository.write_file("file.txt", &lines);
|
repository.write_file("file.txt", &lines);
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches[0].files.len(), 1);
|
assert_eq!(branches[0].files.len(), 1);
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branches[0].id, "second commit", None, false)
|
||||||
.create_commit(project, branches[0].id, "second commit", None, false)
|
|
||||||
.expect("failed to create commit");
|
.expect("failed to create commit");
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches[0].files.len(), 0);
|
assert_eq!(branches[0].files.len(), 0);
|
||||||
assert_eq!(branches[0].commits.len(), 1);
|
assert_eq!(branches[0].commits.len(), 1);
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(
|
project,
|
||||||
project,
|
&BranchCreateRequest {
|
||||||
&BranchCreateRequest {
|
selected_for_changes: Some(true),
|
||||||
selected_for_changes: Some(true),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
lines[8] = "modification 2".to_string();
|
lines[8] = "modification 2".to_string();
|
||||||
repository.write_file("file.txt", &lines);
|
repository.write_file("file.txt", &lines);
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches[0].files.len(), 0);
|
assert_eq!(branches[0].files.len(), 0);
|
||||||
assert_eq!(branches[1].files.len(), 1);
|
assert_eq!(branches[1].files.len(), 1);
|
||||||
|
|
||||||
lines[0] = "modification 3".to_string();
|
lines[0] = "modification 3".to_string();
|
||||||
repository.write_file("file.txt", &lines);
|
repository.write_file("file.txt", &lines);
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches[0].files.len(), 1);
|
assert_eq!(branches[0].files.len(), 1);
|
||||||
assert_eq!(branches[1].files.len(), 1);
|
assert_eq!(branches[1].files.len(), 1);
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,13 @@ use super::*;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn success() {
|
fn success() {
|
||||||
let Test {
|
let Test { project, .. } = &Test::default();
|
||||||
project,
|
|
||||||
controller,
|
|
||||||
..
|
|
||||||
} = &Test::default();
|
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
mod error {
|
mod error {
|
||||||
@ -20,20 +18,15 @@ mod error {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn missing() {
|
fn missing() {
|
||||||
let Test {
|
let Test { project, .. } = &Test::default();
|
||||||
project,
|
|
||||||
controller,
|
|
||||||
..
|
|
||||||
} = &Test::default();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(
|
project,
|
||||||
project,
|
&RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(),
|
||||||
&RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(),
|
)
|
||||||
)
|
.unwrap_err()
|
||||||
.unwrap_err()
|
.to_string(),
|
||||||
.to_string(),
|
|
||||||
"remote branch 'refs/remotes/origin/missing' not found"
|
"remote branch 'refs/remotes/origin/missing' not found"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -50,7 +43,6 @@ mod go_back_to_workspace {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -60,29 +52,33 @@ mod go_back_to_workspace {
|
|||||||
repository.commit_all("two");
|
repository.commit_all("two");
|
||||||
repository.push();
|
repository.push();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let vbranch_id = controller
|
let vbranch_id = gitbutler_branch_actions::create_virtual_branch(
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
project,
|
||||||
.unwrap();
|
&BranchCreateRequest::default(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
std::fs::write(repository.path().join("another file.txt"), "content").unwrap();
|
std::fs::write(repository.path().join("another file.txt"), "content").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, vbranch_id, "one", None, false).unwrap();
|
||||||
.create_commit(project, vbranch_id, "one", None, false)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
|
|
||||||
repository.checkout_commit(oid_one);
|
repository.checkout_commit(oid_one);
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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.len(), 1);
|
||||||
assert_eq!(branches[0].id, vbranch_id);
|
assert_eq!(branches[0].id, vbranch_id);
|
||||||
assert!(branches[0].active);
|
assert!(branches[0].active);
|
||||||
@ -93,7 +89,6 @@ mod go_back_to_workspace {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -103,21 +98,25 @@ mod go_back_to_workspace {
|
|||||||
repository.commit_all("two");
|
repository.commit_all("two");
|
||||||
repository.push();
|
repository.push();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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());
|
assert!(branches.is_empty());
|
||||||
|
|
||||||
repository.checkout_commit(oid_one);
|
repository.checkout_commit(oid_one);
|
||||||
std::fs::write(repository.path().join("file.txt"), "tree").unwrap();
|
std::fs::write(repository.path().join("file.txt"), "tree").unwrap();
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap_err()
|
&"refs/remotes/origin/master".parse().unwrap()
|
||||||
.downcast_ref(),
|
)
|
||||||
|
.unwrap_err()
|
||||||
|
.downcast_ref(),
|
||||||
Some(Marker::ProjectConflict)
|
Some(Marker::ProjectConflict)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -127,7 +126,6 @@ mod go_back_to_workspace {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -137,21 +135,25 @@ mod go_back_to_workspace {
|
|||||||
repository.commit_all("two");
|
repository.commit_all("two");
|
||||||
repository.push();
|
repository.push();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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());
|
assert!(branches.is_empty());
|
||||||
|
|
||||||
repository.checkout_commit(oid_one);
|
repository.checkout_commit(oid_one);
|
||||||
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
|
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
|
||||||
|
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap_err()
|
&"refs/remotes/origin/master".parse().unwrap()
|
||||||
.downcast_ref(),
|
)
|
||||||
|
.unwrap_err()
|
||||||
|
.downcast_ref(),
|
||||||
Some(Marker::ProjectConflict)
|
Some(Marker::ProjectConflict)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -161,7 +163,6 @@ mod go_back_to_workspace {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -171,22 +172,26 @@ mod go_back_to_workspace {
|
|||||||
repository.commit_all("two");
|
repository.commit_all("two");
|
||||||
repository.push();
|
repository.push();
|
||||||
|
|
||||||
let base = controller
|
let base = gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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());
|
assert!(branches.is_empty());
|
||||||
|
|
||||||
repository.checkout_commit(oid_one);
|
repository.checkout_commit(oid_one);
|
||||||
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
|
std::fs::write(repository.path().join("another file.txt"), "tree").unwrap();
|
||||||
repository.commit_all("three");
|
repository.commit_all("three");
|
||||||
|
|
||||||
let base_two = controller
|
let base_two = gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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!(branches.len(), 0);
|
||||||
assert_eq!(base_two, base);
|
assert_eq!(base_two, base);
|
||||||
}
|
}
|
||||||
@ -196,7 +201,6 @@ mod go_back_to_workspace {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
@ -206,20 +210,24 @@ mod go_back_to_workspace {
|
|||||||
repository.commit_all("two");
|
repository.commit_all("two");
|
||||||
repository.push();
|
repository.push();
|
||||||
|
|
||||||
let base = controller
|
let base = gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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());
|
assert!(branches.is_empty());
|
||||||
|
|
||||||
repository.checkout_commit(oid_one);
|
repository.checkout_commit(oid_one);
|
||||||
|
|
||||||
let base_two = controller
|
let base_two = gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"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!(branches.len(), 0);
|
||||||
assert_eq!(base_two, base);
|
assert_eq!(base_two, base);
|
||||||
}
|
}
|
||||||
|
@ -7,52 +7,46 @@ fn head() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let commit_four_oid = {
|
let commit_four_oid = {
|
||||||
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
|
||||||
.create_commit(project, branch_id, "commit four", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::squash(project, branch_id, commit_four_oid).unwrap();
|
||||||
.squash(project, branch_id, commit_four_oid)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -75,52 +69,46 @@ fn middle() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let commit_two_oid = {
|
let commit_two_oid = {
|
||||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
|
||||||
.create_commit(project, branch_id, "commit four", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::squash(project, branch_id, commit_two_oid).unwrap();
|
||||||
.squash(project, branch_id, commit_two_oid)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -144,7 +132,6 @@ fn forcepush_allowed() {
|
|||||||
repository,
|
repository,
|
||||||
project_id,
|
project_id,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
projects,
|
projects,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
@ -156,52 +143,45 @@ fn forcepush_allowed() {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||||
.push_virtual_branch(project, branch_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let commit_two_oid = {
|
let commit_two_oid = {
|
||||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
|
||||||
.create_commit(project, branch_id, "commit four", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::squash(project, branch_id, commit_two_oid).unwrap();
|
||||||
.squash(project, branch_id, commit_two_oid)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -225,64 +205,57 @@ fn forcepush_forbidden() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::update_virtual_branch(
|
||||||
.update_virtual_branch(
|
project,
|
||||||
project,
|
BranchUpdateRequest {
|
||||||
BranchUpdateRequest {
|
id: branch_id,
|
||||||
id: branch_id,
|
allow_rebasing: Some(false),
|
||||||
allow_rebasing: Some(false),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||||
.push_virtual_branch(project, branch_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let commit_two_oid = {
|
let commit_two_oid = {
|
||||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
fs::write(repository.path().join("file four.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit four", None, false)
|
||||||
.create_commit(project, branch_id, "commit four", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::squash(project, branch_id, commit_two_oid)
|
||||||
.squash(project, branch_id, commit_two_oid)
|
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"force push not allowed"
|
"force push not allowed"
|
||||||
@ -294,28 +267,27 @@ fn root_forbidden() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let commit_one_oid = {
|
let commit_one_oid = {
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::squash(project, branch_id, commit_one_oid)
|
||||||
.squash(project, branch_id, commit_one_oid)
|
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"can not squash root commit"
|
"can not squash root commit"
|
||||||
|
@ -8,27 +8,26 @@ use super::Test;
|
|||||||
fn should_unapply_with_commits() {
|
fn should_unapply_with_commits() {
|
||||||
let Test {
|
let Test {
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
repository,
|
repository,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
fs::write(
|
fs::write(
|
||||||
repository.path().join("file.txt"),
|
repository.path().join("file.txt"),
|
||||||
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n",
|
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n",
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "test", None, false).unwrap();
|
||||||
.create_commit(project, branch_id, "test", None, false)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// change in the committed hunks leads to hunk locking
|
// change in the committed hunks leads to hunk locking
|
||||||
fs::write(
|
fs::write(
|
||||||
@ -37,17 +36,15 @@ fn should_unapply_with_commits() {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::unapply_ownership(
|
||||||
.unapply_ownership(
|
project,
|
||||||
project,
|
&"file.txt:1-5,7-11"
|
||||||
&"file.txt:1-5,7-11"
|
.parse::<BranchOwnershipClaims>()
|
||||||
.parse::<BranchOwnershipClaims>()
|
.unwrap(),
|
||||||
.unwrap(),
|
)
|
||||||
)
|
.unwrap_or_else(|err| panic!("{err:?}"));
|
||||||
.unwrap_or_else(|err| panic!("{err:?}"));
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -7,43 +7,41 @@ fn undo_commit_simple() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
let _commit1_id = controller
|
let _commit1_id =
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file2.txt"), "content2").unwrap();
|
||||||
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
fs::write(repository.path().join("file3.txt"), "content3").unwrap();
|
||||||
let commit2_id = controller
|
let commit2_id =
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// create commit
|
// create commit
|
||||||
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
fs::write(repository.path().join("file4.txt"), "content4").unwrap();
|
||||||
let _commit3_id = controller
|
let _commit3_id =
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::undo_commit(project, branch_id, commit2_id).unwrap();
|
||||||
.undo_commit(project, branch_id, commit2_id)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -8,47 +8,48 @@ fn head() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let commit_three_oid = {
|
let commit_three_oid = {
|
||||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
let commit_three = repository.find_commit(commit_three_oid).unwrap();
|
let commit_three = repository.find_commit(commit_three_oid).unwrap();
|
||||||
let before_change_id = &commit_three.change_id();
|
let before_change_id = &commit_three.change_id();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::update_commit_message(
|
||||||
.update_commit_message(project, branch_id, commit_three_oid, "commit three updated")
|
project,
|
||||||
.unwrap();
|
branch_id,
|
||||||
|
commit_three_oid,
|
||||||
|
"commit three updated",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -79,45 +80,46 @@ fn middle() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let commit_two_oid = {
|
let commit_two_oid = {
|
||||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::update_commit_message(
|
||||||
.update_commit_message(project, branch_id, commit_two_oid, "commit two updated")
|
project,
|
||||||
.unwrap();
|
branch_id,
|
||||||
|
commit_two_oid,
|
||||||
|
"commit two updated",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -141,14 +143,15 @@ fn forcepush_allowed() {
|
|||||||
repository,
|
repository,
|
||||||
project_id,
|
project_id,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
projects,
|
projects,
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
projects
|
projects
|
||||||
.update(&projects::UpdateRequest {
|
.update(&projects::UpdateRequest {
|
||||||
@ -157,27 +160,27 @@ fn forcepush_allowed() {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let commit_one_oid = {
|
let commit_one_oid = {
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||||
.push_virtual_branch(project, branch_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::update_commit_message(
|
||||||
.update_commit_message(project, branch_id, commit_one_oid, "commit one updated")
|
project,
|
||||||
.unwrap();
|
branch_id,
|
||||||
|
commit_one_oid,
|
||||||
|
"commit one updated",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -198,45 +201,46 @@ fn forcepush_forbidden() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::update_virtual_branch(
|
||||||
.update_virtual_branch(
|
project,
|
||||||
project,
|
BranchUpdateRequest {
|
||||||
BranchUpdateRequest {
|
id: branch_id,
|
||||||
id: branch_id,
|
allow_rebasing: Some(false),
|
||||||
allow_rebasing: Some(false),
|
..Default::default()
|
||||||
..Default::default()
|
},
|
||||||
},
|
)
|
||||||
)
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let commit_one_oid = {
|
let commit_one_oid = {
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch_id, false, None).unwrap();
|
||||||
.push_virtual_branch(project, branch_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::update_commit_message(
|
||||||
.update_commit_message(project, branch_id, commit_one_oid, "commit one updated",)
|
project,
|
||||||
.unwrap_err()
|
branch_id,
|
||||||
.to_string(),
|
commit_one_oid,
|
||||||
|
"commit one updated",
|
||||||
|
)
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string(),
|
||||||
"force push not allowed"
|
"force push not allowed"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -246,45 +250,46 @@ fn root() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let commit_one_oid = {
|
let commit_one_oid = {
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
fs::write(repository.path().join("file two.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit two", None, false)
|
||||||
.create_commit(project, branch_id, "commit two", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
fs::write(repository.path().join("file three.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit three", None, false)
|
||||||
.create_commit(project, branch_id, "commit three", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::update_commit_message(
|
||||||
.update_commit_message(project, branch_id, commit_one_oid, "commit one updated")
|
project,
|
||||||
.unwrap();
|
branch_id,
|
||||||
|
commit_one_oid,
|
||||||
|
"commit one updated",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -307,28 +312,27 @@ fn empty() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch_id = controller
|
let branch_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let commit_one_oid = {
|
let commit_one_oid = {
|
||||||
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
fs::write(repository.path().join("file one.txt"), "").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch_id, "commit one", None, false)
|
||||||
.create_commit(project, branch_id, "commit one", None, false)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
controller
|
gitbutler_branch_actions::update_commit_message(project, branch_id, commit_one_oid, "",)
|
||||||
.update_commit_message(project, branch_id, commit_one_oid, "",)
|
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"commit message can not be empty"
|
"commit message can not be empty"
|
||||||
|
@ -7,50 +7,43 @@ fn detect_upstream_commits() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch1_id = controller
|
let branch1_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let oid1 = {
|
let oid1 = {
|
||||||
// create first commit
|
// create first commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
|
||||||
.unwrap()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let oid2 = {
|
let oid2 = {
|
||||||
// create second commit
|
// create second commit
|
||||||
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
|
||||||
.unwrap()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// push
|
// push
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None).unwrap();
|
||||||
.push_virtual_branch(project, branch1_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let oid3 = {
|
let oid3 = {
|
||||||
// create third commit
|
// create third commit
|
||||||
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
|
||||||
.unwrap()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
// should correctly detect pushed commits
|
// should correctly detect pushed commits
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].commits.len(), 3);
|
assert_eq!(branches[0].commits.len(), 3);
|
||||||
@ -68,43 +61,37 @@ fn detect_integrated_commits() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
controller
|
gitbutler_branch_actions::set_base_branch(
|
||||||
.set_base_branch(project, &"refs/remotes/origin/master".parse().unwrap())
|
project,
|
||||||
.unwrap();
|
&"refs/remotes/origin/master".parse().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let branch1_id = controller
|
let branch1_id =
|
||||||
.create_virtual_branch(project, &BranchCreateRequest::default())
|
gitbutler_branch_actions::create_virtual_branch(project, &BranchCreateRequest::default())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let oid1 = {
|
let oid1 = {
|
||||||
// create first commit
|
// create first commit
|
||||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
|
||||||
.unwrap()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let oid2 = {
|
let oid2 = {
|
||||||
// create second commit
|
// create second commit
|
||||||
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
|
||||||
.unwrap()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// push
|
// push
|
||||||
controller
|
gitbutler_branch_actions::push_virtual_branch(project, branch1_id, false, None).unwrap();
|
||||||
.push_virtual_branch(project, branch1_id, false, None)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// merge branch upstream
|
// merge branch upstream
|
||||||
let branch = controller
|
let branch = gitbutler_branch_actions::list_virtual_branches(project)
|
||||||
.list_virtual_branches(project)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.0
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -117,14 +104,12 @@ fn detect_integrated_commits() {
|
|||||||
let oid3 = {
|
let oid3 = {
|
||||||
// create third commit
|
// create third commit
|
||||||
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
||||||
controller
|
gitbutler_branch_actions::create_commit(project, branch1_id, "commit", None, false).unwrap()
|
||||||
.create_commit(project, branch1_id, "commit", None, false)
|
|
||||||
.unwrap()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
// should correctly detect pushed commits
|
// should correctly detect pushed commits
|
||||||
let (branches, _) = controller.list_virtual_branches(project).unwrap();
|
let (branches, _) = gitbutler_branch_actions::list_virtual_branches(project).unwrap();
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].id, branch1_id);
|
assert_eq!(branches[0].id, branch1_id);
|
||||||
assert_eq!(branches[0].commits.len(), 3);
|
assert_eq!(branches[0].commits.len(), 3);
|
||||||
|
@ -8,13 +8,12 @@ fn should_fail_on_incorrect_branch() {
|
|||||||
let Test {
|
let Test {
|
||||||
repository,
|
repository,
|
||||||
project,
|
project,
|
||||||
controller,
|
|
||||||
..
|
..
|
||||||
} = &Test::default();
|
} = &Test::default();
|
||||||
|
|
||||||
let branch_name: LocalRefname = "refs/heads/somebranch".parse().unwrap();
|
let branch_name: LocalRefname = "refs/heads/somebranch".parse().unwrap();
|
||||||
repository.checkout(&branch_name);
|
repository.checkout(&branch_name);
|
||||||
let result = controller.list_virtual_branches(project);
|
let result = gitbutler_branch_actions::list_virtual_branches(project);
|
||||||
|
|
||||||
let err = result.unwrap_err();
|
let err = result.unwrap_err();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use gitbutler_branch_actions::VirtualBranchActions;
|
|
||||||
use gitbutler_project::Project;
|
use gitbutler_project::Project;
|
||||||
use gitbutler_reference::RemoteRefname;
|
use gitbutler_reference::RemoteRefname;
|
||||||
|
|
||||||
@ -31,11 +30,13 @@ pub fn add(
|
|||||||
.canonicalize()?;
|
.canonicalize()?;
|
||||||
let project = ctrl.add(path)?;
|
let project = ctrl.add(path)?;
|
||||||
if let Some(refname) = refname {
|
if let Some(refname) = refname {
|
||||||
VirtualBranchActions.set_base_branch(&project, &refname)?;
|
gitbutler_branch_actions::set_base_branch(&project, &refname)?;
|
||||||
};
|
};
|
||||||
debug_print(project)
|
debug_print(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn switch_to_workspace(project: Project, refname: RemoteRefname) -> Result<()> {
|
pub fn switch_to_workspace(project: Project, refname: RemoteRefname) -> Result<()> {
|
||||||
debug_print(VirtualBranchActions.set_base_branch(&project, &refname)?)
|
debug_print(gitbutler_branch_actions::set_base_branch(
|
||||||
|
&project, &refname,
|
||||||
|
)?)
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,14 @@ use anyhow::{bail, Result};
|
|||||||
use gitbutler_branch::{
|
use gitbutler_branch::{
|
||||||
Branch, BranchCreateRequest, BranchIdentity, BranchUpdateRequest, VirtualBranchesHandle,
|
Branch, BranchCreateRequest, BranchIdentity, BranchUpdateRequest, VirtualBranchesHandle,
|
||||||
};
|
};
|
||||||
use gitbutler_branch_actions::{get_branch_listing_details, list_branches, VirtualBranchActions};
|
use gitbutler_branch_actions::{get_branch_listing_details, list_branches};
|
||||||
use gitbutler_command_context::CommandContext;
|
use gitbutler_command_context::CommandContext;
|
||||||
use gitbutler_project::Project;
|
use gitbutler_project::Project;
|
||||||
|
|
||||||
use crate::command::debug_print;
|
use crate::command::debug_print;
|
||||||
|
|
||||||
pub fn update_target(project: Project) -> Result<()> {
|
pub fn update_target(project: Project) -> Result<()> {
|
||||||
let unapplied = VirtualBranchActions.update_base_branch(&project)?;
|
let unapplied = gitbutler_branch_actions::update_base_branch(&project)?;
|
||||||
debug_print(unapplied)
|
debug_print(unapplied)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ pub fn list_all(project: Project) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_local(project: Project) -> Result<()> {
|
pub fn list_local(project: Project) -> Result<()> {
|
||||||
debug_print(VirtualBranchActions::list_local_branches(project)?)
|
debug_print(gitbutler_branch_actions::list_local_branches(project)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn details(project: Project, branch_names: Vec<BranchIdentity>) -> Result<()> {
|
pub fn details(project: Project, branch_names: Vec<BranchIdentity>) -> Result<()> {
|
||||||
@ -45,16 +45,18 @@ pub fn list(project: Project) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn status(project: Project) -> Result<()> {
|
pub fn status(project: Project) -> Result<()> {
|
||||||
debug_print(VirtualBranchActions.list_virtual_branches(&project)?)
|
debug_print(gitbutler_branch_actions::list_virtual_branches(&project)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unapply(project: Project, branch_name: String) -> Result<()> {
|
pub fn unapply(project: Project, branch_name: String) -> Result<()> {
|
||||||
let branch = branch_by_name(&project, &branch_name)?;
|
let branch = branch_by_name(&project, &branch_name)?;
|
||||||
debug_print(VirtualBranchActions.convert_to_real_branch(&project, branch.id)?)
|
debug_print(gitbutler_branch_actions::convert_to_real_branch(
|
||||||
|
&project, branch.id,
|
||||||
|
)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create(project: Project, branch_name: String, set_default: bool) -> Result<()> {
|
pub fn create(project: Project, branch_name: String, set_default: bool) -> Result<()> {
|
||||||
let new = VirtualBranchActions.create_virtual_branch(
|
let new = gitbutler_branch_actions::create_virtual_branch(
|
||||||
&project,
|
&project,
|
||||||
&BranchCreateRequest {
|
&BranchCreateRequest {
|
||||||
name: Some(branch_name),
|
name: Some(branch_name),
|
||||||
@ -74,7 +76,7 @@ pub fn set_default(project: Project, branch_name: String) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn set_default_branch(project: &Project, branch: &Branch) -> Result<()> {
|
fn set_default_branch(project: &Project, branch: &Branch) -> Result<()> {
|
||||||
VirtualBranchActions.update_virtual_branch(
|
gitbutler_branch_actions::update_virtual_branch(
|
||||||
project,
|
project,
|
||||||
BranchUpdateRequest {
|
BranchUpdateRequest {
|
||||||
id: branch.id,
|
id: branch.id,
|
||||||
@ -91,7 +93,7 @@ fn set_default_branch(project: &Project, branch: &Branch) -> Result<()> {
|
|||||||
|
|
||||||
pub fn commit(project: Project, branch_name: String, message: String) -> Result<()> {
|
pub fn commit(project: Project, branch_name: String, message: String) -> Result<()> {
|
||||||
let branch = branch_by_name(&project, &branch_name)?;
|
let branch = branch_by_name(&project, &branch_name)?;
|
||||||
let (info, skipped) = VirtualBranchActions.list_virtual_branches(&project)?;
|
let (info, skipped) = gitbutler_branch_actions::list_virtual_branches(&project)?;
|
||||||
|
|
||||||
if !skipped.is_empty() {
|
if !skipped.is_empty() {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
@ -129,7 +131,7 @@ pub fn commit(project: Project, branch_name: String, message: String) -> Result<
|
|||||||
}
|
}
|
||||||
|
|
||||||
let run_hooks = false;
|
let run_hooks = false;
|
||||||
debug_print(VirtualBranchActions.create_commit(
|
debug_print(gitbutler_branch_actions::create_commit(
|
||||||
&project,
|
&project,
|
||||||
branch.id,
|
branch.id,
|
||||||
&message,
|
&message,
|
||||||
|
@ -4,7 +4,8 @@ use anyhow::{bail, Context, Result};
|
|||||||
use bstr::ByteSlice;
|
use bstr::ByteSlice;
|
||||||
use git2::build::CheckoutBuilder;
|
use git2::build::CheckoutBuilder;
|
||||||
use gitbutler_branch::{signature, Branch, SignaturePurpose, VirtualBranchesHandle};
|
use gitbutler_branch::{signature, Branch, SignaturePurpose, VirtualBranchesHandle};
|
||||||
use gitbutler_branch_actions::{list_virtual_branches, update_workspace_commit, RemoteBranchFile};
|
use gitbutler_branch_actions::internal::list_virtual_branches;
|
||||||
|
use gitbutler_branch_actions::{update_workspace_commit, RemoteBranchFile};
|
||||||
use gitbutler_cherry_pick::RepositoryExt as _;
|
use gitbutler_cherry_pick::RepositoryExt as _;
|
||||||
use gitbutler_command_context::CommandContext;
|
use gitbutler_command_context::CommandContext;
|
||||||
use gitbutler_commit::{
|
use gitbutler_commit::{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
pub mod commands {
|
pub mod commands {
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use gitbutler_branch_actions::{RemoteBranchFile, VirtualBranchActions};
|
use gitbutler_branch_actions::RemoteBranchFile;
|
||||||
use gitbutler_project as projects;
|
use gitbutler_project as projects;
|
||||||
use gitbutler_project::ProjectId;
|
use gitbutler_project::ProjectId;
|
||||||
use gitbutler_repo::RepoCommands;
|
use gitbutler_repo::RepoCommands;
|
||||||
@ -69,6 +69,6 @@ pub mod commands {
|
|||||||
) -> Result<Vec<RemoteBranchFile>, Error> {
|
) -> Result<Vec<RemoteBranchFile>, Error> {
|
||||||
let project = projects.get(id)?;
|
let project = projects.get(id)?;
|
||||||
|
|
||||||
Ok(VirtualBranchActions.get_uncommited_files(&project)?)
|
Ok(gitbutler_branch_actions::get_uncommited_files(&project)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ pub mod commands {
|
|||||||
};
|
};
|
||||||
use gitbutler_branch_actions::{
|
use gitbutler_branch_actions::{
|
||||||
BaseBranch, BranchListing, BranchListingDetails, BranchListingFilter, RemoteBranch,
|
BaseBranch, BranchListing, BranchListingDetails, BranchListingFilter, RemoteBranch,
|
||||||
RemoteBranchData, RemoteBranchFile, VirtualBranchActions, VirtualBranches,
|
RemoteBranchData, RemoteBranchFile, VirtualBranches,
|
||||||
};
|
};
|
||||||
use gitbutler_command_context::CommandContext;
|
use gitbutler_command_context::CommandContext;
|
||||||
use gitbutler_error::error::Code;
|
use gitbutler_error::error::Code;
|
||||||
@ -38,7 +38,7 @@ pub mod commands {
|
|||||||
run_hooks: bool,
|
run_hooks: bool,
|
||||||
) -> Result<String, Error> {
|
) -> Result<String, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let oid = VirtualBranchActions.create_commit(
|
let oid = gitbutler_branch_actions::create_commit(
|
||||||
&project,
|
&project,
|
||||||
branch,
|
branch,
|
||||||
message,
|
message,
|
||||||
@ -56,8 +56,7 @@ pub mod commands {
|
|||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
) -> Result<VirtualBranches, Error> {
|
) -> Result<VirtualBranches, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions
|
gitbutler_branch_actions::list_virtual_branches(&project)
|
||||||
.list_virtual_branches(&project)
|
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
.map(|(branches, skipped_files)| VirtualBranches {
|
.map(|(branches, skipped_files)| VirtualBranches {
|
||||||
branches,
|
branches,
|
||||||
@ -74,7 +73,7 @@ pub mod commands {
|
|||||||
branch: BranchCreateRequest,
|
branch: BranchCreateRequest,
|
||||||
) -> Result<BranchId, Error> {
|
) -> Result<BranchId, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let branch_id = VirtualBranchActions.create_virtual_branch(&project, &branch)?;
|
let branch_id = gitbutler_branch_actions::create_virtual_branch(&project, &branch)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(branch_id)
|
Ok(branch_id)
|
||||||
}
|
}
|
||||||
@ -89,7 +88,7 @@ pub mod commands {
|
|||||||
given_name: String,
|
given_name: String,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.delete_local_branch(&project, &refname, given_name)?;
|
gitbutler_branch_actions::delete_local_branch(&project, &refname, given_name)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -105,7 +104,7 @@ pub mod commands {
|
|||||||
) -> Result<BranchId, Error> {
|
) -> Result<BranchId, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let branch_id =
|
let branch_id =
|
||||||
VirtualBranchActions.create_virtual_branch_from_branch(&project, &branch, remote)?;
|
gitbutler_branch_actions::create_virtual_branch_from_branch(&project, &branch, remote)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(branch_id)
|
Ok(branch_id)
|
||||||
}
|
}
|
||||||
@ -119,7 +118,7 @@ pub mod commands {
|
|||||||
branch: BranchId,
|
branch: BranchId,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.integrate_upstream_commits(&project, branch)?;
|
gitbutler_branch_actions::integrate_upstream_commits(&project, branch)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -131,7 +130,7 @@ pub mod commands {
|
|||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
) -> Result<Option<BaseBranch>, Error> {
|
) -> Result<Option<BaseBranch>, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
if let Ok(base_branch) = VirtualBranchActions::get_base_branch_data(&project) {
|
if let Ok(base_branch) = gitbutler_branch_actions::get_base_branch_data(&project) {
|
||||||
Ok(Some(base_branch))
|
Ok(Some(base_branch))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@ -151,11 +150,11 @@ pub mod commands {
|
|||||||
let branch_name = format!("refs/remotes/{}", branch)
|
let branch_name = format!("refs/remotes/{}", branch)
|
||||||
.parse()
|
.parse()
|
||||||
.context("Invalid branch name")?;
|
.context("Invalid branch name")?;
|
||||||
let base_branch = VirtualBranchActions.set_base_branch(&project, &branch_name)?;
|
let base_branch = gitbutler_branch_actions::set_base_branch(&project, &branch_name)?;
|
||||||
|
|
||||||
// if they also sent a different push remote, set that too
|
// if they also sent a different push remote, set that too
|
||||||
if let Some(push_remote) = push_remote {
|
if let Some(push_remote) = push_remote {
|
||||||
VirtualBranchActions.set_target_push_remote(&project, push_remote)?;
|
gitbutler_branch_actions::set_target_push_remote(&project, push_remote)?;
|
||||||
}
|
}
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(base_branch)
|
Ok(base_branch)
|
||||||
@ -169,7 +168,7 @@ pub mod commands {
|
|||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
) -> Result<Vec<ReferenceName>, Error> {
|
) -> Result<Vec<ReferenceName>, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let unapplied_branches = VirtualBranchActions.update_base_branch(&project)?;
|
let unapplied_branches = gitbutler_branch_actions::update_base_branch(&project)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(unapplied_branches)
|
Ok(unapplied_branches)
|
||||||
}
|
}
|
||||||
@ -183,7 +182,7 @@ pub mod commands {
|
|||||||
branch: BranchUpdateRequest,
|
branch: BranchUpdateRequest,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.update_virtual_branch(&project, branch)?;
|
gitbutler_branch_actions::update_virtual_branch(&project, branch)?;
|
||||||
|
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -198,7 +197,7 @@ pub mod commands {
|
|||||||
branches: Vec<BranchUpdateRequest>,
|
branches: Vec<BranchUpdateRequest>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.update_branch_order(&project, branches)?;
|
gitbutler_branch_actions::update_branch_order(&project, branches)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -212,7 +211,7 @@ pub mod commands {
|
|||||||
branch_id: BranchId,
|
branch_id: BranchId,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.delete_virtual_branch(&project, branch_id)?;
|
gitbutler_branch_actions::delete_virtual_branch(&project, branch_id)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -226,7 +225,7 @@ pub mod commands {
|
|||||||
branch: BranchId,
|
branch: BranchId,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.convert_to_real_branch(&project, branch)?;
|
gitbutler_branch_actions::convert_to_real_branch(&project, branch)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -240,7 +239,7 @@ pub mod commands {
|
|||||||
ownership: BranchOwnershipClaims,
|
ownership: BranchOwnershipClaims,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.unapply_ownership(&project, &ownership)?;
|
gitbutler_branch_actions::unapply_ownership(&project, &ownership)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -255,7 +254,7 @@ pub mod commands {
|
|||||||
files: Vec<PathBuf>,
|
files: Vec<PathBuf>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.reset_files(&project, branch_id, &files)?;
|
gitbutler_branch_actions::reset_files(&project, branch_id, &files)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -270,9 +269,13 @@ pub mod commands {
|
|||||||
with_force: bool,
|
with_force: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions
|
gitbutler_branch_actions::push_virtual_branch(
|
||||||
.push_virtual_branch(&project, branch_id, with_force, Some(Some(branch_id)))
|
&project,
|
||||||
.map_err(|err| err.context(Code::Unknown))?;
|
branch_id,
|
||||||
|
with_force,
|
||||||
|
Some(Some(branch_id)),
|
||||||
|
)
|
||||||
|
.map_err(|err| err.context(Code::Unknown))?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -285,7 +288,9 @@ pub mod commands {
|
|||||||
branch: RemoteRefname,
|
branch: RemoteRefname,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
Ok(VirtualBranchActions.can_apply_remote_branch(&project, &branch)?)
|
Ok(gitbutler_branch_actions::can_apply_remote_branch(
|
||||||
|
&project, &branch,
|
||||||
|
)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command(async)]
|
#[tauri::command(async)]
|
||||||
@ -297,9 +302,7 @@ pub mod commands {
|
|||||||
) -> Result<Vec<RemoteBranchFile>, Error> {
|
) -> Result<Vec<RemoteBranchFile>, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
VirtualBranchActions
|
gitbutler_branch_actions::list_remote_commit_files(&project, commit_oid).map_err(Into::into)
|
||||||
.list_remote_commit_files(&project, commit_oid)
|
|
||||||
.map_err(Into::into)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command(async)]
|
#[tauri::command(async)]
|
||||||
@ -313,7 +316,7 @@ pub mod commands {
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
|
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
VirtualBranchActions.reset_virtual_branch(&project, branch_id, target_commit_oid)?;
|
gitbutler_branch_actions::reset_virtual_branch(&project, branch_id, target_commit_oid)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -330,7 +333,7 @@ pub mod commands {
|
|||||||
) -> Result<String, Error> {
|
) -> Result<String, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
let oid = VirtualBranchActions.amend(&project, branch_id, commit_oid, &ownership)?;
|
let oid = gitbutler_branch_actions::amend(&project, branch_id, commit_oid, &ownership)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(oid.to_string())
|
Ok(oid.to_string())
|
||||||
}
|
}
|
||||||
@ -349,7 +352,7 @@ pub mod commands {
|
|||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let from_commit_oid = git2::Oid::from_str(&from_commit_oid).map_err(|e| anyhow!(e))?;
|
let from_commit_oid = git2::Oid::from_str(&from_commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
let to_commit_oid = git2::Oid::from_str(&to_commit_oid).map_err(|e| anyhow!(e))?;
|
let to_commit_oid = git2::Oid::from_str(&to_commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
let oid = VirtualBranchActions.move_commit_file(
|
let oid = gitbutler_branch_actions::move_commit_file(
|
||||||
&project,
|
&project,
|
||||||
branch_id,
|
branch_id,
|
||||||
from_commit_oid,
|
from_commit_oid,
|
||||||
@ -371,7 +374,7 @@ pub mod commands {
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
VirtualBranchActions.undo_commit(&project, branch_id, commit_oid)?;
|
gitbutler_branch_actions::undo_commit(&project, branch_id, commit_oid)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -388,7 +391,7 @@ pub mod commands {
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
VirtualBranchActions.insert_blank_commit(&project, branch_id, commit_oid, offset)?;
|
gitbutler_branch_actions::insert_blank_commit(&project, branch_id, commit_oid, offset)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -404,7 +407,7 @@ pub mod commands {
|
|||||||
change_id: String,
|
change_id: String,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.create_change_reference(&project, branch_id, name, change_id)?;
|
gitbutler_branch_actions::create_change_reference(&project, branch_id, name, change_id)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -420,7 +423,7 @@ pub mod commands {
|
|||||||
with_force: bool,
|
with_force: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.push_change_reference(&project, branch_id, name, with_force)?;
|
gitbutler_branch_actions::push_change_reference(&project, branch_id, name, with_force)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -436,7 +439,12 @@ pub mod commands {
|
|||||||
new_change_id: String,
|
new_change_id: String,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
VirtualBranchActions.update_change_reference(&project, branch_id, name, new_change_id)?;
|
gitbutler_branch_actions::update_change_reference(
|
||||||
|
&project,
|
||||||
|
branch_id,
|
||||||
|
name,
|
||||||
|
new_change_id,
|
||||||
|
)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -453,7 +461,7 @@ pub mod commands {
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
VirtualBranchActions.reorder_commit(&project, branch_id, commit_oid, offset)?;
|
gitbutler_branch_actions::reorder_commit(&project, branch_id, commit_oid, offset)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -465,7 +473,7 @@ pub mod commands {
|
|||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
) -> Result<Vec<RemoteBranch>, Error> {
|
) -> Result<Vec<RemoteBranch>, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let branches = VirtualBranchActions::list_local_branches(project)?;
|
let branches = gitbutler_branch_actions::list_local_branches(project)?;
|
||||||
Ok(branches)
|
Ok(branches)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,7 +509,7 @@ pub mod commands {
|
|||||||
refname: Refname,
|
refname: Refname,
|
||||||
) -> Result<RemoteBranchData, Error> {
|
) -> Result<RemoteBranchData, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let branch_data = VirtualBranchActions.get_remote_branch_data(&project, &refname)?;
|
let branch_data = gitbutler_branch_actions::get_remote_branch_data(&project, &refname)?;
|
||||||
Ok(branch_data)
|
Ok(branch_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,7 +524,7 @@ pub mod commands {
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
|
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
VirtualBranchActions.squash(&project, branch_id, target_commit_oid)?;
|
gitbutler_branch_actions::squash(&project, branch_id, target_commit_oid)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -530,7 +538,7 @@ pub mod commands {
|
|||||||
) -> Result<BaseBranch, Error> {
|
) -> Result<BaseBranch, Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
|
|
||||||
let project_data_last_fetched = VirtualBranchActions.fetch_from_remotes(
|
let project_data_last_fetched = gitbutler_branch_actions::fetch_from_remotes(
|
||||||
&project,
|
&project,
|
||||||
Some(action.unwrap_or_else(|| "unknown".to_string())),
|
Some(action.unwrap_or_else(|| "unknown".to_string())),
|
||||||
)?;
|
)?;
|
||||||
@ -550,7 +558,7 @@ pub mod commands {
|
|||||||
return Err(anyhow!(error).into());
|
return Err(anyhow!(error).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let base_branch = VirtualBranchActions::get_base_branch_data(&project)?;
|
let base_branch = gitbutler_branch_actions::get_base_branch_data(&project)?;
|
||||||
Ok(base_branch)
|
Ok(base_branch)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,7 +573,7 @@ pub mod commands {
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
VirtualBranchActions.move_commit(&project, target_branch_id, commit_oid)?;
|
gitbutler_branch_actions::move_commit(&project, target_branch_id, commit_oid)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -582,7 +590,7 @@ pub mod commands {
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let project = projects.get(project_id)?;
|
let project = projects.get(project_id)?;
|
||||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||||
VirtualBranchActions.update_commit_message(&project, branch_id, commit_oid, message)?;
|
gitbutler_branch_actions::update_commit_message(&project, branch_id, commit_oid, message)?;
|
||||||
emit_vbranches(&windows, project_id);
|
emit_vbranches(&windows, project_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ use std::{path::PathBuf, sync::Arc};
|
|||||||
|
|
||||||
use super::{events, Change};
|
use super::{events, Change};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use gitbutler_branch_actions::{RemoteBranchFile, VirtualBranchActions, VirtualBranches};
|
use gitbutler_branch_actions::{RemoteBranchFile, VirtualBranches};
|
||||||
use gitbutler_command_context::CommandContext;
|
use gitbutler_command_context::CommandContext;
|
||||||
use gitbutler_diff::DiffByPathMap;
|
use gitbutler_diff::DiffByPathMap;
|
||||||
use gitbutler_error::error::Marker;
|
use gitbutler_error::error::Marker;
|
||||||
@ -106,7 +106,7 @@ impl Handler {
|
|||||||
.projects
|
.projects
|
||||||
.get(project_id)
|
.get(project_id)
|
||||||
.context("failed to get project")?;
|
.context("failed to get project")?;
|
||||||
match VirtualBranchActions.list_virtual_branches_cached(&project, worktree_changes) {
|
match gitbutler_branch_actions::list_virtual_branches_cached(&project, worktree_changes) {
|
||||||
Ok((branches, skipped_files)) => self.emit_app_event(Change::VirtualBranches {
|
Ok((branches, skipped_files)) => self.emit_app_event(Change::VirtualBranches {
|
||||||
project_id: project.id,
|
project_id: project.id,
|
||||||
virtual_branches: VirtualBranches {
|
virtual_branches: VirtualBranches {
|
||||||
@ -142,7 +142,7 @@ impl Handler {
|
|||||||
|
|
||||||
/// Try to emit uncommited files. Swollow errors if they arrise.
|
/// Try to emit uncommited files. Swollow errors if they arrise.
|
||||||
fn emit_uncommited_files(&self, project: &Project) -> Result<DiffByPathMap> {
|
fn emit_uncommited_files(&self, project: &Project) -> Result<DiffByPathMap> {
|
||||||
let files = VirtualBranchActions.get_uncommited_files_reusable(project)?;
|
let files = gitbutler_branch_actions::get_uncommited_files_reusable(project)?;
|
||||||
|
|
||||||
let _ = self.emit_app_event(Change::UncommitedFiles {
|
let _ = self.emit_app_event(Change::UncommitedFiles {
|
||||||
project_id: project.id,
|
project_id: project.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user