From: Matthieu Moy <Matthieu.Moy@imag.fr>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: [PATCH] push: point to 'git pull' and 'git push --force' in case of non-fast forward
Date: Thu, 6 Aug 2009 19:32:13 +0200 [thread overview]
Message-ID: <1249579933-1782-1-git-send-email-Matthieu.Moy@imag.fr> (raw)
'git push' failing because of non-fast forward is a very common situation,
and a beginner does not necessarily understand "fast forward" immediately.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
That may be a bit verbose, but I think it's worth it.
Ideally, there should be a core.expertUser config variable to disable
these kind of messages, but that's another story.
builtin-push.c | 9 ++++++++-
transport.c | 10 +++++++---
transport.h | 3 ++-
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/builtin-push.c b/builtin-push.c
index 1d92e22..214ca77 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -140,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);
@@ -148,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("Some branch push were rejected due to non-fast forward:\n");
+ printf("Merge the remote changes (git pull) before pushing your's\n");
+ printf("or use git push --force to discard the remote changes.\n");
+ }
errs++;
}
return !!errs;
diff --git a/transport.c b/transport.c
index de0d587..f231b35 100644
--- a/transport.c
+++ b/transport.c
@@ -820,7 +820,7 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count, i
}
static void print_push_status(const char *dest, struct ref *refs,
- int verbose, int porcelain)
+ int verbose, int porcelain, int * nonfastforward)
{
struct ref *ref;
int n = 0;
@@ -835,11 +835,14 @@ static void print_push_status(const char *dest, struct ref *refs,
if (ref->status == REF_STATUS_OK)
n += print_one_push_status(ref, dest, n, porcelain);
+ *nonfastforward = 0;
for (ref = refs; ref; ref = ref->next) {
if (ref->status != REF_STATUS_NONE &&
ref->status != REF_STATUS_UPTODATE &&
ref->status != REF_STATUS_OK)
n += print_one_push_status(ref, dest, n, porcelain);
+ if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD)
+ *nonfastforward = 1;
}
}
@@ -997,7 +1000,8 @@ int transport_set_option(struct transport *transport,
}
int transport_push(struct transport *transport,
- int refspec_nr, const char **refspec, int flags)
+ int refspec_nr, const char **refspec, int flags,
+ int * nonfastforward)
{
verify_remote_names(refspec_nr, refspec);
@@ -1024,7 +1028,7 @@ int transport_push(struct transport *transport,
ret = transport->push_refs(transport, remote_refs, flags);
- print_push_status(transport->url, remote_refs, verbose | porcelain, porcelain);
+ print_push_status(transport->url, remote_refs, verbose | porcelain, porcelain, nonfastforward);
if (!(flags & TRANSPORT_PUSH_DRY_RUN)) {
struct ref *ref;
diff --git a/transport.h b/transport.h
index 51b5397..639f13d 100644
--- a/transport.h
+++ b/transport.h
@@ -68,7 +68,8 @@ int transport_set_option(struct transport *transport, const char *name,
const char *value);
int transport_push(struct transport *connection,
- int refspec_nr, const char **refspec, int flags);
+ int refspec_nr, const char **refspec, int flags,
+ int * nonfastforward);
const struct ref *transport_get_remote_refs(struct transport *transport);
--
1.6.4.57.g116738.dirty
next reply other threads:[~2009-08-06 17:36 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-06 17:32 Matthieu Moy [this message]
2009-08-06 20:04 ` [PATCH] push: point to 'git pull' and 'git push --force' in case of non-fast forward Michael J Gruber
2009-08-07 19:21 ` Matthieu Moy
2009-08-07 19:46 ` Michael J Gruber
2009-08-06 20:15 ` Junio C Hamano
2009-08-06 21:16 ` [PATCH] " Nicolas Sebrecht
2009-08-06 21:32 ` Junio C Hamano
2009-08-07 19:37 ` [PATCH] " Matthieu Moy
2009-08-07 20:05 ` Junio C Hamano
2009-08-07 20:22 ` Matthieu Moy
2009-08-08 7:51 ` [PATCH v2] " Matthieu Moy
2009-08-08 8:35 ` Teemu Likonen
2009-08-08 15:22 ` Matthieu Moy
2009-08-08 16:25 ` Junio C Hamano
2009-08-08 22:23 ` [PATCH v2] " Nicolas Sebrecht
2009-08-09 18:35 ` [PATCH v2] " Matthieu Moy
2009-08-09 20:22 ` Junio C Hamano
2009-08-10 8:43 ` Matthieu Moy
2009-08-10 8:49 ` Junio C Hamano
2009-08-10 8:56 ` Matthieu Moy
2009-08-11 3:03 ` Nanako Shiraishi
2009-09-06 6:44 ` [RFC/PATCH 0/4] make helpful messages optional Jeff King
2009-09-06 6:46 ` [PATCH 1/4] push: fix english in non-fast-forward message Jeff King
2009-09-06 6:47 ` [PATCH 2/4] push: re-flow " Jeff King
2009-09-06 6:48 ` [PATCH 3/4] push: make non-fast-forward help message configurable Jeff King
2009-09-06 7:09 ` Junio C Hamano
2009-09-06 7:23 ` Jeff King
2009-09-06 7:30 ` Junio C Hamano
2009-09-06 7:32 ` Jeff King
2009-09-06 7:52 ` Junio C Hamano
2009-09-06 11:30 ` Sverre Rabbelier
2009-09-07 0:44 ` Nanako Shiraishi
2009-09-07 7:35 ` Johannes Sixt
2009-09-07 7:40 ` Mike Hommey
2009-09-07 8:24 ` Jeff King
2009-09-07 8:34 ` Matthieu Moy
2009-09-07 8:54 ` Jeff King
2009-09-07 11:20 ` Matthieu Moy
2009-09-08 18:51 ` Uri Okrent
2009-09-09 11:22 ` Jeff King
2009-09-09 11:26 ` [PATCH 0/2] configurable advice messages Jeff King
2009-09-09 11:38 ` [PATCH 1/2] push: make non-fast-forward help message configurable Jeff King
2009-09-09 19:06 ` Junio C Hamano
2009-09-09 20:39 ` Jeff King
2009-09-09 21:47 ` Junio C Hamano
2009-09-09 11:43 ` [PATCH 2/2] status: make "how to stage" messages optional Jeff King
2009-09-06 6:50 ` [PATCH 4/4] " Jeff King
2009-09-06 11:53 ` [RFC/PATCH 0/4] make helpful " Matthieu Moy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1249579933-1782-1-git-send-email-Matthieu.Moy@imag.fr \
--to=matthieu.moy@imag.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).