aboutsummaryrefslogtreecommitdiff
path: root/builtin-push.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin-push.c')
-rw-r--r--builtin-push.c69
1 files changed, 43 insertions, 26 deletions
diff --git a/builtin-push.c b/builtin-push.c
index 356d7c1fd..dcfb53f18 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -87,6 +87,37 @@ static void setup_default_push_refspecs(void)
}
}
+static int push_with_options(struct transport *transport, int flags)
+{
+ int err;
+ int nonfastforward;
+ if (receivepack)
+ transport_set_option(transport,
+ TRANS_OPT_RECEIVEPACK, receivepack);
+ if (thin)
+ transport_set_option(transport, TRANS_OPT_THIN, "yes");
+
+ if (flags & TRANSPORT_PUSH_VERBOSE)
+ fprintf(stderr, "Pushing to %s\n", transport->url);
+ err = transport_push(transport, refspec_nr, refspec, flags,
+ &nonfastforward);
+ if (err != 0)
+ error("failed to push some refs to '%s'", transport->url);
+
+ err |= transport_disconnect(transport);
+
+ if (!err)
+ return 0;
+
+ if (nonfastforward && advice_push_nonfastforward) {
+ printf("To prevent you from losing history, non-fast-forward updates were rejected\n"
+ "Merge the remote changes before pushing again. See the 'non-fast-forward'\n"
+ "section of 'git push --help' for details.\n");
+ }
+
+ return 1;
+}
+
static int do_push(const char *repo, int flags)
{
int i, errs;
@@ -135,33 +166,19 @@ static int do_push(const char *repo, int flags)
url = remote->url;
url_nr = remote->url_nr;
}
- for (i = 0; i < url_nr; i++) {
- struct transport *transport =
- transport_get(remote, url[i]);
- int err;
- int nonfastforward;
- if (receivepack)
- transport_set_option(transport,
- TRANS_OPT_RECEIVEPACK, receivepack);
- if (thin)
- transport_set_option(transport, TRANS_OPT_THIN, "yes");
-
- if (flags & TRANSPORT_PUSH_VERBOSE)
- fprintf(stderr, "Pushing to %s\n", url[i]);
- err = transport_push(transport, refspec_nr, refspec, flags,
- &nonfastforward);
- err |= transport_disconnect(transport);
-
- if (!err)
- continue;
-
- error("failed to push some refs to '%s'", url[i]);
- if (nonfastforward && advice_push_nonfastforward) {
- printf("To prevent you from losing history, non-fast-forward updates were rejected\n"
- "Merge the remote changes before pushing again. See the 'non-fast-forward'\n"
- "section of 'git push --help' for details.\n");
+ if (url_nr) {
+ for (i = 0; i < url_nr; i++) {
+ struct transport *transport =
+ transport_get(remote, url[i]);
+ if (push_with_options(transport, flags))
+ errs++;
}
- errs++;
+ } else {
+ struct transport *transport =
+ transport_get(remote, NULL);
+
+ if (push_with_options(transport, flags))
+ errs++;
}
return !!errs;
}