Skip to content

Commit

Permalink
fix(remote): push when server is ahead of nostr
Browse files Browse the repository at this point in the history
but behind local.

correctly report on situation and allow push
  • Loading branch information
DanConwayDev committed Aug 5, 2024
1 parent b683047 commit 92e378f
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/git_remote_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ fn create_rejected_refspecs_and_remotes_refspecs(
refspecs_for_remote.push(format!("+{refspec}"));
}
}
// TODO do we need to force push to this remote?
} else if let Ok(remote_value_tip) =
git_repo.get_commit_or_tip_of_reference(remote_value)
{
Expand All @@ -574,26 +573,36 @@ fn create_rejected_refspecs_and_remotes_refspecs(
format!("{short_name} {to} already up-to-date").as_str(),
)?;
}
let nostr_value_tip =
git_repo.get_commit_or_tip_of_reference(nostr_value)?;
let (ahead, behind) = git_repo
.get_commits_ahead_behind(&remote_value_tip, &nostr_value_tip)?;
if behind.is_empty() {
let (ahead_of_local, behind_local) =
git_repo.get_commits_ahead_behind(&from_tip, &remote_value_tip)?;
if ahead_of_local.is_empty() {
// can soft push
refspecs_for_remote.push(refspec.clone());
} else {
// cant soft push
rejected_refspecs
.entry(refspec.to_string())
.and_modify(|a| a.push(url.to_string()))
.or_insert(vec![url.to_string()]);
term.write_line(
format!(
"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",
ahead.len(),
behind.len(),
).as_str(),
)?;
let (ahead_of_nostr, behind_nostr) = git_repo
.get_commits_ahead_behind(
&git_repo.get_commit_or_tip_of_reference(nostr_value)?,
&remote_value_tip,
)?;
if ahead_of_nostr.is_empty() {
// ancestor of nostr and we are force pushing anyway...
refspecs_for_remote.push(refspec.clone());
} else {
rejected_refspecs
.entry(refspec.to_string())
.and_modify(|a| a.push(url.to_string()))
.or_insert(vec![url.to_string()]);
term.write_line(
format!(
"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",
ahead_of_nostr.len(),
behind_nostr.len(),
ahead_of_local.len(),
behind_local.len(),
).as_str(),
)?;
}
};
} else {
// remote_value oid is not present locally
Expand Down Expand Up @@ -624,7 +633,7 @@ fn create_rejected_refspecs_and_remotes_refspecs(
if let Ok(remote_value_tip) = git_repo.get_commit_or_tip_of_reference(remote_value)
{
let (ahead, behind) =
git_repo.get_commits_ahead_behind(&remote_value_tip, &from_tip)?;
git_repo.get_commits_ahead_behind(&from_tip, &remote_value_tip)?;
if behind.is_empty() {
// can soft push
refspecs_for_remote.push(refspec.clone());
Expand Down

0 comments on commit 92e378f

Please sign in to comment.