From: Tyler Cipriani Date: Wed, 04 Nov 2026 00:27:21 GMT Subject: [PATCH] push: fix --force-with-lease forwarding in push_multiple() Message-ID: <20261104002721.304153-1-tyler@tylercipriani.com> 8ea8281665 (push: support pushing to a remote group, 2026-05-03) taught push how to handle a remote group, but mishandled --force-with-lease. Fix two bugs with remote group --force-with-lease: - Bare --force-with-lease always rejects non-fast-forward pushes since it was never forwarded. The bare option sets cas.use_tracking_for_rest without adding a cas entry; only cas entries were forwarded. - Using --force-with-lease=: (i.e., expect that is absent on the remote) could overwrite a remote branch if 's remote-tracking branch is up-to-date with the remote, which is the usual state following fetch. Reported-by: Patrick Perośa Signed-off-by: Tyler Cipriani --- Thanks for the clear reproduction case, Patrick! Based off maint since it's a bug in 2.56.0. builtin/push.c | 7 ++++++- t/t5533-push-cas.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/builtin/push.c b/builtin/push.c index 2377b5af55..7f0091206a 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -627,6 +627,9 @@ static int push_multiple(struct string_list *list, strvec_pushf(&argv, "--push-option=%s", push_options->items[i].string); + if (cas.use_tracking_for_rest) + strvec_push(&argv, "--force-with-lease"); + for (i = 0; i < cas.nr; i++) { if (cas.entry[i].use_tracking) { strvec_pushf(&argv, "--force-with-lease=%s", @@ -636,7 +639,9 @@ static int push_multiple(struct string_list *list, cas.entry[i].refname, oid_to_hex(&cas.entry[i].expect)); } else { - strvec_push(&argv, "--force-with-lease"); + /* : means expect ref not to exist */ + strvec_pushf(&argv, "--force-with-lease=%s:", + cas.entry[i].refname); } } diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh index 2e14aecaa2..6a56aa46d3 100755 --- a/t/t5533-push-cas.sh +++ b/t/t5533-push-cas.sh @@ -168,6 +168,48 @@ test_expect_success 'push to update (allowed even though no-ff)' ' test_cmp expect actual ' +test_expect_success 'push to update (allowed even though no-ff) multiple remotes' ' + setup_srcdst_basic && + git clone --bare src src2 && + test_when_finished "rm -rf src2" && + ( + cd dst && + git remote add src2 ../src2 && + git fetch src2 && + git config remotes.multi "origin src2" && + git reset --hard HEAD^ && + test_commit D && + git push --force-with-lease multi main 2>err && + test_grep "forced update" err + ) && + git ls-remote dst refs/heads/main >expect && + git ls-remote src refs/heads/main >actual && + git ls-remote src2 refs/heads/main >actual2 && + test_cmp expect actual && + test_cmp expect actual2 +' + +test_expect_success 'push to update (protected, expect absent) multiple remotes' ' + setup_srcdst_basic && + git clone --bare src src2 && + git ls-remote src refs/heads/main >expect && + test_when_finished "rm -rf src2" && + ( + cd dst && + git remote add src2 ../src2 && + git fetch src2 && + git config remotes.multi "origin src2" && + git reset --hard HEAD^ && + test_commit D && + test_must_fail git push --force-with-lease=main: multi main 2>err && + test_grep "stale info" err + ) && + git ls-remote src refs/heads/main >actual && + git ls-remote src2 refs/heads/main >actual2 && + test_cmp expect actual && + test_cmp expect actual2 +' + test_expect_success 'push to delete (protected)' ' setup_srcdst_basic && git ls-remote src refs/heads/main >expect && -- 2.47.3