Skip to content

Commit f34d900

Browse files
committed
Merge branch 'jk/push-force-with-lease-creation' into maint
"git push --force-with-lease" already had enough logic to allow ensuring that such a push results in creation of a ref (i.e. the receiving end did not have another push from sideways that would be discarded by our force-pushing), but didn't expose this possibility to the users. It does so now. * jk/push-force-with-lease-creation: t5533: make it pass on case-sensitive filesystems push: allow pushing new branches with --force-with-lease push: add shorthand for --force-with-lease branch creation Documentation/git-push: fix placeholder formatting
2 parents f59c6e6 + 9eed4f3 commit f34d900

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

Documentation/git-push.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,11 @@ branch we have for it.
198198
+
199199
`--force-with-lease=<refname>:<expect>` will protect the named ref (alone),
200200
if it is going to be updated, by requiring its current value to be
201-
the same as the specified value <expect> (which is allowed to be
201+
the same as the specified value `<expect>` (which is allowed to be
202202
different from the remote-tracking branch we have for the refname,
203203
or we do not even have to have such a remote-tracking branch when
204-
this form is used).
204+
this form is used). If `<expect>` is the empty string, then the named ref
205+
must not already exist.
205206
+
206207
Note that all forms other than `--force-with-lease=<refname>:<expect>`
207208
that specifies the expected current value of the ref explicitly are

remote.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,8 +1544,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
15441544
* branch.
15451545
*/
15461546
if (ref->expect_old_sha1) {
1547-
if (ref->expect_old_no_trackback ||
1548-
oidcmp(&ref->old_oid, &ref->old_oid_expect))
1547+
if (oidcmp(&ref->old_oid, &ref->old_oid_expect))
15491548
reject_reason = REF_STATUS_REJECT_STALE;
15501549
else
15511550
/* If the ref isn't stale then force the update. */
@@ -2294,6 +2293,8 @@ int parse_push_cas_option(struct push_cas_option *cas, const char *arg, int unse
22942293
entry = add_cas_entry(cas, arg, colon - arg);
22952294
if (!*colon)
22962295
entry->use_tracking = 1;
2296+
else if (!colon[1])
2297+
hashclr(entry->expect);
22972298
else if (get_sha1(colon + 1, entry->expect))
22982299
return error("cannot parse expected object name '%s'", colon + 1);
22992300
return 0;
@@ -2343,7 +2344,7 @@ static void apply_cas(struct push_cas_option *cas,
23432344
if (!entry->use_tracking)
23442345
hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);
23452346
else if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
2346-
ref->expect_old_no_trackback = 1;
2347+
oidclr(&ref->old_oid_expect);
23472348
return;
23482349
}
23492350

@@ -2353,7 +2354,7 @@ static void apply_cas(struct push_cas_option *cas,
23532354

23542355
ref->expect_old_sha1 = 1;
23552356
if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
2356-
ref->expect_old_no_trackback = 1;
2357+
oidclr(&ref->old_oid_expect);
23572358
}
23582359

23592360
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
@@ -89,7 +89,6 @@ struct ref {
8989
force:1,
9090
forced_update:1,
9191
expect_old_sha1:1,
92-
expect_old_no_trackback:1,
9392
deletion:1,
9493
matched:1;
9594

t/t5533-push-cas.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,42 @@ 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+
206+
test_expect_success 'new branch covered by force-with-lease (explicit)' '
207+
setup_srcdst_basic &&
208+
(
209+
cd dst &&
210+
git branch branch master &&
211+
git push --force-with-lease=branch: origin branch
212+
) &&
213+
git ls-remote dst refs/heads/branch >expect &&
214+
git ls-remote src refs/heads/branch >actual &&
215+
test_cmp expect actual
216+
'
217+
218+
test_expect_success 'new branch already exists' '
219+
setup_srcdst_basic &&
220+
(
221+
cd src &&
222+
git checkout -b branch master &&
223+
test_commit F
224+
) &&
225+
(
226+
cd dst &&
227+
git branch branch master &&
228+
test_must_fail git push --force-with-lease=branch: origin branch
229+
)
230+
'
231+
194232
test_done

0 commit comments

Comments
 (0)