Skip to content

Commit

Permalink
devel/git-cinnabar: Add patches to fix spurious git push success.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
riastradh committed Dec 16, 2024
1 parent 6490b72 commit 2292c35
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 2 deletions.
3 changes: 2 additions & 1 deletion devel/git-cinnabar/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# $NetBSD: Makefile,v 1.22 2024/12/16 00:41:19 riastradh Exp $
# $NetBSD: Makefile,v 1.23 2024/12/16 00:41:41 riastradh Exp $

.include "Makefile.common"

PKGREVISION= 1
CATEGORIES= devel

MAINTAINER= [email protected]
Expand Down
4 changes: 3 additions & 1 deletion devel/git-cinnabar/distinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$NetBSD: distinfo,v 1.8 2024/12/05 02:31:30 riastradh Exp $
$NetBSD: distinfo,v 1.9 2024/12/16 00:41:41 riastradh Exp $

BLAKE2s (addr2line-0.24.1.crate) = 6b7b4e5845873018da12292d582de9e8ec0be0edbac314cbbbfb7dad89d7a983
SHA512 (addr2line-0.24.1.crate) = ffa53fcfbbccdec943410083aa5f44e93122e0b40dc45acfe00b454a02c5575549e9a61807d87080d1677da807fef695b6676036fec3ca079d2b841794dbc0b5
Expand Down Expand Up @@ -412,5 +412,7 @@ BLAKE2s (zstd-sys-2.0.13+zstd.1.5.6.crate) = df71c3b7a2dd396817e8e71eee920caccb9
SHA512 (zstd-sys-2.0.13+zstd.1.5.6.crate) = c1f0176ebd0914879d0060796776c7fe376293ce9bc9f8f07ee3b809932a75aa033881d59a1bc99b6cd9af85b8e225fc09bcfc96013e556d7c11f155b759ecbf
Size (zstd-sys-2.0.13+zstd.1.5.6.crate) = 749090 bytes
SHA1 (patch-git-core_ci_run-test-slice.sh) = 9c7bc2b52c677d96d77a4d842650828a23c3eccc
SHA1 (patch-src_main.rs) = 13681decb7b9f1a4bd5876a2c651320660fb2935
SHA1 (patch-tests_cinnabarclone.t) = 054754e932eb52a04001da5cae96c5582dfacddc
SHA1 (patch-tests_push-refs.t) = c6de59558337c8fe193df7166a9a4179cf3e14ca
SHA1 (patch-tests_push.t) = e95d39ba32fcd0921da4e59be5bbc71df6355fee
55 changes: 55 additions & 0 deletions devel/git-cinnabar/patches/patch-src_main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
$NetBSD: patch-src_main.rs,v 1.1 2024/12/16 00:41:41 riastradh Exp $

Make git push fail with nonzero status when rejected upstream.
https://github.com/glandium/git-cinnabar/issues/338
https://github.com/glandium/git-cinnabar/issues/341
https://github.com/glandium/git-cinnabar/pull/342

