Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make git push fail gracefully with nonzero exit status if upstream hg crashes or rejects push #342

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

riastradh
Copy link

@riastradh riastradh commented Dec 9, 2024

Intended to fix the following three issues:

Not 100% sure about the logic here in remote_helper_push, but it seems to produce the desired effect in the test cases. In particular, the mechanism for propagating an error through (resetting pushed to empty) seems questionable, and it's not immediately clear to me what to do about multi-part bundlev2 responses.

@glandium
Copy link
Owner

Thank you for the patches. Could you add your tests to tests/push.t instead of adding separate tests?

Copy link
Owner

@glandium glandium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind doing a separate PR for this one?

Edit: of course, github doesn't attach that to the commit I added the comment from: d5438e7

@riastradh
Copy link
Author

Thank you for the patches. Could you add your tests to tests/push.t instead of adding separate tests?

I can do that if you like, but push.t is already a long narrative which doesn't seem to involve anything that makes commits in git and pushes them to hg. So it wasn't obvious where to thread these test cases into the narrative -- it looked to me like the wrong place to put these tests altogether; likewise push-refs.t.

Are you sure you want me to put these cases in push.t? Should I put them at the end? Reset the repositories first so the history isn't cluttered with extra stuff not germane to whether or not the git commit went through?

@riastradh
Copy link
Author

Would you mind doing a separate PR for this one?

Done: #343

@glandium
Copy link
Owner

Thank you for the patches. Could you add your tests to tests/push.t instead of adding separate tests?

I can do that if you like, but push.t is already a long narrative which doesn't seem to involve anything that makes commits in git and pushes them to hg. So it wasn't obvious where to thread these test cases into the narrative -- it looked to me like the wrong place to put these tests altogether; likewise push-refs.t.

Are you sure you want me to put these cases in push.t? Should I put them at the end? Reset the repositories first so the history isn't cluttered with extra stuff not germane to whether or not the git commit went through?

These tests use the history that was pulled from mercurial instead of creating fresh commits with git. Technically speaking, you don't need to create more git commits, you just can reset the cinnabar metadata with rollback and push to a new empty (or non-empty) mercurial repo.

From that perspective, add your two tests at the end ought to be enough.

@riastradh riastradh force-pushed the riastradh-issue338-issue341-pushcrashreject branch from d5438e7 to 184c6d3 Compare December 15, 2024 00:29
@riastradh
Copy link
Author

OK, I've moved the tests to the end of tests/push.t instead. Seems awkward to reuse the repository history previously set up by the rest of the test, but it does exhibit the issue and the fix, at least; let me know if I misunderstood what you were asking for.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Dec 16, 2024
PKGREVISION++

(No change to devel/py-hg-cinnabarclone PKGREVISION even though the
patch also applies to it, because the patch doesn't change any of the
content of the py-hg-cinnabarclone package, which consists mainly of
one .py file in git-cinnabar.  The patch is applied merely for the
convenience of sharing distinfo between the two packages.)

Derived from the current state of:

glandium/git-cinnabar#342
Copy link
Owner

@glandium glandium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have yet to check whether the changes in src/main.rs are what's wanted, but let's already get these comments out.

tests/push.t Outdated
XXX This should fail with nonzero exit status and not update remote refs:
https://github.com/glandium/git-cinnabar/issues/341

$ cat <<EOF >repo/.hg/hgrc
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use $REPO here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

tests/push.t Outdated
ERROR Changes on branch 'default' resulted in multiple heads
To hg::.*/push.t/repo (re)
+ 687e015...846552c 846552c6f25c1b46e784f59d8249fb31afac2996 -> branches/default/tip (forced update)
$ rm repo/.hg/hgrc
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the git log below change too?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think I see what's going on: since the first one overwrites the remote refs, even when the second one doesn't do anything, it still keeps the wrong refs from the first push. How about adding a git remote update to reset the remote to what it's supposed to have?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done -- I put a git remote update in while that part is exhibiting the bug, and removed it with the bug fix.

$ rm repo/.hg/hgrc
$ git -C abc-git log --graph --remotes --oneline --no-abbrev-commit
* 846552c6f25c1b46e784f59d8249fb31afac2996 x
* bc90f2819ad12e294b313097b8763d26ca0c08ae b
* 687e015f9f646bb19797d991f2f53087297fbe14 c
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! This should change in the previous commit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@@ -560,11 +560,13 @@ https://github.com/glandium/git-cinnabar/issues/341
\r (no-eol) (esc)
ERROR Changes on branch 'default' resulted in multiple heads
To hg::.*/push.t/repo (re)
+ 687e015...846552c 846552c6f25c1b46e784f59d8249fb31afac2996 -> branches/default/tip (forced update)
! [remote rejected] 846552c6f25c1b46e784f59d8249fb31afac2996 -> branches/default/tip (nothing changed on remote)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XXX above this should be removed too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@riastradh riastradh force-pushed the riastradh-issue338-issue341-pushcrashreject branch from 184c6d3 to 67644cc Compare December 18, 2024 15:02
@riastradh
Copy link
Author

OK, I think I have addressed all your comments on the tests.

Like I said at the beginning, the changes to src/main.rs probably aren't quite right -- instead of reporting what was rejected, it just pretends nothing changed on the remote. Probably the right thing is to update pushed, or find some way to propagate the detailed failure into status, but this approximation -- good enough to make it fail with nonzero exit status and not spuriously update remote refs -- was easier to draft than the surgery of those data structures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants