From f2f60a5935e3673e6df2a45b25c961587d9a2186 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 6 Jul 2017 11:36:35 -0700 Subject: push: disable lazy --force-with-lease by default "git push --force-with-lease=:" makes sure that there is no unexpected changes to the branch at the remote while you prepare a rewrite based on the old state of the branch. This feature came with an experimental option that allows : part to be omitted by using the tip of remote-tracking branch that corresponds to the . It turns out that some people use third-party tools that fetch from remote and update the remote-tracking branches behind users' back, defeating the safety that relies on the stability of the remote-tracking branches. We have some warning text that was meant to sound scary in our documentation, but nevertheless people seem to be bitten. See https://public-inbox.org/git/1491617750.2149.10.camel@mattmccutchen.net/ for a recent example. Let's disable the forms that rely on the stability of remote-tracking branches by default, and allow users who _know_ their remote-tracking branches are stable to enable it with a configuration variable. This problem was predicted from the very beginning; see 28f5d176 (remote.c: add command line option parser for "--force-with-lease", 2013-07-08). Signed-off-by: Junio C Hamano --- remote.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'remote.c') diff --git a/remote.c b/remote.c index d87482573d..2d3ee6020f 100644 --- a/remote.c +++ b/remote.c @@ -1517,7 +1517,9 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, int force_update) { struct ref *ref; + int allow_lazy_cas = 0; + git_config_get_bool("push.allowLazyForceWithLease", &allow_lazy_cas); for (ref = remote_refs; ref; ref = ref->next) { int force_ref_update = ref->force || force_update; int reject_reason = 0; @@ -1544,7 +1546,9 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, * branch. */ if (ref->expect_old_sha1) { - if (oidcmp(&ref->old_oid, &ref->old_oid_expect)) + if (!allow_lazy_cas && ref->lazy_cas) + reject_reason = REF_STATUS_REJECT_LAZY_CAS; + else 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. */ @@ -2341,10 +2345,13 @@ static void apply_cas(struct push_cas_option *cas, if (!refname_match(entry->refname, ref->name)) continue; ref->expect_old_sha1 = 1; - if (!entry->use_tracking) + 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)) - oidclr(&ref->old_oid_expect); + } else { + ref->lazy_cas = 1; + if (remote_tracking(remote, ref->name, &ref->old_oid_expect)) + oidclr(&ref->old_oid_expect); + } return; } @@ -2353,6 +2360,7 @@ static void apply_cas(struct push_cas_option *cas, return; ref->expect_old_sha1 = 1; + ref->lazy_cas = 1; if (remote_tracking(remote, ref->name, &ref->old_oid_expect)) oidclr(&ref->old_oid_expect); } -- cgit v1.2.1