{"thread":{"id":"66763","subject":"[PATCH] push: fix --force-with-lease forwarding in push_multiple()","startedAt":"2026-11-04T00:27:21Z","lastAt":"2026-11-04T18:49:50Z","messageCount":3,"participants":["Tyler Cipriani","Kristoffer Haugsbakk"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"557392","messageId":"20261104002721.304153-1-tyler@tylercipriani.com","threadId":"66763","inReplyTo":null,"subject":"[PATCH] push: fix --force-with-lease forwarding in push_multiple()","fromName":"Tyler Cipriani","fromEmail":"tyler@tylercipriani.com","sentAt":"2026-11-04T00:27:21Z","receivedAt":"2026-11-04T00:27:21Z","isPatch":true,"sender":{"key":"tyler@tylercipriani.com","avatar":"https://gravatar.com/avatar/552e70f7d13c1043b4b97c2f80d1b6c4e7edcfe0f03dcce45bd6a1145c0529ec?d=mp&s=160"},"body":"8ea8281665 (push: support pushing to a remote group, 2026-05-03) taught\npush how to handle a remote group, but mishandled --force-with-lease.\n\nFix two bugs with remote group --force-with-lease:\n\n- Bare --force-with-lease always rejects non-fast-forward pushes since\n  it was never forwarded. The bare option sets cas.use_tracking_for_rest\n  without adding a cas entry; only cas entries were forwarded.\n\n- Using --force-with-lease=<ref>: (i.e., expect that <ref> is absent on\n  the remote) could overwrite a remote branch if <ref>'s remote-tracking\n  branch is up-to-date with the remote, which is the usual state\n  following fetch.\n\nReported-by: Patrick Perośa <pa3ck.perosa@gmail.com>\nSigned-off-by: Tyler Cipriani <tyler@tylercipriani.com>\n---\nThanks for the clear reproduction case, Patrick!\n\nBased off maint since it's a bug in 2.56.0.\n\n builtin/push.c      |  7 ++++++-\n t/t5533-push-cas.sh | 42 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 48 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 2377b5af55..7f0091206a 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -627,6 +627,9 @@ static int push_multiple(struct string_list *list,\n \t\tstrvec_pushf(&argv, \"--push-option=%s\",\n \t\t\t     push_options->items[i].string);\n \n+\tif (cas.use_tracking_for_rest)\n+\t\tstrvec_push(&argv, \"--force-with-lease\");\n+\n \tfor (i = 0; i < cas.nr; i++) {\n \t\tif (cas.entry[i].use_tracking) {\n \t\t\tstrvec_pushf(&argv, \"--force-with-lease=%s\",\n@@ -636,7 +639,9 @@ static int push_multiple(struct string_list *list,\n \t\t\t\t     cas.entry[i].refname,\n \t\t\t\t     oid_to_hex(&cas.entry[i].expect));\n \t\t} else {\n-\t\t\tstrvec_push(&argv, \"--force-with-lease\");\n+\t\t\t/* <ref>: means expect ref not to exist */\n+\t\t\tstrvec_pushf(&argv, \"--force-with-lease=%s:\",\n+\t\t\t\t     cas.entry[i].refname);\n \t\t}\n \t}\n \ndiff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh\nindex 2e14aecaa2..6a56aa46d3 100755\n--- a/t/t5533-push-cas.sh\n+++ b/t/t5533-push-cas.sh\n@@ -168,6 +168,48 @@ test_expect_success 'push to update (allowed even though no-ff)' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'push to update (allowed even though no-ff) multiple remotes' '\n+\tsetup_srcdst_basic &&\n+\tgit clone --bare src src2 &&\n+\ttest_when_finished \"rm -rf src2\" &&\n+\t(\n+\t\tcd dst &&\n+\t\tgit remote add src2 ../src2 &&\n+\t\tgit fetch src2 &&\n+\t\tgit config remotes.multi \"origin src2\" &&\n+\t\tgit reset --hard HEAD^ &&\n+\t\ttest_commit D &&\n+\t\tgit push --force-with-lease multi main 2>err &&\n+\t\ttest_grep \"forced update\" err\n+\t) &&\n+\tgit ls-remote dst refs/heads/main >expect &&\n+\tgit ls-remote src refs/heads/main >actual &&\n+\tgit ls-remote src2 refs/heads/main >actual2 &&\n+\ttest_cmp expect actual &&\n+\ttest_cmp expect actual2\n+'\n+\n+test_expect_success 'push to update (protected, expect absent) multiple remotes' '\n+\tsetup_srcdst_basic &&\n+\tgit clone --bare src src2 &&\n+\tgit ls-remote src refs/heads/main >expect &&\n+\ttest_when_finished \"rm -rf src2\" &&\n+\t(\n+\t\tcd dst &&\n+\t\tgit remote add src2 ../src2 &&\n+\t\tgit fetch src2 &&\n+\t\tgit config remotes.multi \"origin src2\" &&\n+\t\tgit reset --hard HEAD^ &&\n+\t\ttest_commit D &&\n+\t\ttest_must_fail git push --force-with-lease=main: multi main 2>err &&\n+\t\ttest_grep \"stale info\" err\n+\t) &&\n+\tgit ls-remote src refs/heads/main >actual &&\n+\tgit ls-remote src2 refs/heads/main >actual2 &&\n+\ttest_cmp expect actual &&\n+\ttest_cmp expect actual2\n+'\n+\n test_expect_success 'push to delete (protected)' '\n \tsetup_srcdst_basic &&\n \tgit ls-remote src refs/heads/main >expect &&\n-- \n2.47.3\n\n\n"},{"id":"557401","messageId":"510c81e1-dc54-4049-bf5a-c22ec157a4e3@app.fastmail.com","threadId":"66763","inReplyTo":"20261104002721.304153-1-tyler@tylercipriani.com","subject":"Re: [PATCH] push: fix --force-with-lease forwarding in push_multiple()","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-11-04T05:21:46Z","receivedAt":"2026-11-04T05:21:46Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Wed, Nov 4, 2026, at 01:27, Tyler Cipriani wrote:\n> [snip]\n>\n> Reported-by: Patrick Perośa <pa3ck.perosa@gmail.com>\n\nIt should be Peroša.\n\n> Signed-off-by: Tyler Cipriani <tyler@tylercipriani.com>\n> ---\n> Thanks for the clear reproduction case, Patrick!\n>\n> Based off maint since it's a bug in 2.56.0.\n>\n>[snip]\n\n-- \nI don't have my glasses on though\n\n"},{"id":"557489","messageId":"20261104184950.403069-1-tyler@tylercipriani.com","threadId":"66763","inReplyTo":"20261104002721.304153-1-tyler@tylercipriani.com","subject":"[PATCH v2] push: fix --force-with-lease forwarding in push_multiple()","fromName":"Tyler Cipriani","fromEmail":"tyler@tylercipriani.com","sentAt":"2026-11-04T18:49:50Z","receivedAt":"2026-11-04T18:49:50Z","isPatch":true,"sender":{"key":"tyler@tylercipriani.com","avatar":"https://gravatar.com/avatar/552e70f7d13c1043b4b97c2f80d1b6c4e7edcfe0f03dcce45bd6a1145c0529ec?d=mp&s=160"},"body":"8ea8281665 (push: support pushing to a remote group, 2026-05-03) taught\npush how to handle a remote group, but mishandled --force-with-lease.\n\nFix two bugs with remote group --force-with-lease:\n\n- Non-fast-forward --force-with-lease is always rejected because that\n  option is never forwarded to the remote group. The bare option sets\n  cas.use_tracking_for_rest without adding a cas entry; only cas entries\n  are forwarded.\n\n- Using --force-with-lease=<ref>: (i.e., expect that <ref> is absent on\n  the remote) could overwrite a remote branch if <ref>'s remote-tracking\n  branch is up-to-date with the remote, which is the usual state\n  following fetch.\n\nReported-by: Patrick Peroša <pa3ck.perosa@gmail.com>\nSigned-off-by: Tyler Cipriani <tyler@tylercipriani.com>\n---\nBased on maint since it's a bug in 2.56.0\n\nChanges since v1:\n- Fix incorrect name in Reported-by trailer\n- Fix confusing sentence with mixed verb tenses in log message\n\n builtin/push.c      |  7 ++++++-\n t/t5533-push-cas.sh | 42 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 48 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/push.c b/builtin/push.c\nindex 2377b5af55..7f0091206a 100644\n--- a/builtin/push.c\n+++ b/builtin/push.c\n@@ -627,6 +627,9 @@ static int push_multiple(struct string_list *list,\n \t\tstrvec_pushf(&argv, \"--push-option=%s\",\n \t\t\t     push_options->items[i].string);\n \n+\tif (cas.use_tracking_for_rest)\n+\t\tstrvec_push(&argv, \"--force-with-lease\");\n+\n \tfor (i = 0; i < cas.nr; i++) {\n \t\tif (cas.entry[i].use_tracking) {\n \t\t\tstrvec_pushf(&argv, \"--force-with-lease=%s\",\n@@ -636,7 +639,9 @@ static int push_multiple(struct string_list *list,\n \t\t\t\t     cas.entry[i].refname,\n \t\t\t\t     oid_to_hex(&cas.entry[i].expect));\n \t\t} else {\n-\t\t\tstrvec_push(&argv, \"--force-with-lease\");\n+\t\t\t/* <ref>: means expect ref not to exist */\n+\t\t\tstrvec_pushf(&argv, \"--force-with-lease=%s:\",\n+\t\t\t\t     cas.entry[i].refname);\n \t\t}\n \t}\n \ndiff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh\nindex 2e14aecaa2..6a56aa46d3 100755\n--- a/t/t5533-push-cas.sh\n+++ b/t/t5533-push-cas.sh\n@@ -168,6 +168,48 @@ test_expect_success 'push to update (allowed even though no-ff)' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'push to update (allowed even though no-ff) multiple remotes' '\n+\tsetup_srcdst_basic &&\n+\tgit clone --bare src src2 &&\n+\ttest_when_finished \"rm -rf src2\" &&\n+\t(\n+\t\tcd dst &&\n+\t\tgit remote add src2 ../src2 &&\n+\t\tgit fetch src2 &&\n+\t\tgit config remotes.multi \"origin src2\" &&\n+\t\tgit reset --hard HEAD^ &&\n+\t\ttest_commit D &&\n+\t\tgit push --force-with-lease multi main 2>err &&\n+\t\ttest_grep \"forced update\" err\n+\t) &&\n+\tgit ls-remote dst refs/heads/main >expect &&\n+\tgit ls-remote src refs/heads/main >actual &&\n+\tgit ls-remote src2 refs/heads/main >actual2 &&\n+\ttest_cmp expect actual &&\n+\ttest_cmp expect actual2\n+'\n+\n+test_expect_success 'push to update (protected, expect absent) multiple remotes' '\n+\tsetup_srcdst_basic &&\n+\tgit clone --bare src src2 &&\n+\tgit ls-remote src refs/heads/main >expect &&\n+\ttest_when_finished \"rm -rf src2\" &&\n+\t(\n+\t\tcd dst &&\n+\t\tgit remote add src2 ../src2 &&\n+\t\tgit fetch src2 &&\n+\t\tgit config remotes.multi \"origin src2\" &&\n+\t\tgit reset --hard HEAD^ &&\n+\t\ttest_commit D &&\n+\t\ttest_must_fail git push --force-with-lease=main: multi main 2>err &&\n+\t\ttest_grep \"stale info\" err\n+\t) &&\n+\tgit ls-remote src refs/heads/main >actual &&\n+\tgit ls-remote src2 refs/heads/main >actual2 &&\n+\ttest_cmp expect actual &&\n+\ttest_cmp expect actual2\n+'\n+\n test_expect_success 'push to delete (protected)' '\n \tsetup_srcdst_basic &&\n \tgit ls-remote src refs/heads/main >expect &&\n\nRange-diff against v1:\n1:  28266d5d24 ! 1:  f5553bf99a push: fix --force-with-lease forwarding in push_multiple()\n    @@ Commit message\n     \n         Fix two bugs with remote group --force-with-lease:\n     \n    -    - Bare --force-with-lease always rejects non-fast-forward pushes since\n    -      it was never forwarded. The bare option sets cas.use_tracking_for_rest\n    -      without adding a cas entry; only cas entries were forwarded.\n    +    - Non-fast-forward --force-with-lease is always rejected because that\n    +      option is never forwarded to the remote group. The bare option sets\n    +      cas.use_tracking_for_rest without adding a cas entry; only cas entries\n    +      are forwarded.\n     \n         - Using --force-with-lease=<ref>: (i.e., expect that <ref> is absent on\n           the remote) could overwrite a remote branch if <ref>'s remote-tracking\n           branch is up-to-date with the remote, which is the usual state\n           following fetch.\n     \n    -    Reported-by: Patrick Perośa <pa3ck.perosa@gmail.com>\n    +    Reported-by: Patrick Peroša <pa3ck.perosa@gmail.com>\n         Signed-off-by: Tyler Cipriani <tyler@tylercipriani.com>\n     \n      ## builtin/push.c ##\n-- \n2.47.3\n\n\n"}]}