Skip to content

Commit 64ac39a

Browse files
johnkeepinggitster
authored andcommitted
push: allow pushing new branches with --force-with-lease
If there is no upstream information for a branch, it is likely that it is newly created and can safely be pushed under the normal fast-forward rules. Relax the --force-with-lease check so that we do not reject these branches immediately but rather attempt to push them as new branches, using the null SHA-1 as the expected value. In fact, it is already possible to push new branches using the explicit --force-with-lease=<branch>:<expect> syntax, so all we do here is make this behaviour the default if no explicit "expect" value is specified. Signed-off-by: John Keeping <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eee98e7 commit 64ac39a

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

remote.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,8 +1554,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
15541554
* branch.
15551555
*/
15561556
if (ref->expect_old_sha1) {
1557-
if (ref->expect_old_no_trackback ||
1558-
oidcmp(&ref->old_oid, &ref->old_oid_expect))
1557+
if (oidcmp(&ref->old_oid, &ref->old_oid_expect))
15591558
reject_reason = REF_STATUS_REJECT_STALE;
15601559
else
15611560
/* If the ref isn't stale then force the update. */
@@ -2355,7 +2354,7 @@ static void apply_cas(struct push_cas_option *cas,
23552354
if (!entry->use_tracking)
23562355
hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);
23572356
else if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
2358-
ref->expect_old_no_trackback = 1;
2357+
oidclr(&ref->old_oid_expect);
23592358
return;
23602359
}
23612360

@@ -2365,7 +2364,7 @@ static void apply_cas(struct push_cas_option *cas,
23652364

23662365
ref->expect_old_sha1 = 1;
23672366
if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
2368-
ref->expect_old_no_trackback = 1;
2367+
oidclr(&ref->old_oid_expect);
23692368
}
23702369

23712370
void apply_push_cas(struct push_cas_option *cas,

remote.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ struct ref {
8787
force:1,
8888
forced_update:1,
8989
expect_old_sha1:1,
90-
expect_old_no_trackback:1,
9190
deletion:1,
9291
matched:1;
9392

t/t5533-push-cas.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ test_expect_success 'cover everything with default force-with-lease (allowed)' '
191191
test_cmp expect actual
192192
'
193193

194+
test_expect_success 'new branch covered by force-with-lease' '
195+
setup_srcdst_basic &&
196+
(
197+
cd dst &&
198+
git branch branch master &&
199+
git push --force-with-lease=branch origin branch
200+
) &&
201+
git ls-remote dst refs/heads/branch >expect &&
202+
git ls-remote src refs/heads/branch >actual &&
203+
test_cmp expect actual
204+
'
205+
194206
test_expect_success 'new branch covered by force-with-lease (explicit)' '
195207
setup_srcdst_basic &&
196208
(

0 commit comments

Comments
 (0)