--- src/main.rs.orig 2024-09-30 20:35:52.000000000 +0000
+++ src/main.rs
@@ -4845,25 +4845,29 @@ 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);
+ pushed = ChangesetHeads::new();
}
- error!(target: "root", "{}", message);
+ _ => {}
}
- _ => {}
}
+ } else {
+ pushed = ChangesetHeads::new();
}
}
UnbundleResponse::Raw(response) => {
104 changes: 104 additions & 0 deletions devel/git-cinnabar/patches/patch-tests_push.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
$NetBSD: patch-tests_push.t,v 1.1 2024/12/16 00:41:41 riastradh Exp $

Make git push fail with nonzero status when rejected upstream.
https://github.com/glandium/git-cinnabar/issues/338
https://github.com/glandium/git-cinnabar/issues/341
https://github.com/glandium/git-cinnabar/pull/342

--- tests/push.t.orig 2024-09-30 20:35:52.000000000 +0000
+++ tests/push.t
@@ -516,3 +516,94 @@ different than without the feature enabl
* 687e015f9f646bb19797d991f2f53087297fbe14 c
* d04f6df4abe2870ceb759263ee6aaa9241c4f93c b
* 8b86a58578d5270969543e287634e3a2f122a338 a
+
+Create a new commit in a divergent Mercurial clone.
+
+ $ ABX=$(pwd)/abx
+ $ hg clone -q -u 636e60525868096cbdc961870493510558f41d2f abc abx
+ $ cd abx
+ $ create x
+ $ cd ..
+ $ hg -R $ABX log -G --template '{node} {branch} {desc}'
+ @ 2b10b3a49ff6e308c904c2c626d7e449480b6403 default x
+ |
+ | o bd623dea939349b06a47d5dce064255e5f1d9ec1 default c
+ |/
+ o 636e60525868096cbdc961870493510558f41d2f default b
+ |
+ o f92470d7f6966a39dfbced6a525fe81ebf5c37b9 default a
+
+Grab the divergent commit in git:
+
+ $ git -C abc-git -c fetch.prune=true fetch -q hg::$ABX
+ $ git -C abc-git log --graph --oneline --no-abbrev-commit FETCH_HEAD
+ * 846552c6f25c1b46e784f59d8249fb31afac2996 x
+ * bc90f2819ad12e294b313097b8763d26ca0c08ae b
+ * 8b86a58578d5270969543e287634e3a2f122a338 a
+
+Verify that pushes to the divergent hg clone are rejected by a
+reject_new_heads hook:
+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
+ > [hooks]
+ > pretxnclose.reject_new_heads = python:hgext.hooklib.reject_new_heads.hook
+ > EOF
+ $ git -C abc-git push -f origin 846552c6f25c1b46e784f59d8249fb31afac2996:branches/default/tip
+ remote: adding changesets
+ remote: adding manifests
+ remote: adding file changes
+ remote: error: pretxnclose.reject_new_heads hook failed: Changes on branch 'default' resulted in multiple heads
+ remote: transaction abort!
+ remote: rollback completed
+ \r (no-eol) (esc)
+ ERROR Changes on branch 'default' resulted in multiple heads
+ 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
+ $ git -C abc-git log --graph --remotes --oneline --no-abbrev-commit
+ * 687e015f9f646bb19797d991f2f53087297fbe14 c
+ * d04f6df4abe2870ceb759263ee6aaa9241c4f93c b
+ * 8b86a58578d5270969543e287634e3a2f122a338 a
+ $ hg -R $REPO log -G --template '{node} {branch} {desc}'
+ o c70941aaa15aa6e5feae28164438f13dc3cd7b8e default c
+ |
+ o 29872b591f8d41c613bbfad38722824ab0457f17 default b
+ |
+ o f92470d7f6966a39dfbced6a525fe81ebf5c37b9 default a
+
+
+Verify that pushes to the divergent clone are rejected by a broken
+hook:
+
+ $ cat <<EOF >repo/.hg/hgrc
+ > [hooks]
+ > pretxnclose = python:/nonexistent:fail
+ > EOF
+ $ git -C abc-git push -f origin 846552c6f25c1b46e784f59d8249fb31afac2996:branches/default/tip
+ remote: adding changesets
+ remote: adding manifests
+ remote: adding file changes
+ remote: loading pretxnclose hook failed:
+ remote: transaction abort!
+ remote: rollback completed
+ remote: abort: No such file or directory: '/nonexistent'
+ 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
+ $ git -C abc-git log --graph --remotes --oneline --no-abbrev-commit
+ * 687e015f9f646bb19797d991f2f53087297fbe14 c
+ * d04f6df4abe2870ceb759263ee6aaa9241c4f93c b
+ * 8b86a58578d5270969543e287634e3a2f122a338 a
+ $ hg -R $REPO log -G --template '{node} {branch} {desc}'
+ o c70941aaa15aa6e5feae28164438f13dc3cd7b8e default c
+ |
+ o 29872b591f8d41c613bbfad38722824ab0457f17 default b
+ |
+ o f92470d7f6966a39dfbced6a525fe81ebf5c37b9 default a
+

0 comments on commit 2292c35

Please sign in to comment.