Skip to content

Commit

Permalink
Handle I/O errors gracefully on push.
Browse files Browse the repository at this point in the history
If connection to upstream is hosed, consider nothing to have been
pushed.

fix #338
  • Loading branch information
Taylor R Campbell committed Dec 9, 2024
1 parent 5595234 commit 718cd34
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
35 changes: 19 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4845,25 +4845,28 @@ fn remote_helper_push(
let response = conn.unbundle(heads, file);
match response {
UnbundleResponse::Bundlev2(data) => {
let mut bundle = BundleReader::new(data).unwrap();
while let Some(part) = bundle.next_part().unwrap() {
match part.part_type.as_bytes() {
b"reply:changegroup" => {
// TODO: should check in-reply-to param.
let response = part.get_param("return").unwrap();
result = u32::from_str(response).ok();
}
b"error:abort" => {
let mut message =
part.get_param("message").unwrap().to_string();
if let Some(hint) = part.get_param("hint") {
message.push_str("\n\n");
message.push_str(hint);
if let Ok(mut bundle) = BundleReader::new(data) {
while let Ok(Some(part)) = bundle.next_part() {
match part.part_type.as_bytes() {
b"reply:changegroup" => {
// TODO: should check in-reply-to param.
let response = part.get_param("return").unwrap();
result = u32::from_str(response).ok();
}
b"error:abort" => {
let mut message =
part.get_param("message").unwrap().to_string();
if let Some(hint) = part.get_param("hint") {
message.push_str("\n\n");
message.push_str(hint);
}
error!(target: "root", "{}", message);
}
error!(target: "root", "{}", message);
_ => {}
}
_ => {}
}
} else {
pushed = ChangesetHeads::new();
}
}
UnbundleResponse::Raw(response) => {
Expand Down
6 changes: 2 additions & 4 deletions tests/pushcrash.t
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Commit something in the git clone:
$ creategit z
$ cd ..

XXX git-cinnabar failure is a bit ungraceful!
git push fails gracefully with nonzero exit status:

$ git -C repo.git push origin
Expand All @@ -66,9 +65,8 @@ git push fails gracefully with nonzero exit status:
remote: transaction abort!
remote: rollback completed
remote: abort: No such file or directory: '/nonexistent'
fatal: called `Result::unwrap()` on an `Err` value: Error { kind: UnexpectedEof, message: "failed to fill whole buffer" }
Run the command again with `git -c cinnabar.check=traceback <command>` to see the full traceback.
error: git-remote-hg died of signal 6
To hg::*/cramtests-*/pushcrash.t/repo.hg (glob)
! [remote rejected] branches/default/tip -> branches/default/tip (nothing changed on remote)
error: failed to push some refs to 'hg::*/cramtests-*/pushcrash.t/repo.hg' (glob)
[1]

Expand Down

0 comments on commit 718cd34

Please sign in to comment.