From 9f1d8cd964a04197565a2acb1f2b174c9582d333 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 22 Feb 2024 16:18:44 +0000 Subject: fix: applying commits that exist in other branches previously these commits would be skipped --- src/git.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/git.rs') diff --git a/src/git.rs b/src/git.rs index 41d68c7..b44390b 100644 --- a/src/git.rs +++ b/src/git.rs @@ -370,13 +370,16 @@ impl RepoActions for Repo { branch_name: &str, patch_and_ancestors: Vec, ) -> Result> { - // filter out existing ancestors + let branch_tip = self.get_tip_of_local_branch(branch_name)?; + // filter out existing ancestors in branch let mut patches_to_apply: Vec = patch_and_ancestors .into_iter() .filter(|e| { - !self - .does_commit_exist(&get_commit_id_from_patch(e).unwrap()) - .unwrap() + let commit_id = get_commit_id_from_patch(e).unwrap(); + !branch_tip.to_string().eq(&commit_id) + || !self + .ancestor_of(&branch_tip, &str_to_sha1(&commit_id).unwrap()) + .unwrap() }) .collect(); @@ -395,16 +398,6 @@ impl RepoActions for Repo { bail!("cannot find parent commit ({parent_commit_id}). run git pull and try again.") } - // check for rebase or changes - if let Ok(current_tip) = self.get_tip_of_local_branch(branch_name) { - if !current_tip.to_string().eq(&parent_commit_id) { - // TODO: either changes have been made on the local branch or - // the latest commit in the prpoosal has rebased onto a newer - // commit that you havn't pulled yet ask user - // whether they want to proceed - } - } - // checkout branch if !self.get_checked_out_branch_name()?.eq(&branch_name) { self.create_branch_at_commit(branch_name, &parent_commit_id)?; @@ -415,7 +408,13 @@ impl RepoActions for Repo { patches_to_apply.reverse(); for patch in &patches_to_apply { - apply_patch(self, patch)?; + let commit_id = get_commit_id_from_patch(patch)?; + // only create new commits - otherwise make them the tip + if self.does_commit_exist(&commit_id)? { + self.create_branch_at_commit(branch_name, &commit_id)?; + } else { + apply_patch(self, patch)?; + } } Ok(patches_to_apply) } -- cgit v1.2.3