]> git.ipfire.org Git - thirdparty/git.git/commitdiff
push: add advice for rejected tag reference
authorChris Rorvick <chris@rorvick.com>
Fri, 30 Nov 2012 01:41:34 +0000 (19:41 -0600)
committerJunio C Hamano <gitster@pobox.com>
Sun, 2 Dec 2012 09:39:50 +0000 (01:39 -0800)
Advising the user to fetch and merge only makes sense if the rejected
reference is a branch.  If none of the rejections are for branches, just
tell the user the reference already exists.

Signed-off-by: Chris Rorvick <chris@rorvick.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/push.c
cache.h
remote.c
transport.c
transport.h

index 9d17fc799cbfef0d009a8e44834f5d82225688a6..e08485d1239fae1e1409864007b30b9c458a02e7 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 and the update is not a fast-forward.");
+
 static void advise_pull_before_push(void)
 {
        if (!advice_push_non_ff_current || !advice_push_nonfastforward)
@@ -241,6 +245,11 @@ 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;
@@ -272,6 +281,8 @@ static int push_with_options(struct transport *transport, int flags)
                        advise_use_upstream();
                else
                        advise_checkout_pull_push();
+       } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
+               advise_ref_already_exists();
        }
 
        return 1;
diff --git a/cache.h b/cache.h
index dbd8018b5827ce40fd72ac0ba84934551a11f225..d72b64d8b0958216e1f7266b11816c210be0efb9 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1002,6 +1002,7 @@ struct ref {
        unsigned int force:1,
                merge:1,
                nonfastforward:1,
+               not_forwardable:1,
                deletion:1;
        enum {
                REF_STATUS_NONE = 0,
index 04fd9ea4bd2f99003c9c5abb7bbbad7dafca3937..51016831b94d8e11f1397bf250a01c986a5d13f5 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -1279,6 +1279,14 @@ int match_push_refs(struct ref *src, struct ref **dst,
        return 0;
 }
 
+static inline int is_forwardable(struct ref* ref)
+{
+       if (!prefixcmp(ref->name, "refs/tags/"))
+               return 0;
+
+       return 1;
+}
+
 void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
        int force_update)
 {
@@ -1316,6 +1324,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
                 *     always allowed.
                 */
 
+               ref->not_forwardable = !is_forwardable(ref);
+
                ref->nonfastforward =
                        !ref->deletion &&
                        !is_null_sha1(ref->old_sha1) &&
index d4568e7b378b475f2326f6afd5814f01858ce77e..bc31e8e66beac675a4334b32b8d1547350bbb470 100644 (file)
@@ -740,6 +740,8 @@ void transport_print_push_status(const char *dest, struct ref *refs,
                    ref->status != REF_STATUS_OK)
                        n += print_one_push_status(ref, dest, n, porcelain);
                if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD) {
+                       if (ref->not_forwardable)
+                               *reject_reasons |= REJECT_ALREADY_EXISTS;
                        if (!strcmp(head, ref->name))
                                *reject_reasons |= REJECT_NON_FF_HEAD;
                        else
index 404b113014be755788c9f04a283bdb1cb1c4cc7a..bfd2df5823aac55e4ce8674b7980cccabf0fed5f 100644 (file)
@@ -142,6 +142,7 @@ void transport_set_verbosity(struct transport *transport, int verbosity,
 
 #define REJECT_NON_FF_HEAD     0x01
 #define REJECT_NON_FF_OTHER    0x02
+#define REJECT_ALREADY_EXISTS  0x04
 
 int transport_push(struct transport *connection,
                   int refspec_nr, const char **refspec, int flags,