Thread View: linux.kernel.git
3 messages
3 total messages
Started by Tyler Cipriani
Wed, 04 Nov 2026 00:27
[PATCH] push: fix --force-with-lease forwarding in push_multiple()
Author: Tyler Cipriani
Date: Wed, 04 Nov 2026 00:27
Date: Wed, 04 Nov 2026 00:27
106 lines
14327 bytes
14327 bytes
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
Re: [PATCH] push: fix --force-with-lease forwarding in push_multiple()
Author: "Kristoffer Haugsbakk"
Date: Wed, 04 Nov 2026 05:21
Date: Wed, 04 Nov 2026 05:21
18 lines
13092 bytes
13092 bytes
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
[PATCH v2] push: fix --force-with-lease forwarding in push_multiple()
Author: Tyler Cipriani
Date: Wed, 04 Nov 2026 18:49
Date: Wed, 04 Nov 2026 18:49
134 lines
15773 bytes
15773 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads