git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] push: point to 'git pull' and 'git push --force' in case of non-fast forward

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Aug 6, 2009, 20:04 UTC
Message-ID
<4A7B3760.2000303@drmicha.warpmail.net>
In-Reply-To
<1249579933-1782-1-git-send-email-Matthieu.Moy@imag.fr>
Matthieu Moy venit, vidit, dixit 06.08.2009 19:32:
Show 48 quoted lines
> '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;

May I suggest "Some push was rejected because it would not result in a fast forward:\n Merge in the remote changes (using git pull) before pushing yours\n or use..."?

Cheers, Michael

Show 61 quoted lines
> 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);
>  
Previous: Matthieu MoyNext: Matthieu Moy
Message 2 of 48 in “push: point to 'git pull' and 'git push --force' in case of non-fast forward”
  1. push: point to 'git pull' and 'git push --force' in case of non-fast forwardMatthieu Moy, Aug 6, 2009
  2. Michael J GruberAug 6, 2009
  3. Matthieu MoyAug 7, 2009
  4. Michael J GruberAug 7, 2009
  5. Junio C HamanoAug 6, 2009
  6. Re: push: point to 'git pull' and 'git push --force' in case of non-fast forwardNicolas Sebrecht, Aug 6, 2009
  7. Junio C HamanoAug 6, 2009
  8. Matthieu MoyAug 7, 2009
  9. Junio C HamanoAug 7, 2009
  10. Matthieu MoyAug 7, 2009
  11. push: point to 'git pull' and 'git push --force' in case of non-fast forwardMatthieu Moy, Aug 8, 2009
  12. Teemu LikonenAug 8, 2009
  13. Matthieu MoyAug 8, 2009
  14. Junio C HamanoAug 8, 2009
  15. Re: push: point to 'git pull' and 'git push --force' in case of non-fast forwardNicolas Sebrecht, Aug 8, 2009
  16. Matthieu MoyAug 9, 2009
  17. Junio C HamanoAug 9, 2009
  18. Matthieu MoyAug 10, 2009
  19. Junio C HamanoAug 10, 2009
  20. Matthieu MoyAug 10, 2009
  21. Nanako ShiraishiAug 11, 2009
  22. 0/4 make helpful messages optionalJeff King, Sep 6, 2009
  23. 1/4 push: fix english in non-fast-forward messageJeff King, Sep 6, 2009
  24. 2/4 push: re-flow non-fast-forward messageJeff King, Sep 6, 2009
  25. 3/4 push: make non-fast-forward help message configurableJeff King, Sep 6, 2009
  26. Junio C HamanoSep 6, 2009
  27. Jeff KingSep 6, 2009
  28. Junio C HamanoSep 6, 2009
  29. Jeff KingSep 6, 2009
  30. Junio C HamanoSep 6, 2009
  31. Sverre RabbelierSep 6, 2009
  32. Nanako ShiraishiSep 7, 2009
  33. Johannes SixtSep 7, 2009
  34. Mike HommeySep 7, 2009
  35. Jeff KingSep 7, 2009
  36. Matthieu MoySep 7, 2009
  37. Jeff KingSep 7, 2009
  38. Matthieu MoySep 7, 2009
  39. Uri OkrentSep 8, 2009
  40. Jeff KingSep 9, 2009
  41. 0/2 configurable advice messagesJeff King, Sep 9, 2009
  42. 1/2 push: make non-fast-forward help message configurableJeff King, Sep 9, 2009
  43. Junio C HamanoSep 9, 2009
  44. Jeff KingSep 9, 2009
  45. Junio C HamanoSep 9, 2009
  46. 2/2 status: make "how to stage" messages optionalJeff King, Sep 9, 2009
  47. 4/4 status: make "how to stage" messages optionalJeff King, Sep 6, 2009
  48. Matthieu MoySep 6, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.