From b8867ef59589c56ae93139a9506516b52bb5f47c Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Sun, 28 Jul 2024 13:25:33 +0100 Subject: fix(remote): only update ref when `push` succeeds only update remote ref when push was successful --- src/git_remote_helper.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs index 71dc7e1..793e714 100644 --- a/src/git_remote_helper.rs +++ b/src/git_remote_helper.rs @@ -165,6 +165,7 @@ fn push( stdin: &Stdin, initial_refspec: &str, ) -> Result<()> { + let refspecs = get_refspecs_from_push_batch(stdin, initial_refspec)?; let auth = GitAuthenticator::default(); let git_config = git_repo.config()?; let mut push_options = git2::PushOptions::new(); @@ -174,26 +175,28 @@ fn push( if let Some(error) = error { println!("error {name} {error}"); } else { + if let Some(refspec) = refspecs + .iter() + .find(|r| r.contains(format!(":{name}").as_str())) + { + if let Err(e) = update_remote_refs_pushed(git_repo, refspec, nostr_url) + .context("could not update remote_ref locally") + { + return Err(git2::Error::from_str(e.to_string().as_str())); + } + } println!("ok {name}",); } Ok(()) }); push_options.remote_callbacks(remote_callbacks); - temp_remote.push( - &get_refspecs_from_push_batch(stdin, initial_refspec)?, - Some(&mut push_options), - )?; - update_remote_refs_from_push_refspecs(git_repo, initial_refspec, nostr_url)?; + temp_remote.push(&refspecs, Some(&mut push_options))?; temp_remote.disconnect()?; println!(); Ok(()) } -fn update_remote_refs_from_push_refspecs( - git_repo: &Repository, - refspec: &str, - url: &str, -) -> Result<()> { +fn update_remote_refs_pushed(git_repo: &Repository, refspec: &str, url: &str) -> Result<()> { if !refspec.contains(':') { bail!( "refspec should contain a colon (:) but consists of: {}", -- cgit v1.2.3