diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-28 13:25:33 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-28 13:25:33 +0100 |
| commit | b8867ef59589c56ae93139a9506516b52bb5f47c (patch) | |
| tree | 841745f3e27f812eddece8780c243f8ad4e9ab7a /src/git_remote_helper.rs | |
| parent | 04ecf3d8335a263a0c3e644fc324e9cc00c1f02d (diff) | |
fix(remote): only update ref when `push` succeeds
only update remote ref when push was successful
Diffstat (limited to 'src/git_remote_helper.rs')
| -rw-r--r-- | src/git_remote_helper.rs | 23 |
1 files changed, 13 insertions, 10 deletions
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( | |||
| 165 | stdin: &Stdin, | 165 | stdin: &Stdin, |
| 166 | initial_refspec: &str, | 166 | initial_refspec: &str, |
| 167 | ) -> Result<()> { | 167 | ) -> Result<()> { |
| 168 | let refspecs = get_refspecs_from_push_batch(stdin, initial_refspec)?; | ||
| 168 | let auth = GitAuthenticator::default(); | 169 | let auth = GitAuthenticator::default(); |
| 169 | let git_config = git_repo.config()?; | 170 | let git_config = git_repo.config()?; |
| 170 | let mut push_options = git2::PushOptions::new(); | 171 | let mut push_options = git2::PushOptions::new(); |
| @@ -174,26 +175,28 @@ fn push( | |||
| 174 | if let Some(error) = error { | 175 | if let Some(error) = error { |
| 175 | println!("error {name} {error}"); | 176 | println!("error {name} {error}"); |
| 176 | } else { | 177 | } else { |
| 178 | if let Some(refspec) = refspecs | ||
| 179 | .iter() | ||
| 180 | .find(|r| r.contains(format!(":{name}").as_str())) | ||
| 181 | { | ||
| 182 | if let Err(e) = update_remote_refs_pushed(git_repo, refspec, nostr_url) | ||
| 183 | .context("could not update remote_ref locally") | ||
| 184 | { | ||
| 185 | return Err(git2::Error::from_str(e.to_string().as_str())); | ||
| 186 | } | ||
| 187 | } | ||
| 177 | println!("ok {name}",); | 188 | println!("ok {name}",); |
| 178 | } | 189 | } |
| 179 | Ok(()) | 190 | Ok(()) |
| 180 | }); | 191 | }); |
| 181 | push_options.remote_callbacks(remote_callbacks); | 192 | push_options.remote_callbacks(remote_callbacks); |
| 182 | temp_remote.push( | 193 | temp_remote.push(&refspecs, Some(&mut push_options))?; |
| 183 | &get_refspecs_from_push_batch(stdin, initial_refspec)?, | ||
| 184 | Some(&mut push_options), | ||
| 185 | )?; | ||
| 186 | update_remote_refs_from_push_refspecs(git_repo, initial_refspec, nostr_url)?; | ||
| 187 | temp_remote.disconnect()?; | 194 | temp_remote.disconnect()?; |
| 188 | println!(); | 195 | println!(); |
| 189 | Ok(()) | 196 | Ok(()) |
| 190 | } | 197 | } |
| 191 | 198 | ||
| 192 | fn update_remote_refs_from_push_refspecs( | 199 | fn update_remote_refs_pushed(git_repo: &Repository, refspec: &str, url: &str) -> Result<()> { |
| 193 | git_repo: &Repository, | ||
| 194 | refspec: &str, | ||
| 195 | url: &str, | ||
| 196 | ) -> Result<()> { | ||
| 197 | if !refspec.contains(':') { | 200 | if !refspec.contains(':') { |
| 198 | bail!( | 201 | bail!( |
| 199 | "refspec should contain a colon (:) but consists of: {}", | 202 | "refspec should contain a colon (:) but consists of: {}", |