diff options
Diffstat (limited to 'src/git_remote_helper.rs')
| -rw-r--r-- | src/git_remote_helper.rs | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs index 657f992..a930617 100644 --- a/src/git_remote_helper.rs +++ b/src/git_remote_helper.rs | |||
| @@ -564,7 +564,6 @@ fn create_rejected_refspecs_and_remotes_refspecs( | |||
| 564 | refspecs_for_remote.push(format!("+{refspec}")); | 564 | refspecs_for_remote.push(format!("+{refspec}")); |
| 565 | } | 565 | } |
| 566 | } | 566 | } |
| 567 | // TODO do we need to force push to this remote? | ||
| 568 | } else if let Ok(remote_value_tip) = | 567 | } else if let Ok(remote_value_tip) = |
| 569 | git_repo.get_commit_or_tip_of_reference(remote_value) | 568 | git_repo.get_commit_or_tip_of_reference(remote_value) |
| 570 | { | 569 | { |
| @@ -574,26 +573,36 @@ fn create_rejected_refspecs_and_remotes_refspecs( | |||
| 574 | format!("{short_name} {to} already up-to-date").as_str(), | 573 | format!("{short_name} {to} already up-to-date").as_str(), |
| 575 | )?; | 574 | )?; |
| 576 | } | 575 | } |
| 577 | let nostr_value_tip = | 576 | let (ahead_of_local, behind_local) = |
| 578 | git_repo.get_commit_or_tip_of_reference(nostr_value)?; | 577 | git_repo.get_commits_ahead_behind(&from_tip, &remote_value_tip)?; |
| 579 | let (ahead, behind) = git_repo | 578 | if ahead_of_local.is_empty() { |
| 580 | .get_commits_ahead_behind(&remote_value_tip, &nostr_value_tip)?; | ||
| 581 | if behind.is_empty() { | ||
| 582 | // can soft push | 579 | // can soft push |
| 583 | refspecs_for_remote.push(refspec.clone()); | 580 | refspecs_for_remote.push(refspec.clone()); |
| 584 | } else { | 581 | } else { |
| 585 | // cant soft push | 582 | // cant soft push |
| 586 | rejected_refspecs | 583 | let (ahead_of_nostr, behind_nostr) = git_repo |
| 587 | .entry(refspec.to_string()) | 584 | .get_commits_ahead_behind( |
| 588 | .and_modify(|a| a.push(url.to_string())) | 585 | &git_repo.get_commit_or_tip_of_reference(nostr_value)?, |
| 589 | .or_insert(vec![url.to_string()]); | 586 | &remote_value_tip, |
| 590 | term.write_line( | 587 | )?; |
| 591 | format!( | 588 | if ahead_of_nostr.is_empty() { |
| 592 | "ERROR: {short_name} {to} conflicts with nostr ({} ahead {} behind). either:\r\n 1. pull from that git server and resolve\r\n 2. force push your branch to the git server before pushing to nostr remote", | 589 | // ancestor of nostr and we are force pushing anyway... |
| 593 | ahead.len(), | 590 | refspecs_for_remote.push(refspec.clone()); |
| 594 | behind.len(), | 591 | } else { |
| 595 | ).as_str(), | 592 | rejected_refspecs |
| 596 | )?; | 593 | .entry(refspec.to_string()) |
| 594 | .and_modify(|a| a.push(url.to_string())) | ||
| 595 | .or_insert(vec![url.to_string()]); | ||
| 596 | term.write_line( | ||
| 597 | format!( | ||
| 598 | "ERROR: {short_name} {to} conflicts with nostr ({} ahead {} behind) and local ({} ahead {} behind). either:\r\n 1. pull from that git server and resolve\r\n 2. force push your branch to the git server before pushing to nostr remote", | ||
| 599 | ahead_of_nostr.len(), | ||
| 600 | behind_nostr.len(), | ||
| 601 | ahead_of_local.len(), | ||
| 602 | behind_local.len(), | ||
| 603 | ).as_str(), | ||
| 604 | )?; | ||
| 605 | } | ||
| 597 | }; | 606 | }; |
| 598 | } else { | 607 | } else { |
| 599 | // remote_value oid is not present locally | 608 | // remote_value oid is not present locally |
| @@ -624,7 +633,7 @@ fn create_rejected_refspecs_and_remotes_refspecs( | |||
| 624 | if let Ok(remote_value_tip) = git_repo.get_commit_or_tip_of_reference(remote_value) | 633 | if let Ok(remote_value_tip) = git_repo.get_commit_or_tip_of_reference(remote_value) |
| 625 | { | 634 | { |
| 626 | let (ahead, behind) = | 635 | let (ahead, behind) = |
| 627 | git_repo.get_commits_ahead_behind(&remote_value_tip, &from_tip)?; | 636 | git_repo.get_commits_ahead_behind(&from_tip, &remote_value_tip)?; |
| 628 | if behind.is_empty() { | 637 | if behind.is_empty() { |
| 629 | // can soft push | 638 | // can soft push |
| 630 | refspecs_for_remote.push(refspec.clone()); | 639 | refspecs_for_remote.push(refspec.clone()); |