push: check for errors earlier
Move the error checking for using the "--mirror", "--all", and "--tags" options earlier and explicitly check for the presence of the flags instead of checking for a side-effect of the flag. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
May 16, 2018 at 15:58 UTC
800a4ab399e954b8970897076b327bf1cf18c0ac
1 file changed
+14
-17
builtin/push.c
+14
-17
@@ -417,23 +417,6 @@ static int do_push(const char *repo, int flags,
417
if (push_options->nr)
418
flags |= TRANSPORT_PUSH_OPTIONS;
419
420
- if ((flags & TRANSPORT_PUSH_ALL) && refspec) {
421
- if (!strcmp(*refspec, "refs/tags/*"))
422
- return error(_("--all and --tags are incompatible"));
423
- return error(_("--all can't be combined with refspecs"));
424
- }
425
-
426
- if ((flags & TRANSPORT_PUSH_MIRROR) && refspec) {
427
- if (!strcmp(*refspec, "refs/tags/*"))
428
- return error(_("--mirror and --tags are incompatible"));
429
- return error(_("--mirror can't be combined with refspecs"));
430
- }
431
-
432
- if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) ==
433
- (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) {
434
- return error(_("--all and --mirror are incompatible"));
435
- }
436
-
420
if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
421
if (remote->push.raw_nr) {
422
refspec = remote->push.raw;
@@ -625,6 +608,20 @@ int cmd_push(int argc, const char **argv, const char *prefix)
608
die(_("--delete is incompatible with --all, --mirror and --tags"));
609
if (deleterefs && argc < 2)
610
die(_("--delete doesn't make sense without any refs"));
611
+ if (flags & TRANSPORT_PUSH_ALL) {
612
+ if (tags)
613
+ die(_("--all and --tags are incompatible"));
614
+ if (argc >= 2)
615
+ die(_("--all can't be combined with refspecs"));
616
+ }
617
+ if (flags & TRANSPORT_PUSH_MIRROR) {
618
+ if (tags)
619
+ die(_("--mirror and --tags are incompatible"));
620
+ if (argc >= 2)
621
+ die(_("--mirror can't be combined with refspecs"));
622
+ }
623
+ if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR))
624
+ die(_("--all and --mirror are incompatible"));
625
626
if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
627
flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;