Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 41 additions & 53 deletions crates/gitbutler-branch-actions/src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
use crate::{
base::{
get_base_branch_data, set_base_branch, set_target_push_remote, update_base_branch,
BaseBranch,
},
branch_manager::BranchManagerExt,
remote::{get_branch_data, list_remote_branches, RemoteBranch, RemoteBranchData},
VirtualBranchesExt,
};
use anyhow::Result;
use gitbutler_branch::{
BranchOwnershipClaims, {BranchCreateRequest, BranchId, BranchUpdateRequest},
};
use gitbutler_branch::{BranchCreateRequest, BranchId, BranchOwnershipClaims, BranchUpdateRequest};
use gitbutler_command_context::ProjectRepository;
use gitbutler_oplog::{
entry::{OperationKind, SnapshotDetails},
OplogExt, SnapshotExt,
};
use gitbutler_project::{FetchResult, Project};
use gitbutler_reference::ReferenceName;
use gitbutler_reference::{Refname, RemoteRefname};
use gitbutler_reference::{ReferenceName, Refname, RemoteRefname};
use gitbutler_repo::{credentials::Helper, RepoActionsExt, RepositoryExt};
use tracing::instrument;

use super::r#virtual as branch;

use crate::file::RemoteBranchFile;
use crate::{
base::{
get_base_branch_data, set_base_branch, set_target_push_remote, update_base_branch,
BaseBranch,
},
branch_manager::BranchManagerExt,
file::RemoteBranchFile,
remote::{get_branch_data, list_remote_branches, RemoteBranch, RemoteBranchData},
VirtualBranchesExt,
};

#[derive(Clone, Copy, Default)]
pub struct VirtualBranchActions;

