diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 16:18:44 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 16:18:44 +0000 |
| commit | 9f1d8cd964a04197565a2acb1f2b174c9582d333 (patch) | |
| tree | 03ef4536994de203b15104043a819875fd87acc1 /src/git.rs | |
| parent | ce3cdd0039be0cf0543ac0937b5d6c06bb69891b (diff) | |
fix: applying commits that exist in other branches
previously these commits would be skipped
Diffstat (limited to 'src/git.rs')
| -rw-r--r-- | src/git.rs | 29 |
1 files changed, 14 insertions, 15 deletions
| @@ -370,13 +370,16 @@ impl RepoActions for Repo { | |||
| 370 | branch_name: &str, | 370 | branch_name: &str, |
| 371 | patch_and_ancestors: Vec<nostr::Event>, | 371 | patch_and_ancestors: Vec<nostr::Event>, |
| 372 | ) -> Result<Vec<nostr::Event>> { | 372 | ) -> Result<Vec<nostr::Event>> { |
| 373 | // filter out existing ancestors | 373 | let branch_tip = self.get_tip_of_local_branch(branch_name)?; |
| 374 | // filter out existing ancestors in branch | ||
| 374 | let mut patches_to_apply: Vec<nostr::Event> = patch_and_ancestors | 375 | let mut patches_to_apply: Vec<nostr::Event> = patch_and_ancestors |
| 375 | .into_iter() | 376 | .into_iter() |
| 376 | .filter(|e| { | 377 | .filter(|e| { |
| 377 | !self | 378 | let commit_id = get_commit_id_from_patch(e).unwrap(); |
| 378 | .does_commit_exist(&get_commit_id_from_patch(e).unwrap()) | 379 | !branch_tip.to_string().eq(&commit_id) |
| 379 | .unwrap() | 380 | || !self |
| 381 | .ancestor_of(&branch_tip, &str_to_sha1(&commit_id).unwrap()) | ||
| 382 | .unwrap() | ||
| 380 | }) | 383 | }) |
| 381 | .collect(); | 384 | .collect(); |
| 382 | 385 | ||
| @@ -395,16 +398,6 @@ impl RepoActions for Repo { | |||
| 395 | bail!("cannot find parent commit ({parent_commit_id}). run git pull and try again.") | 398 | bail!("cannot find parent commit ({parent_commit_id}). run git pull and try again.") |
| 396 | } | 399 | } |
| 397 | 400 | ||
| 398 | // check for rebase or changes | ||
| 399 | if let Ok(current_tip) = self.get_tip_of_local_branch(branch_name) { | ||
| 400 | if !current_tip.to_string().eq(&parent_commit_id) { | ||
| 401 | // TODO: either changes have been made on the local branch or | ||
| 402 | // the latest commit in the prpoosal has rebased onto a newer | ||
| 403 | // commit that you havn't pulled yet ask user | ||
| 404 | // whether they want to proceed | ||
| 405 | } | ||
| 406 | } | ||
| 407 | |||
| 408 | // checkout branch | 401 | // checkout branch |
| 409 | if !self.get_checked_out_branch_name()?.eq(&branch_name) { | 402 | if !self.get_checked_out_branch_name()?.eq(&branch_name) { |
| 410 | self.create_branch_at_commit(branch_name, &parent_commit_id)?; | 403 | self.create_branch_at_commit(branch_name, &parent_commit_id)?; |
| @@ -415,7 +408,13 @@ impl RepoActions for Repo { | |||
| 415 | patches_to_apply.reverse(); | 408 | patches_to_apply.reverse(); |
| 416 | 409 | ||
| 417 | for patch in &patches_to_apply { | 410 | for patch in &patches_to_apply { |
| 418 | apply_patch(self, patch)?; | 411 | let commit_id = get_commit_id_from_patch(patch)?; |
| 412 | // only create new commits - otherwise make them the tip | ||
| 413 | if self.does_commit_exist(&commit_id)? { | ||
| 414 | self.create_branch_at_commit(branch_name, &commit_id)?; | ||
| 415 | } else { | ||
| 416 | apply_patch(self, patch)?; | ||
| 417 | } | ||
| 419 | } | 418 | } |
| 420 | Ok(patches_to_apply) | 419 | Ok(patches_to_apply) |
| 421 | } | 420 | } |