path: root/builtin/push.c
diff options
authorJunio C Hamano <>2013-09-09 21:30:29 (GMT)
committerJunio C Hamano <>2013-09-09 21:30:29 (GMT)
commit2233ad4534db8a37b1bf726312d52d4a0a51db0a (patch)
treea13884a1de77eb61ef89f9b3f780553c6b2a3225 /builtin/push.c
parent711b2769740637e228c8200927e96b31f2065d32 (diff)
parent05c1eb10348f159908becc7a6ed6bbcdab24c893 (diff)
Merge branch 'jc/push-cas'
Allow a safer "rewind of the remote tip" push than blind "--force", by requiring that the overwritten remote ref to be unchanged since the new history to replace it was prepared. The machinery is more or less ready. The "--force" option is again the big red button to override any safety, thanks to J6t's sanity (the original round allowed --lockref to defeat --force). The logic to choose the default implemented here is fragile (e.g. "git fetch" after seeing a failure will update the remote-tracking branch and will make the next "push" pass, defeating the safety pretty easily). It is suitable only for the simplest workflows, and it may hurt users more than it helps them. * jc/push-cas: push: teach --force-with-lease to smart-http transport send-pack: fix parsing of --force-with-lease option t5540/5541: smart-http does not support "--force-with-lease" t5533: test "push --force-with-lease" push --force-with-lease: tie it all together push --force-with-lease: implement logic to populate old_sha1_expect[] remote.c: add command line option parser for "--force-with-lease" builtin/push.c: use OPT_BOOL, not OPT_BOOLEAN cache.h: move remote/connect API out of it
Diffstat (limited to 'builtin/push.c')
1 files changed, 13 insertions, 0 deletions
diff --git a/builtin/push.c b/builtin/push.c
index aff507c..50bbfd6 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -21,6 +21,8 @@ static const char *receivepack;
static int verbosity;
static int progress = -1;
+static struct push_cas_option cas;
static const char **refspec;
static int refspec_nr;
static int refspec_alloc;
@@ -316,6 +318,13 @@ static int push_with_options(struct transport *transport, int flags)
if (thin)
transport_set_option(transport, TRANS_OPT_THIN, "yes");
+ if (!is_empty_cas(&cas)) {
+ if (!transport->smart_options)
+ die("underlying transport does not support --%s option",
+ transport->smart_options->cas = &cas;
+ }
if (verbosity > 0)
fprintf(stderr, _("Pushing to %s\n"), transport->url);
err = transport_push(transport, refspec_nr, refspec, flags,
@@ -451,6 +460,10 @@ int cmd_push(int argc, const char **argv, const char *prefix)
OPT_BIT('n' , "dry-run", &flags, N_("dry run"), TRANSPORT_PUSH_DRY_RUN),
OPT_BIT( 0, "porcelain", &flags, N_("machine-readable output"), TRANSPORT_PUSH_PORCELAIN),
OPT_BIT('f', "force", &flags, N_("force updates"), TRANSPORT_PUSH_FORCE),
+ 0, CAS_OPT_NAME, &cas, N_("refname>:<expect"),
+ N_("require old value of ref to be at this value"),
+ PARSE_OPT_OPTARG, parseopt_push_cas_option },
{ OPTION_CALLBACK, 0, "recurse-submodules", &flags, N_("check"),
N_("control recursive pushing of submodules"),
PARSE_OPT_OPTARG, option_parse_recurse_submodules },