Skip to content

Commit 800a4ab

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9fa2e5e commit 800a4ab

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

builtin/push.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -417,23 +417,6 @@ static int do_push(const char *repo, int flags,
417417
if (push_options->nr)
418418
flags |= TRANSPORT_PUSH_OPTIONS;
419419

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-
437420
if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
438421
if (remote->push.raw_nr) {
439422
refspec = remote->push.raw;
@@ -625,6 +608,20 @@ int cmd_push(int argc, const char **argv, const char *prefix)
625608
die(_("--delete is incompatible with --all, --mirror and --tags"));
626609
if (deleterefs && argc < 2)
627610
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"));
628625

629626
if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
630627
flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;

0 commit comments

Comments
 (0)