summaryrefslogtreecommitdiff
path: root/builtin-push.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin-push.c')
-rw-r--r--builtin-push.c58
1 files changed, 25 insertions, 33 deletions
diff --git a/builtin-push.c b/builtin-push.c
index 2eabcd3bdf..f8376cffa4 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -10,7 +10,7 @@
#include "parse-options.h"
static const char * const push_usage[] = {
- "git push [--all | --mirror] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
+ "git push [--all | --mirror] [--dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
NULL,
};
@@ -64,36 +64,11 @@ static void setup_push_tracking(void)
add_refspec(refspec.buf);
}
-static const char *warn_unconfigured_push_msg[] = {
- "You did not specify any refspecs to push, and the current remote",
- "has not configured any push refspecs. The default action in this",
- "case is to push all matching refspecs, that is, all branches",
- "that exist both locally and remotely will be updated. This may",
- "not necessarily be what you want to happen.",
- "",
- "You can specify what action you want to take in this case, and",
- "avoid seeing this message again, by configuring 'push.default' to:",
- " 'nothing' : Do not push anything",
- " 'matching' : Push all matching branches (default)",
- " 'tracking' : Push the current branch to whatever it is tracking",
- " 'current' : Push the current branch"
-};
-
-static void warn_unconfigured_push(void)
-{
- int i;
- for (i = 0; i < ARRAY_SIZE(warn_unconfigured_push_msg); i++)
- warning("%s", warn_unconfigured_push_msg[i]);
-}
-
static void setup_default_push_refspecs(void)
{
git_config(git_default_config, NULL);
switch (push_default) {
- case PUSH_DEFAULT_UNSPECIFIED:
- warn_unconfigured_push();
- /* fallthrough */
-
+ default:
case PUSH_DEFAULT_MATCHING:
add_refspec(":");
break;
@@ -117,6 +92,8 @@ static int do_push(const char *repo, int flags)
{
int i, errs;
struct remote *remote = remote_get(repo);
+ const char **url;
+ int url_nr;
if (!remote) {
if (repo)
@@ -152,10 +129,18 @@ static int do_push(const char *repo, int flags)
setup_default_push_refspecs();
}
errs = 0;
- for (i = 0; i < remote->url_nr; i++) {
+ if (remote->pushurl_nr) {
+ url = remote->pushurl;
+ url_nr = remote->pushurl_nr;
+ } else {
+ url = remote->url;
+ url_nr = remote->url_nr;
+ }
+ for (i = 0; i < url_nr; i++) {
struct transport *transport =
- transport_get(remote, remote->url[i]);
+ transport_get(remote, url[i]);
int err;
+ int nonfastforward;
if (receivepack)
transport_set_option(transport,
TRANS_OPT_RECEIVEPACK, receivepack);
@@ -163,14 +148,20 @@ static int do_push(const char *repo, int flags)
transport_set_option(transport, TRANS_OPT_THIN, "yes");
if (flags & TRANSPORT_PUSH_VERBOSE)
- fprintf(stderr, "Pushing to %s\n", remote->url[i]);
- err = transport_push(transport, refspec_nr, refspec, flags);
+ 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'", remote->url[i]);
+ error("failed to push some refs to '%s'", url[i]);
+ if (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");
+ }
errs++;
}
return !!errs;
@@ -191,6 +182,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
(TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
OPT_BOOLEAN( 0 , "tags", &tags, "push tags"),
OPT_BIT( 0 , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
+ OPT_BIT( 0, "porcelain", &flags, "machine-readable output", TRANSPORT_PUSH_PORCELAIN),
OPT_BIT('f', "force", &flags, "force updates", TRANSPORT_PUSH_FORCE),
OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", "receive pack program"),
@@ -198,7 +190,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
OPT_END()
};
- argc = parse_options(argc, argv, options, push_usage, 0);
+ argc = parse_options(argc, argv, prefix, options, push_usage, 0);
if (tags)
add_refspec("refs/tags/*");