# [PATCH] push: fix --force-with-lease forwarding in push_multiple()

3 messages from 2026-11-04 to 2026-11-04. Participants: Tyler Cipriani, Kristoffer Haugsbakk.
Thread: https://gitlist.dev/t/66763

## Tyler Cipriani, 2026-11-04 00:27

Subject: [PATCH] push: fix --force-with-lease forwarding in push_multiple()
Message-ID: <20261104002721.304153-1-tyler@tylercipriani.com>
URL: https://gitlist.dev/e/20261104002721.304153-1-tyler%40tylercipriani.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=<ref>: (i.e., expect that <ref> is absent on
  the remote) could overwrite a remote branch if <ref>'s remote-tracking
  branch is up-to-date with the remote, which is the usual state
  following fetch.

Reported-by: Patrick Perośa <pa3ck.perosa@gmail.com>
Signed-off-by: Tyler Cipriani <tyler@tylercipriani.com>
---
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");
+			/* <ref>: 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



```

## Kristoffer Haugsbakk, 2026-11-04 05:21

Subject: Re: [PATCH] push: fix --force-with-lease forwarding in push_multiple()
Message-ID: <510c81e1-dc54-4049-bf5a-c22ec157a4e3@app.fastmail.com>
URL: https://gitlist.dev/e/510c81e1-dc54-4049-bf5a-c22ec157a4e3%40app.fastmail.com
In-Reply-To: <20261104002721.304153-1-tyler@tylercipriani.com>

```
On Wed, Nov 4, 2026, at 01:27, Tyler Cipriani wrote:
> [snip]
>
> Reported-by: Patrick Perośa <pa3ck.perosa@gmail.com>

It should be Peroša.

> Signed-off-by: Tyler Cipriani <tyler@tylercipriani.com>
> ---
> Thanks for the clear reproduction case, Patrick!
>
> Based off maint since it's a bug in 2.56.0.
>
>[snip]

-- 
I don't have my glasses on though


```

## Tyler Cipriani, 2026-11-04 18:49

Subject: [PATCH v2] push: fix --force-with-lease forwarding in push_multiple()
Message-ID: <20261104184950.403069-1-tyler@tylercipriani.com>
URL: https://gitlist.dev/e/20261104184950.403069-1-tyler%40tylercipriani.com
In-Reply-To: <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:

- Non-fast-forward --force-with-lease is always rejected because that
  option is never forwarded to the remote group. The bare option sets
  cas.use_tracking_for_rest without adding a cas entry; only cas entries
  are forwarded.

- Using --force-with-lease=<ref>: (i.e., expect that <ref> is absent on
  the remote) could overwrite a remote branch if <ref>'s remote-tracking
  branch is up-to-date with the remote, which is the usual state
  following fetch.

Reported-by: Patrick Peroša <pa3ck.perosa@gmail.com>
Signed-off-by: Tyler Cipriani <tyler@tylercipriani.com>
---
Based on maint since it's a bug in 2.56.0

Changes since v1:
- Fix incorrect name in Reported-by trailer
- Fix confusing sentence with mixed verb tenses in log message

 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");
+			/* <ref>: 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 &&

Range-diff against v1:
1:  28266d5d24 ! 1:  f5553bf99a push: fix --force-with-lease forwarding in push_multiple()
    @@ Commit message
     
         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.
    +    - Non-fast-forward --force-with-lease is always rejected because that
    +      option is never forwarded to the remote group. The bare option sets
    +      cas.use_tracking_for_rest without adding a cas entry; only cas entries
    +      are forwarded.
     
         - Using --force-with-lease=<ref>: (i.e., expect that <ref> is absent on
           the remote) could overwrite a remote branch if <ref>'s remote-tracking
           branch is up-to-date with the remote, which is the usual state
           following fetch.
     
    -    Reported-by: Patrick Perośa <pa3ck.perosa@gmail.com>
    +    Reported-by: Patrick Peroša <pa3ck.perosa@gmail.com>
         Signed-off-by: Tyler Cipriani <tyler@tylercipriani.com>
     
      ## builtin/push.c ##
-- 
2.47.3



```
