push: clarify rejection of update to non-commit-ish
[gitweb.git] / builtin / push.c
index db9ba30b08c221ac2290b1ffc939713fe378e666..83a3cc80c332a6b53c3f18365eaef2a406a531ef 100644 (file)
@@ -220,6 +220,10 @@ static const char message_advice_checkout_pull_push[] =
           "(e.g. 'git pull') before pushing again.\n"
           "See the 'Note about fast-forwards' in 'git push --help' for details.");
 
+static const char message_advice_ref_already_exists[] =
+       N_("Updates were rejected because the destination reference already exists\n"
+          "in the remote.");
+
 static void advise_pull_before_push(void)
 {
        if (!advice_push_non_ff_current || !advice_push_nonfastforward)
@@ -241,10 +245,15 @@ static void advise_checkout_pull_push(void)
        advise(_(message_advice_checkout_pull_push));
 }
 
+static void advise_ref_already_exists(void)
+{
+       advise(_(message_advice_ref_already_exists));
+}
+
 static int push_with_options(struct transport *transport, int flags)
 {
        int err;
-       int nonfastforward;
+       unsigned int reject_reasons;
 
        transport_set_verbosity(transport, verbosity, progress);
 
@@ -257,7 +266,7 @@ static int push_with_options(struct transport *transport, int flags)
        if (verbosity > 0)
                fprintf(stderr, _("Pushing to %s\n"), transport->url);
        err = transport_push(transport, refspec_nr, refspec, flags,
-                            &nonfastforward);
+                            &reject_reasons);
        if (err != 0)
                error(_("failed to push some refs to '%s'"), transport->url);
 
@@ -265,18 +274,15 @@ static int push_with_options(struct transport *transport, int flags)
        if (!err)
                return 0;
 
-       switch (nonfastforward) {
-       default:
-               break;
-       case NON_FF_HEAD:
+       if (reject_reasons & REJECT_NON_FF_HEAD) {
                advise_pull_before_push();
-               break;
-       case NON_FF_OTHER:
+       } else if (reject_reasons & REJECT_NON_FF_OTHER) {
                if (default_matching_used)
                        advise_use_upstream();
                else
                        advise_checkout_pull_push();
-               break;
+       } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
+               advise_ref_already_exists();
        }
 
        return 1;