summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-09-08 21:35:53 -0700
committerJunio C Hamano <gitster@pobox.com>2016-09-08 21:35:53 -0700
commitf34d900aa7346592a9d7fd2eb7b21126fd9732d5 (patch)
treebf756b15988b94b1f045a6f53c1eec9c3c479812
parentf59c6e6ccb1386f0fdde2753f62536dfd3343118 (diff)
parent9eed4f3711a605ab2d9b986357879a09a6d54f36 (diff)
downloadgit-f34d900aa7346592a9d7fd2eb7b21126fd9732d5.tar.gz
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
-rw-r--r--Documentation/git-push.txt5
-rw-r--r--remote.c9
-rw-r--r--remote.h1
-rwxr-xr-xt/t5533-push-cas.sh38
4 files changed, 46 insertions, 7 deletions
diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 93c3527f0c..927a0341cf 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -198,10 +198,11 @@ branch we have for it.
+
`--force-with-lease=<refname>:<expect>` will protect the named ref (alone),
if it is going to be updated, by requiring its current value to be
-the same as the specified value <expect> (which is allowed to be
+the same as the specified value `<expect>` (which is allowed to be
different from the remote-tracking branch we have for the refname,
or we do not even have to have such a remote-tracking branch when
-this form is used).
+this form is used). If `<expect>` is the empty string, then the named ref
+must not already exist.
+
Note that all forms other than `--force-with-lease=<refname>:<expect>`
that specifies the expected current value of the ref explicitly are
diff --git a/remote.c b/remote.c
index a326e4e251..d29850a81c 100644
--- a/remote.c
+++ b/remote.c
@@ -1544,8 +1544,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
* branch.
*/
if (ref->expect_old_sha1) {
- if (ref->expect_old_no_trackback ||
- oidcmp(&ref->old_oid, &ref->old_oid_expect))
+ if (oidcmp(&ref->old_oid, &ref->old_oid_expect))
reject_reason = REF_STATUS_REJECT_STALE;
else
/* 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
entry = add_cas_entry(cas, arg, colon - arg);
if (!*colon)
entry->use_tracking = 1;
+ else if (!colon[1])
+ hashclr(entry->expect);
else if (get_sha1(colon + 1, entry->expect))
return error("cannot parse expected object name '%s'", colon + 1);
return 0;
@@ -2343,7 +2344,7 @@ static void apply_cas(struct push_cas_option *cas,
if (!entry->use_tracking)
hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);
else if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
- ref->expect_old_no_trackback = 1;
+ oidclr(&ref->old_oid_expect);
return;
}
@@ -2353,7 +2354,7 @@ static void apply_cas(struct push_cas_option *cas,
ref->expect_old_sha1 = 1;
if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
- ref->expect_old_no_trackback = 1;
+ oidclr(&ref->old_oid_expect);
}
void apply_push_cas(struct push_cas_option *cas,
diff --git a/remote.h b/remote.h
index c21fd3788c..924881169d 100644
--- a/remote.h
+++ b/remote.h
@@ -89,7 +89,6 @@ struct ref {
force:1,
forced_update:1,
expect_old_sha1:1,
- expect_old_no_trackback:1,
deletion:1,
matched:1;
diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh
index c7320121ec..a2c9e7439f 100755
--- a/t/t5533-push-cas.sh
+++ b/t/t5533-push-cas.sh
@@ -191,4 +191,42 @@ test_expect_success 'cover everything with default force-with-lease (allowed)' '
test_cmp expect actual
'
+test_expect_success 'new branch covered by force-with-lease' '
+ setup_srcdst_basic &&
+ (
+ cd dst &&
+ git branch branch master &&
+ git push --force-with-lease=branch origin branch
+ ) &&
+ git ls-remote dst refs/heads/branch >expect &&
+ git ls-remote src refs/heads/branch >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'new branch covered by force-with-lease (explicit)' '
+ setup_srcdst_basic &&
+ (
+ cd dst &&
+ git branch branch master &&
+ git push --force-with-lease=branch: origin branch
+ ) &&
+ git ls-remote dst refs/heads/branch >expect &&
+ git ls-remote src refs/heads/branch >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'new branch already exists' '
+ setup_srcdst_basic &&
+ (
+ cd src &&
+ git checkout -b branch master &&
+ test_commit F
+ ) &&
+ (
+ cd dst &&
+ git branch branch master &&
+ test_must_fail git push --force-with-lease=branch: origin branch
+ )
+'
+
test_done