Code

grep: do not segfault when -f is used
[git.git] / builtin-push.c
index 0a0297f981121924a3ccc8ee52c9b2051f3d410d..f8376cffa447a796794983b56e44592be6a87b80 100644 (file)
@@ -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;
@@ -165,6 +140,7 @@ static int do_push(const char *repo, int flags)
                struct transport *transport =
                        transport_get(remote, url[i]);
                int err;
+               int nonfastforward;
                if (receivepack)
                        transport_set_option(transport,
                                             TRANS_OPT_RECEIVEPACK, receivepack);
@@ -173,13 +149,19 @@ static int do_push(const char *repo, int flags)
 
                if (flags & TRANSPORT_PUSH_VERBOSE)
                        fprintf(stderr, "Pushing to %s\n", url[i]);
-               err = transport_push(transport, refspec_nr, refspec, flags);
+               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) {
+                       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;