Skip to content

Commit b73feed

Browse files
committed
Remove unused and kinda borked cherry_commit code
1 parent e42c2be commit b73feed

File tree

7 files changed

+0
-631
lines changed

7 files changed

+0
-631
lines changed

app/src/lib/vbranches/branchController.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -291,25 +291,6 @@ You can find them in the 'Branches' sidebar in order to resolve conflicts.`;
291291
}
292292
}
293293

294-
async cherryPick(branchId: string, targetCommitOid: string) {
295-
try {
296-
await invoke<void>('cherry_pick_onto_virtual_branch', {
297-
projectId: this.projectId,
298-
branchId,
299-
targetCommitOid
300-
});
301-
} catch (err: any) {
302-
// TODO: Probably we wanna have error code checking in a more generic way
303-
if (err.code === 'errors.commit.signing_failed') {
304-
showSignError(err);
305-
} else {
306-
showError('Failed to cherry-pick commit', err);
307-
}
308-
} finally {
309-
this.targetBranchService.reload();
310-
}
311-
}
312-
313294
async markResolved(path: string) {
314295
try {
315296
await invoke<void>('mark_resolved', { projectId: this.projectId, path });

crates/gitbutler-core/src/virtual_branches/controller.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,6 @@ impl Controller {
321321
.await
322322
}
323323

324-
pub async fn cherry_pick(
325-
&self,
326-
project_id: ProjectId,
327-
branch_id: BranchId,
328-
commit_oid: git2::Oid,
329-
) -> Result<Option<git2::Oid>> {
330-
self.inner(project_id)
331-
.await
332-
.cherry_pick(project_id, branch_id, commit_oid)
333-
.await
334-
}
335-
336324
pub async fn list_remote_branches(
337325
&self,
338326
project_id: ProjectId,
@@ -818,22 +806,6 @@ impl ControllerInner {
818806
.await?
819807
}
820808

821-
pub async fn cherry_pick(
822-
&self,
823-
project_id: ProjectId,
824-
branch_id: BranchId,
825-
commit_oid: git2::Oid,
826-
) -> Result<Option<git2::Oid>> {
827-
let _permit = self.semaphore.acquire().await;
828-
829-
self.with_verify_branch(project_id, |project_repository, _| {
830-
let _ = project_repository
831-
.project()
832-
.create_snapshot(SnapshotDetails::new(OperationKind::CherryPick));
833-
super::cherry_pick(project_repository, branch_id, commit_oid).map_err(Into::into)
834-
})
835-
}
836-
837809
pub fn list_remote_branches(&self, project_id: ProjectId) -> Result<Vec<super::RemoteBranch>> {
838810
let project = self.projects.get(project_id)?;
839811
let project_repository = project_repository::Repository::open(&project)?;

crates/gitbutler-core/src/virtual_branches/virtual.rs

Lines changed: 0 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,185 +3213,6 @@ pub fn undo_commit(
32133213
Ok(())
32143214
}
32153215

3216-
pub fn cherry_pick(
3217-
project_repository: &project_repository::Repository,
3218-
branch_id: BranchId,
3219-
target_commit_id: git2::Oid,
3220-
) -> Result<Option<git2::Oid>> {
3221-
project_repository.assure_unconflicted()?;
3222-
3223-
let vb_state = project_repository.project().virtual_branches();
3224-
3225-
let mut branch = vb_state
3226-
.get_branch(branch_id)
3227-
.context("failed to read branch")?;
3228-
3229-
if !branch.applied {
3230-
// todo?
3231-
bail!("can not cherry pick a branch that is not applied")
3232-
}
3233-
3234-
let target_commit = project_repository
3235-
.repo()
3236-
.find_commit(target_commit_id)
3237-
.map_err(|err| match err {
3238-
err if err.code() == git2::ErrorCode::NotFound => {
3239-
anyhow!("commit {target_commit_id} not found ")
3240-
}
3241-
err => err.into(),
3242-
})?;
3243-
3244-
let branch_head_commit = project_repository
3245-
.repo()
3246-
.find_commit(branch.head)
3247-
.context("failed to find branch tree")?;
3248-
3249-
let default_target = vb_state.get_default_target()?;
3250-
3251-
// if any other branches are applied, unapply them
3252-
let applied_branches = vb_state
3253-
.list_branches()
3254-
.context("failed to read virtual branches")?
3255-
.into_iter()
3256-
.filter(|b| b.applied)
3257-
.collect::<Vec<_>>();
3258-
3259-
let integration_commit_id = get_workspace_head(&vb_state, project_repository)?;
3260-
3261-
let (applied_statuses, _) = get_applied_status(
3262-
project_repository,
3263-
&integration_commit_id,
3264-
&default_target.sha,
3265-
applied_branches,
3266-
)?;
3267-
3268-
let branch_files = applied_statuses
3269-
.iter()
3270-
.find(|(b, _)| b.id == branch_id)
3271-
.map(|(_, f)| f)
3272-
.context("branch status not found")?;
3273-
3274-
// create a wip commit. we'll use it to offload cherrypick conflicts calculation to libgit.
3275-
let wip_commit = {
3276-
let wip_tree_oid = write_tree(project_repository, &branch.head, branch_files)?;
3277-
let wip_tree = project_repository
3278-
.repo()
3279-
.find_tree(wip_tree_oid)
3280-
.context("failed to find tree")?;
3281-
3282-
let signature = git2::Signature::now("GitButler", "gitbutler@gitbutler.com")
3283-
.context("failed to make gb signature")?;
3284-
let oid = project_repository
3285-
.repo()
3286-
.commit_with_signature(
3287-
None,
3288-
&signature,
3289-
&signature,
3290-
"wip cherry picking commit",
3291-
&wip_tree,
3292-
&[&branch_head_commit],
3293-
None,
3294-
)
3295-
.context("failed to commit wip work")?;
3296-
project_repository
3297-
.repo()
3298-
.find_commit(oid)
3299-
.context("failed to find wip commit")?
3300-
};
3301-
3302-
let mut cherrypick_index = project_repository
3303-
.repo()
3304-
.cherrypick_commit(&target_commit, &wip_commit, 0, None)
3305-
.context("failed to cherry pick")?;
3306-
3307-
// unapply other branches
3308-
for other_branch in applied_statuses
3309-
.iter()
3310-
.filter(|(b, _)| b.id != branch.id)
3311-
.map(|(b, _)| b)
3312-
{
3313-
convert_to_real_branch(project_repository, other_branch.id, Default::default())
3314-
.context("failed to unapply branch")?;
3315-
}
3316-
3317-
let commit_oid = if cherrypick_index.has_conflicts() {
3318-
// checkout the conflicts
3319-
project_repository
3320-
.repo()
3321-
.checkout_index_builder(&mut cherrypick_index)
3322-
.allow_conflicts()
3323-
.conflict_style_merge()
3324-
.force()
3325-
.checkout()
3326-
.context("failed to checkout conflicts")?;
3327-
3328-
// mark conflicts
3329-
let conflicts = cherrypick_index
3330-
.conflicts()
3331-
.context("failed to get conflicts")?;
3332-
let mut merge_conflicts = Vec::new();
3333-
for path in conflicts.flatten() {
3334-
if let Some(ours) = path.our {
3335-
let path = std::str::from_utf8(&ours.path)
3336-
.context("failed to convert path")?
3337-
.to_string();
3338-
merge_conflicts.push(path);
3339-
}
3340-
}
3341-
conflicts::mark(project_repository, &merge_conflicts, Some(branch.head))?;
3342-
3343-
None
3344-
} else {
3345-
let merge_tree_oid = cherrypick_index
3346-
.write_tree_to(project_repository.repo())
3347-
.context("failed to write merge tree")?;
3348-
let merge_tree = project_repository
3349-
.repo()
3350-
.find_tree(merge_tree_oid)
3351-
.context("failed to find merge tree")?;
3352-
3353-
let branch_head_commit = project_repository
3354-
.repo()
3355-
.find_commit(branch.head)
3356-
.context("failed to find branch head commit")?;
3357-
3358-
let change_id = target_commit.change_id();
3359-
let commit_oid = project_repository
3360-
.repo()
3361-
.commit_with_signature(
3362-
None,
3363-
&target_commit.author(),
3364-
&target_commit.committer(),
3365-
&target_commit.message_bstr().to_str_lossy(),
3366-
&merge_tree,
3367-
&[&branch_head_commit],
3368-
change_id.as_deref(),
3369-
)
3370-
.context("failed to create commit")?;
3371-
3372-
// checkout final_tree into the working directory
3373-
project_repository
3374-
.repo()
3375-
.checkout_tree_builder(&merge_tree)
3376-
.force()
3377-
.remove_untracked()
3378-
.checkout()
3379-
.context("failed to checkout final tree")?;
3380-
3381-
// update branch status
3382-
branch.head = commit_oid;
3383-
branch.updated_timestamp_ms = crate::time::now_ms();
3384-
vb_state.set_branch(branch.clone())?;
3385-
3386-
Some(commit_oid)
3387-
};
3388-
3389-
super::integration::update_gitbutler_integration(&vb_state, project_repository)
3390-
.context("failed to update gitbutler integration")?;
3391-
3392-
Ok(commit_oid)
3393-
}
3394-
33953216
/// squashes a commit from a virtual branch into its parent.
33963217
pub fn squash(
33973218
project_repository: &project_repository::Repository,

0 commit comments

Comments
 (0)