Skip to content

Commit 0eefe10

Browse files
committed
Merge branch 'aw/push-force-with-lease-reporting' into maint
"git push --force-with-lease" has been taught to report if the push needed to force (or fast-forwarded). * aw/push-force-with-lease-reporting: push: fix ref status reporting for --force-with-lease
2 parents 88221d9 + b2e93f8 commit 0eefe10

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

remote.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,11 +1545,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
15451545
}
15461546

15471547
/*
1548-
* Bypass the usual "must fast-forward" check but
1549-
* replace it with a weaker "the old value must be
1550-
* this value we observed". If the remote ref has
1551-
* moved and is now different from what we expect,
1552-
* reject any push.
1548+
* If the remote ref has moved and is now different
1549+
* from what we expect, reject any push.
15531550
*
15541551
* It also is an error if the user told us to check
15551552
* with the remote-tracking branch to find the value
@@ -1560,10 +1557,14 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
15601557
if (ref->expect_old_no_trackback ||
15611558
oidcmp(&ref->old_oid, &ref->old_oid_expect))
15621559
reject_reason = REF_STATUS_REJECT_STALE;
1560+
else
1561+
/* If the ref isn't stale then force the update. */
1562+
force_ref_update = 1;
15631563
}
15641564

15651565
/*
1566-
* The usual "must fast-forward" rules.
1566+
* If the update isn't already rejected then check
1567+
* the usual "must fast-forward" rules.
15671568
*
15681569
* Decide whether an individual refspec A:B can be
15691570
* pushed. The push will succeed if any of the
@@ -1582,7 +1583,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
15821583
* passing the --force argument
15831584
*/
15841585

1585-
else if (!ref->deletion && !is_null_oid(&ref->old_oid)) {
1586+
if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) {
15861587
if (starts_with(ref->name, "refs/tags/"))
15871588
reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS;
15881589
else if (!has_object_file(&ref->old_oid))

t/t5533-push-cas.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ test_expect_success 'push to update (protected)' '
2525
(
2626
cd dst &&
2727
test_commit D &&
28-
test_must_fail git push --force-with-lease=master:master origin master
28+
test_must_fail git push --force-with-lease=master:master origin master 2>err &&
29+
grep "stale info" err
2930
) &&
3031
git ls-remote . refs/heads/master >expect &&
3132
git ls-remote src refs/heads/master >actual &&
@@ -37,7 +38,8 @@ test_expect_success 'push to update (protected, forced)' '
3738
(
3839
cd dst &&
3940
test_commit D &&
40-
git push --force --force-with-lease=master:master origin master
41+
git push --force --force-with-lease=master:master origin master 2>err &&
42+
grep "forced update" err
4143
) &&
4244
git ls-remote dst refs/heads/master >expect &&
4345
git ls-remote src refs/heads/master >actual &&
@@ -101,7 +103,8 @@ test_expect_success 'push to update (allowed, tracking)' '
101103
(
102104
cd dst &&
103105
test_commit D &&
104-
git push --force-with-lease=master origin master
106+
git push --force-with-lease=master origin master 2>err &&
107+
! grep "forced update" err
105108
) &&
106109
git ls-remote dst refs/heads/master >expect &&
107110
git ls-remote src refs/heads/master >actual &&
@@ -114,7 +117,8 @@ test_expect_success 'push to update (allowed even though no-ff)' '
114117
cd dst &&
115118
git reset --hard HEAD^ &&
116119
test_commit D &&
117-
git push --force-with-lease=master origin master
120+
git push --force-with-lease=master origin master 2>err &&
121+
grep "forced update" err
118122
) &&
119123
git ls-remote dst refs/heads/master >expect &&
120124
git ls-remote src refs/heads/master >actual &&
@@ -147,7 +151,8 @@ test_expect_success 'push to delete (allowed)' '
147151
setup_srcdst_basic &&
148152
(
149153
cd dst &&
150-
git push --force-with-lease=master origin :master
154+
git push --force-with-lease=master origin :master 2>err &&
155+
grep deleted err
151156
) &&
152157
>expect &&
153158
git ls-remote src refs/heads/master >actual &&

0 commit comments

Comments
 (0)