Skip to content

Commit b24e604

Browse files
crorvickgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 10643d4 commit b24e604

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

builtin/push.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ static const char message_advice_checkout_pull_push[] =
220220
"(e.g. 'git pull') before pushing again.\n"
221221
"See the 'Note about fast-forwards' in 'git push --help' for details.");
222222

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+
223227
static void advise_pull_before_push(void)
224228
{
225229
if (!advice_push_non_ff_current || !advice_push_nonfastforward)
@@ -241,6 +245,11 @@ static void advise_checkout_pull_push(void)
241245
advise(_(message_advice_checkout_pull_push));
242246
}
243247

248+
static void advise_ref_already_exists(void)
249+
{
250+
advise(_(message_advice_ref_already_exists));
251+
}
252+
244253
static int push_with_options(struct transport *transport, int flags)
245254
{
246255
int err;
@@ -272,6 +281,8 @@ static int push_with_options(struct transport *transport, int flags)
272281
advise_use_upstream();
273282
else
274283
advise_checkout_pull_push();
284+
} else if (reject_reasons & REJECT_ALREADY_EXISTS) {
285+
advise_ref_already_exists();
275286
}
276287

277288
return 1;

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ struct ref {
10021002
unsigned int force:1,
10031003
merge:1,
10041004
nonfastforward:1,
1005+
not_forwardable:1,
10051006
deletion:1;
10061007
enum {
10071008
REF_STATUS_NONE = 0,

remote.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,14 @@ int match_push_refs(struct ref *src, struct ref **dst,
12791279
return 0;
12801280
}
12811281

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+
12821290
void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
12831291
int force_update)
12841292
{
@@ -1316,6 +1324,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
13161324
* always allowed.
13171325
*/
13181326

1327+
ref->not_forwardable = !is_forwardable(ref);
1328+
13191329
ref->nonfastforward =
13201330
!ref->deletion &&
13211331
!is_null_sha1(ref->old_sha1) &&

transport.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,8 @@ void transport_print_push_status(const char *dest, struct ref *refs,
740740
ref->status != REF_STATUS_OK)
741741
n += print_one_push_status(ref, dest, n, porcelain);
742742
if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD) {
743+
if (ref->not_forwardable)
744+
*reject_reasons |= REJECT_ALREADY_EXISTS;
743745
if (!strcmp(head, ref->name))
744746
*reject_reasons |= REJECT_NON_FF_HEAD;
745747
else

transport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ void transport_set_verbosity(struct transport *transport, int verbosity,
142142

143143
#define REJECT_NON_FF_HEAD 0x01
144144
#define REJECT_NON_FF_OTHER 0x02
145+
#define REJECT_ALREADY_EXISTS 0x04
145146

146147
int transport_push(struct transport *connection,
147148
int refspec_nr, const char **refspec, int flags,

0 commit comments

Comments
 (0)