Skip to content

Commit 7f731d4

Browse files
committed
Use push_update_reference to learn of failed pushes
1 parent c214e9c commit 7f731d4

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ s3 = { path = "src/s3" }
2020
migrate = { path = "src/migrate" }
2121
rand = "0.3"
2222
time = "0.1"
23-
git2 = "0.6"
23+
git2 = "0.6.4"
2424
flate2 = "0.2"
2525
semver = "0.5"
2626
url = "1.2.1"

src/git.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,24 @@ fn commit_and_push<F>(repo: &git2::Repository, mut f: F) -> CargoResult<()>
131131
try!(repo.commit(Some("HEAD"), &sig, &sig, &msg, &tree, &[&parent]));
132132

133133
// git push
134-
let mut callbacks = git2::RemoteCallbacks::new();
135-
callbacks.credentials(credentials);
134+
let mut ref_status = None;
136135
let mut origin = try!(repo.find_remote("origin"));
137-
let mut opts = git2::PushOptions::new();
138-
opts.remote_callbacks(callbacks);
139-
match origin.push(&["refs/heads/master"], Some(&mut opts)) {
140-
Ok(()) => return Ok(()),
141-
Err(..) => {}
136+
let res = {
137+
let mut callbacks = git2::RemoteCallbacks::new();
138+
callbacks.credentials(credentials);
139+
callbacks.push_update_reference(|refname, status| {
140+
assert_eq!(refname, "refs/heads/master");
141+
ref_status = status.map(|s| s.to_string());
142+
Ok(())
143+
});
144+
let mut opts = git2::PushOptions::new();
145+
opts.remote_callbacks(callbacks);
146+
origin.push(&["refs/heads/master"], Some(&mut opts))
147+
};
148+
match res {
149+
Ok(()) if ref_status.is_none() => return Ok(()),
150+
Ok(()) => info!("failed to push a ref: {:?}", ref_status),
151+
Err(e) => info!("failure to push: {}", e),
142152
}
143153

144154
let mut callbacks = git2::RemoteCallbacks::new();

0 commit comments

Comments
 (0)