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 <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
John Keeping committed
Jul 26, 2016 at 21:44 UTC
64ac39af7020f3a8bc52d51137804ce9f46baf66
3 files changed
+15
-5
remote.c
+3
-4
@@ -1554,8 +1554,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
1554
* branch.
1555
*/
1556
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))
1558
reject_reason = REF_STATUS_REJECT_STALE;
1559
else
1560
/* If the ref isn't stale then force the update. */
@@ -2355,7 +2354,7 @@ static void apply_cas(struct push_cas_option *cas,
2354
if (!entry->use_tracking)
2355
hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);
2356
else if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
2358
- ref->expect_old_no_trackback = 1;
2357
+ oidclr(&ref->old_oid_expect);
2358
return;
2359
}
2360
@@ -2365,7 +2364,7 @@ static void apply_cas(struct push_cas_option *cas,
2364
2365
ref->expect_old_sha1 = 1;
2366
if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
2368
- ref->expect_old_no_trackback = 1;
2367
+ oidclr(&ref->old_oid_expect);
2368
}
2369
2370
void apply_push_cas(struct push_cas_option *cas,
remote.h
-1
@@ -87,7 +87,6 @@ struct ref {
87
force:1,
88
forced_update:1,
89
expect_old_sha1:1,
90
- expect_old_no_trackback:1,
90
deletion:1,
91
matched:1;
92
t/t5533-push-cas.sh
+12
@@ -191,6 +191,18 @@ test_expect_success 'cover everything with default force-with-lease (allowed)' '
191
test_cmp expect actual
192
'
193
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
+
206
test_expect_success 'new branch covered by force-with-lease (explicit)' '
207
setup_srcdst_basic &&
208
(