Skip to content

Commit fe048e4

Browse files
committed
Merge branch 'tg/push-all-in-mirror-forbidden'
Fix an earlier regression to "git push --all" which should have been forbidden when the target remote repository is set to be a mirror. * tg/push-all-in-mirror-forbidden: push: disallow --all and refspecs when remote.<name>.mirror is set
2 parents cab037c + 8e4c8af commit fe048e4

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

builtin/push.c

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -385,30 +385,14 @@ static int push_with_options(struct transport *transport, struct refspec *rs,
385385
}
386386

387387
static int do_push(const char *repo, int flags,
388-
const struct string_list *push_options)
388+
const struct string_list *push_options,
389+
struct remote *remote)
389390
{
390391
int i, errs;
391-
struct remote *remote = pushremote_get(repo);
392392
const char **url;
393393
int url_nr;
394394
struct refspec *push_refspec = &rs;
395395

396-
if (!remote) {
397-
if (repo)
398-
die(_("bad repository '%s'"), repo);
399-
die(_("No configured push destination.\n"
400-
"Either specify the URL from the command-line or configure a remote repository using\n"
401-
"\n"
402-
" git remote add <name> <url>\n"
403-
"\n"
404-
"and then push using the remote name\n"
405-
"\n"
406-
" git push <name>\n"));
407-
}
408-
409-
if (remote->mirror)
410-
flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
411-
412396
if (push_options->nr)
413397
flags |= TRANSPORT_PUSH_OPTIONS;
414398

@@ -548,6 +532,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
548532
struct string_list push_options_cmdline = STRING_LIST_INIT_DUP;
549533
struct string_list *push_options;
550534
const struct string_list_item *item;
535+
struct remote *remote;
551536

552537
struct option options[] = {
553538
OPT__VERBOSITY(&verbosity),
@@ -602,20 +587,6 @@ int cmd_push(int argc, const char **argv, const char *prefix)
602587
die(_("--delete is incompatible with --all, --mirror and --tags"));
603588
if (deleterefs && argc < 2)
604589
die(_("--delete doesn't make sense without any refs"));
605-
if (flags & TRANSPORT_PUSH_ALL) {
606-
if (tags)
607-
die(_("--all and --tags are incompatible"));
608-
if (argc >= 2)
609-
die(_("--all can't be combined with refspecs"));
610-
}
611-
if (flags & TRANSPORT_PUSH_MIRROR) {
612-
if (tags)
613-
die(_("--mirror and --tags are incompatible"));
614-
if (argc >= 2)
615-
die(_("--mirror can't be combined with refspecs"));
616-
}
617-
if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR))
618-
die(_("--all and --mirror are incompatible"));
619590

620591
if (recurse_submodules == RECURSE_SUBMODULES_CHECK)
621592
flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
@@ -632,11 +603,43 @@ int cmd_push(int argc, const char **argv, const char *prefix)
632603
set_refspecs(argv + 1, argc - 1, repo);
633604
}
634605

606+
remote = pushremote_get(repo);
607+
if (!remote) {
608+
if (repo)
609+
die(_("bad repository '%s'"), repo);
610+
die(_("No configured push destination.\n"
611+
"Either specify the URL from the command-line or configure a remote repository using\n"
612+
"\n"
613+
" git remote add <name> <url>\n"
614+
"\n"
615+
"and then push using the remote name\n"
616+
"\n"
617+
" git push <name>\n"));
618+
}
619+
620+
if (remote->mirror)
621+
flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
622+
623+
if (flags & TRANSPORT_PUSH_ALL) {
624+
if (tags)
625+
die(_("--all and --tags are incompatible"));
626+
if (argc >= 2)
627+
die(_("--all can't be combined with refspecs"));
628+
}
629+
if (flags & TRANSPORT_PUSH_MIRROR) {
630+
if (tags)
631+
die(_("--mirror and --tags are incompatible"));
632+
if (argc >= 2)
633+
die(_("--mirror can't be combined with refspecs"));
634+
}
635+
if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR))
636+
die(_("--all and --mirror are incompatible"));
637+
635638
for_each_string_list_item(item, push_options)
636639
if (strchr(item->string, '\n'))
637640
die(_("push options must not have new line characters"));
638641

639-
rc = do_push(repo, flags, push_options);
642+
rc = do_push(repo, flags, push_options, remote);
640643
string_list_clear(&push_options_cmdline, 0);
641644
string_list_clear(&push_options_config, 0);
642645
if (rc == -1)

t/t5517-push-mirror.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,14 @@ test_expect_success 'remote.foo.mirror=no has no effect' '
265265
266266
'
267267

268+
test_expect_success 'push to mirrored repository with refspec fails' '
269+
mk_repo_pair &&
270+
(
271+
cd master &&
272+
echo one >foo && git add foo && git commit -m one &&
273+
git config --add remote.up.mirror true &&
274+
test_must_fail git push up master
275+
)
276+
'
277+
268278
test_done

0 commit comments

Comments
 (0)