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 glandium#338
  • Loading branch information
Taylor R Campbell committed Dec 14, 2024
1 parent c58517e commit ed39d41
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 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
7 changes: 2 additions & 5 deletions tests/push.t
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,6 @@ https://github.com/glandium/git-cinnabar/issues/341

Verify that pushes to the divergent clone are rejected by a broken
hook:
XXX This should not crash git-cinnabar:
https://github.com/glandium/git-cinnabar/issues/338

$ cat <<EOF >repo/.hg/hgrc
> [hooks]
Expand All @@ -591,9 +589,8 @@ https://github.com/glandium/git-cinnabar/issues/338
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::.*/push.t/repo (re)
! [remote rejected] 846552c6f25c1b46e784f59d8249fb31afac2996 -> branches/default/tip (nothing changed on remote)
error: failed to push some refs to 'hg::.*/push.t/repo' (re)
[1]
$ rm repo/.hg/hgrc
Expand Down

0 comments on commit ed39d41

Please sign in to comment.