git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Tyler Cipriani <tyler@tylercipriani.com>
Date
Nov 4, 2026, 18:49 UTC
Message-ID
<20261104184950.403069-1-tyler@tylercipriani.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
Previous: Kristoffer Haugsbakk
Message 3 of 3 in “push: fix --force-with-lease forwarding in push_multiple()”
  1. push: fix --force-with-lease forwarding in push_multiple()Tyler Cipriani, Nov 4, 2026
  2. Kristoffer HaugsbakkNov 4, 2026
  3. push: fix --force-with-lease forwarding in push_multiple()Tyler Cipriani, Nov 4, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.