push: add advice for rejected tag reference

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>

Chris Rorvick committed Nov 29, 2012 at 19:41 UTC b24e6047a8da3cddfd686e6a9157ed4bac28ed4f
5 files changed +25
builtin/push.c
+11
@@ -220,6 +220,10 @@ static const char message_advice_checkout_pull_push[] =
220 "(e.g. 'git pull') before pushing again.\n"
221 "See the 'Note about fast-forwards' in 'git push --help' for details.");
222
223 +static const char message_advice_ref_already_exists[] =
224 + N_("Updates were rejected because the destination reference already exists\n"
225 + "in the remote and the update is not a fast-forward.");
226 +
227 static void advise_pull_before_push(void)
228 {
229 if (!advice_push_non_ff_current || !advice_push_nonfastforward)
@@ -241,6 +245,11 @@ static void advise_checkout_pull_push(void)
245 advise(_(message_advice_checkout_pull_push));
246 }
247
248 +static void advise_ref_already_exists(void)
249 +{
250 + advise(_(message_advice_ref_already_exists));
251 +}
252 +
253 static int push_with_options(struct transport *transport, int flags)
254 {
255 int err;
@@ -272,6 +281,8 @@ static int push_with_options(struct transport *transport, int flags)
281 advise_use_upstream();
282 else
283 advise_checkout_pull_push();
284 + } else if (reject_reasons & REJECT_ALREADY_EXISTS) {
285 + advise_ref_already_exists();
286 }
287
288 return 1;
cache.h
+1
@@ -1002,6 +1002,7 @@ struct ref {
1002 unsigned int force:1,
1003 merge:1,
1004 nonfastforward:1,
1005 + not_forwardable:1,
1006 deletion:1;
1007 enum {
1008 REF_STATUS_NONE = 0,
remote.c
+10
@@ -1279,6 +1279,14 @@ int match_push_refs(struct ref *src, struct ref **dst,
1279 return 0;
1280 }
1281
1282 +static inline int is_forwardable(struct ref* ref)
1283 +{
1284 + if (!prefixcmp(ref->name, "refs/tags/"))
1285 + return 0;
1286 +
1287 + return 1;
1288 +}
1289 +
1290 void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
1291 int force_update)
1292 {
@@ -1316,6 +1324,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
1324 * always allowed.
1325 */
1326
1327 + ref->not_forwardable = !is_forwardable(ref);
1328 +
1329 ref->nonfastforward =
1330 !ref->deletion &&
1331 !is_null_sha1(ref->old_sha1) &&
transport.c
+2
@@ -740,6 +740,8 @@ void transport_print_push_status(const char *dest, struct ref *refs,
740 ref->status != REF_STATUS_OK)
741 n += print_one_push_status(ref, dest, n, porcelain);
742 if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD) {
743 + if (ref->not_forwardable)
744 + *reject_reasons |= REJECT_ALREADY_EXISTS;
745 if (!strcmp(head, ref->name))
746 *reject_reasons |= REJECT_NON_FF_HEAD;
747 else
transport.h
+1
@@ -142,6 +142,7 @@ void transport_set_verbosity(struct transport *transport, int verbosity,
142
143 #define REJECT_NON_FF_HEAD 0x01
144 #define REJECT_NON_FF_OTHER 0x02
145 +#define REJECT_ALREADY_EXISTS 0x04
146
147 int transport_push(struct transport *connection,
148 int refspec_nr, const char **refspec, int flags,