impl VirtualBranchActions {
pub async fn create_commit(
pub fn create_commit(
&self,
project: &Project,
branch_id: BranchId,
Expand Down Expand Up @@ -63,7 +59,7 @@ impl VirtualBranchActions {
result
}

pub async fn can_apply_remote_branch(
pub fn can_apply_remote_branch(
&self,
project: &Project,
branch_name: &RemoteRefname,
Expand All @@ -72,7 +68,7 @@ impl VirtualBranchActions {
branch::is_remote_branch_mergeable(&project_repository, branch_name).map_err(Into::into)
}

pub async fn list_virtual_branches(
pub fn list_virtual_branches(
&self,
project: &Project,
) -> Result<(Vec<branch::VirtualBranch>, Vec<gitbutler_diff::FileDiff>)> {
Expand All @@ -83,7 +79,7 @@ impl VirtualBranchActions {
.map_err(Into::into)
}

pub async fn create_virtual_branch(
pub fn create_virtual_branch(
&self,
project: &Project,
create: &BranchCreateRequest,
Expand All @@ -98,12 +94,12 @@ impl VirtualBranchActions {
}

#[instrument(skip(project), err(Debug))]
pub async fn get_base_branch_data(project: &Project) -> Result<BaseBranch> {
pub fn get_base_branch_data(project: &Project) -> Result<BaseBranch> {
let project_repository = ProjectRepository::open(project)?;
get_base_branch_data(&project_repository)
}

pub async fn list_remote_commit_files(
pub fn list_remote_commit_files(
&self,
project: &Project,
commit_oid: git2::Oid,
Expand All @@ -113,7 +109,7 @@ impl VirtualBranchActions {
.map_err(Into::into)
}

pub async fn set_base_branch(
pub fn set_base_branch(
&self,
project: &Project,
target_branch: &RemoteRefname,
Expand All @@ -127,16 +123,12 @@ impl VirtualBranchActions {
set_base_branch(&project_repository, target_branch)
}

pub async fn set_target_push_remote(&self, project: &Project, push_remote: &str) -> Result<()> {
pub fn set_target_push_remote(&self, project: &Project, push_remote: &str) -> Result<()> {
let project_repository = ProjectRepository::open(project)?;
set_target_push_remote(&project_repository, push_remote)
}

pub async fn integrate_upstream_commits(
&self,
project: &Project,
branch_id: BranchId,
) -> Result<()> {
pub fn integrate_upstream_commits(&self, project: &Project, branch_id: BranchId) -> Result<()> {
let project_repository = open_with_verify(project)?;
let mut guard = project.exclusive_worktree_access();
let _ = project_repository.project().create_snapshot(
Expand All @@ -146,7 +138,7 @@ impl VirtualBranchActions {
branch::integrate_upstream_commits(&project_repository, branch_id).map_err(Into::into)
}

pub async fn update_base_branch(&self, project: &Project) -> Result<Vec<ReferenceName>> {
pub fn update_base_branch(&self, project: &Project) -> Result<Vec<ReferenceName>> {
let project_repository = open_with_verify(project)?;
let mut guard = project.exclusive_worktree_access();
let _ = project_repository.project().create_snapshot(
Expand All @@ -156,7 +148,7 @@ impl VirtualBranchActions {
update_base_branch(&project_repository, guard.write_permission()).map_err(Into::into)
}

pub async fn update_virtual_branch(
pub fn update_virtual_branch(
&self,
project: &Project,
branch_update: BranchUpdateRequest,
Expand All @@ -183,18 +175,14 @@ impl VirtualBranchActions {
result?;
Ok(())
}
pub async fn delete_virtual_branch(
&self,
project: &Project,
branch_id: BranchId,
) -> Result<()> {
pub fn delete_virtual_branch(&self, project: &Project, branch_id: BranchId) -> Result<()> {
let project_repository = open_with_verify(project)?;
let branch_manager = project_repository.branch_manager();
let mut guard = project.exclusive_worktree_access();
branch_manager.delete_branch(branch_id, guard.write_permission())
}

pub async fn unapply_ownership(
pub fn unapply_ownership(
&self,
project: &Project,
ownership: &BranchOwnershipClaims,
Expand All @@ -209,7 +197,7 @@ impl VirtualBranchActions {
.map_err(Into::into)
}

pub async fn reset_files(&self, project: &Project, files: &Vec<String>) -> Result<()> {
pub fn reset_files(&self, project: &Project, files: &Vec<String>) -> Result<()> {
let project_repository = open_with_verify(project)?;
let mut guard = project.exclusive_worktree_access();
let _ = project_repository.project().create_snapshot(
Expand All @@ -219,7 +207,7 @@ impl VirtualBranchActions {
branch::reset_files(&project_repository, files).map_err(Into::into)
}

pub async fn amend(
pub fn amend(
&self,
project: &Project,
branch_id: BranchId,
Expand All @@ -235,7 +223,7 @@ impl VirtualBranchActions {
branch::amend(&project_repository, branch_id, commit_oid, ownership)
}

pub async fn move_commit_file(
pub fn move_commit_file(
&self,
project: &Project,
branch_id: BranchId,
Expand All @@ -259,7 +247,7 @@ impl VirtualBranchActions {
.map_err(Into::into)
}

pub async fn undo_commit(
pub fn undo_commit(
&self,
project: &Project,
branch_id: BranchId,
Expand All @@ -283,7 +271,7 @@ impl VirtualBranchActions {
result
}

pub async fn insert_blank_commit(
pub fn insert_blank_commit(
&self,
project: &Project,
branch_id: BranchId,
Expand All @@ -300,7 +288,7 @@ impl VirtualBranchActions {
.map_err(Into::into)
}

pub async fn reorder_commit(
pub fn reorder_commit(
&self,
project: &Project,
branch_id: BranchId,
Expand All @@ -317,7 +305,7 @@ impl VirtualBranchActions {
.map_err(Into::into)
}

pub async fn reset_virtual_branch(
pub fn reset_virtual_branch(
&self,
project: &Project,
branch_id: BranchId,
Expand All @@ -332,7 +320,7 @@ impl VirtualBranchActions {
branch::reset_branch(&project_repository, branch_id, target_commit_oid).map_err(Into::into)
}

pub async fn convert_to_real_branch(
pub fn convert_to_real_branch(
&self,
project: &Project,
branch_id: BranchId,
Expand All @@ -356,7 +344,7 @@ impl VirtualBranchActions {
result
}

pub async fn push_virtual_branch(
pub fn push_virtual_branch(
&self,
project: &Project,
branch_id: BranchId,
Expand All @@ -368,12 +356,12 @@ impl VirtualBranchActions {
branch::push(&project_repository, branch_id, with_force, &helper, askpass)
}

pub async fn list_remote_branches(project: Project) -> Result<Vec<RemoteBranch>> {
pub fn list_remote_branches(project: Project) -> Result<Vec<RemoteBranch>> {
let project_repository = ProjectRepository::open(&project)?;
list_remote_branches(&project_repository)
}

pub async fn get_remote_branch_data(
pub fn get_remote_branch_data(
&self,
project: &Project,
refname: &Refname,
Expand All @@ -382,7 +370,7 @@ impl VirtualBranchActions {
get_branch_data(&project_repository, refname)
}

pub async fn squash(
pub fn squash(
&self,
project: &Project,
branch_id: BranchId,
Expand All @@ -397,7 +385,7 @@ impl VirtualBranchActions {
branch::squash(&project_repository, branch_id, commit_oid).map_err(Into::into)
}

pub async fn update_commit_message(
pub fn update_commit_message(
&self,
project: &Project,
branch_id: BranchId,
Expand All @@ -414,7 +402,7 @@ impl VirtualBranchActions {
.map_err(Into::into)
}

pub async fn fetch_from_remotes(
pub fn fetch_from_remotes(
&self,
project: &Project,
askpass: Option<String>,
Expand Down Expand Up @@ -446,7 +434,7 @@ impl VirtualBranchActions {
Ok(project_data_last_fetched)
}

pub async fn move_commit(
pub fn move_commit(
&self,
project: &Project,
target_branch_id: BranchId,
Expand All @@ -461,7 +449,7 @@ impl VirtualBranchActions {
branch::move_commit(&project_repository, target_branch_id, commit_oid).map_err(Into::into)
}

pub async fn create_virtual_branch_from_branch(
pub fn create_virtual_branch_from_branch(
&self,
project: &Project,
branch: &Refname,
Expand Down
37 changes: 17 additions & 20 deletions crates/gitbutler-branch-actions/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@ use std::{path::Path, time};

use anyhow::{anyhow, Context, Result};
use git2::Index;
use gitbutler_branch::Branch;
use gitbutler_branch::BranchOwnershipClaims;
use gitbutler_branch::Target;
use gitbutler_branch::VirtualBranchesHandle;
use gitbutler_branch::{self, BranchId};
use gitbutler_branch::{
self, Branch, BranchId, BranchOwnershipClaims, Target, VirtualBranchesHandle,
GITBUTLER_INTEGRATION_REFERENCE,
};
use gitbutler_command_context::ProjectRepository;
use gitbutler_project::FetchResult;
use gitbutler_reference::ReferenceName;
use gitbutler_reference::{Refname, RemoteRefname};
use gitbutler_repo::{LogUntil, RepoActionsExt, RepositoryExt};
use gitbutler_error::error::Marker;
use gitbutler_project::{access::WorktreeWritePermission, FetchResult};
use gitbutler_reference::{ReferenceName, Refname, RemoteRefname};
use gitbutler_repo::{rebase::cherry_rebase, LogUntil, RepoActionsExt, RepositoryExt};
use serde::Serialize;

use crate::branch_manager::BranchManagerExt;
use crate::conflicts::RepoConflictsExt;
use crate::hunk::VirtualBranchHunk;
use crate::integration::update_gitbutler_integration;
use crate::remote::{commit_to_remote_commit, RemoteCommit};
use crate::status::get_applied_status;
use crate::VirtualBranchesExt;
use gitbutler_branch::GITBUTLER_INTEGRATION_REFERENCE;
use gitbutler_error::error::Marker;
use gitbutler_project::access::WorktreeWritePermission;
use gitbutler_repo::rebase::cherry_rebase;
use crate::{
branch_manager::BranchManagerExt,
conflicts::RepoConflictsExt,
hunk::VirtualBranchHunk,
integration::update_gitbutler_integration,
remote::{commit_to_remote_commit, RemoteCommit},
status::get_applied_status,
VirtualBranchesExt,
};

#[derive(Debug, Serialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
Expand Down
27 changes: 12 additions & 15 deletions crates/gitbutler-branch-actions/src/branch.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
use std::cmp::max;
use std::collections::HashMap;
use std::collections::HashSet;
use std::vec;
use std::{
cmp::max,
collections::{HashMap, HashSet},
vec,
};

use anyhow::Context;
use anyhow::Result;
use anyhow::{Context, Result};
use bstr::{BString, ByteSlice};
use gitbutler_branch::Branch as GitButlerBranch;
use gitbutler_branch::BranchId;
use gitbutler_branch::ReferenceExt;
use gitbutler_branch::Target;
use gitbutler_branch::VirtualBranchesHandle;
use gitbutler_branch::{
Branch as GitButlerBranch, BranchId, ReferenceExt, Target, VirtualBranchesHandle,
};
use gitbutler_command_context::ProjectRepository;

use crate::{VirtualBranch, VirtualBranchesExt};
use gitbutler_reference::normalize_branch_name;
use gitbutler_repo::RepoActionsExt;
use itertools::Itertools;
use serde::Deserialize;
use serde::Serialize;
use serde::{Deserialize, Serialize};

use crate::{VirtualBranch, VirtualBranchesExt};

/// Returns a list of branches associated with this project.
pub fn list_branches(
Expand Down
Loading