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

Re: Minor annoyance with git push

From
Jeff King <peff@peff.net>
Date
Feb 9, 2008, 02:54 UTC
Message-ID
<20080209025431.GF2572@coredump.intra.peff.net>
In-Reply-To
<20080209024636.GE2572@coredump.intra.peff.net>
On Fri, Feb 08, 2008 at 09:46:36PM -0500, Jeff King wrote:
Show 8 quoted lines
> > The local side has the remote refs if the client has fetched recently,
> > so it might be able to tell in some cases. Not with authority (things
> > may have changed on the server side...) but the client might be able
> > to say something less alarming.
> 
> This is actually not that hard to do in the case that we can. Patch will
> follow in a second, though I am not sure it is a good idea (because it
> silently ignores pushing rewinds).

And here it is. Again, I don't think this is the right default behavior. I'm not even sure it is a good idea as configurable behavior. But it's here for comment and for playing with, nonetheless.

-- >8 -- send-pack: treat strict rewinds specially

If you try to push an out-of-date version of a branch, it will generally be rejected as a non-fastforward. This can clutter up the status output of git-push if you have many such branches.

Instead, let's check explicitly whether what we are pushing is a strict subset of what the remote already has. We treat this as a non-error, and don't even print any status unless "verbose" is given. If the push is "forced", then we will push as usual.

Note that we cannot always perform this check accurately; it relies on us having the commit object that the remote claims to have. In the case that we don't, we treat it like an ordinary non-fastforward and reject.

---
diff --git a/cache.h b/cache.h
index 920e731..78fee0b 100644
--- a/cache.h
+++ b/cache.h
@@ -596,6 +596,7 @@ struct ref {
 		REF_STATUS_UPTODATE,
 		REF_STATUS_REMOTE_REJECT,
 		REF_STATUS_EXPECTING_REPORT,
+		REF_STATUS_REJECT_REWIND,
 	} status;
 	char *remote_status;
 	struct ref *peer_ref; /* when renaming */
diff --git a/builtin-send-pack.c b/builtin-send-pack.c
index 454ad8f..9f82b83 100644
--- a/builtin-send-pack.c
+++ b/builtin-send-pack.c
@@ -315,6 +315,7 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count)
 				ref->peer_ref, NULL);
 		break;
 	case REF_STATUS_REJECT_NONFASTFORWARD:
+	case REF_STATUS_REJECT_REWIND:
 		print_ref_status('!', "[rejected]", ref, ref->peer_ref,
 				"non-fast forward");
 		break;
@@ -343,7 +344,8 @@ static void print_push_status(const char *dest, struct ref *refs)
 
 	if (args.verbose) {
 		for (ref = refs; ref; ref = ref->next)
-			if (ref->status == REF_STATUS_UPTODATE)
+			if (ref->status == REF_STATUS_UPTODATE ||
+			    ref->status == REF_STATUS_REJECT_REWIND)
 				n += print_one_push_status(ref, dest, n);
 	}
 
@@ -354,7 +356,8 @@ static void print_push_status(const char *dest, struct ref *refs)
 	for (ref = refs; ref; ref = ref->next) {
 		if (ref->status != REF_STATUS_NONE &&
 		    ref->status != REF_STATUS_UPTODATE &&
-		    ref->status != REF_STATUS_OK)
+		    ref->status != REF_STATUS_OK &&
+		    ref->status != REF_STATUS_REJECT_REWIND)
 			n += print_one_push_status(ref, dest, n);
 	}
 }
@@ -365,6 +368,7 @@ static int refs_pushed(struct ref *ref)
 		switch(ref->status) {
 		case REF_STATUS_NONE:
 		case REF_STATUS_UPTODATE:
+		case REF_STATUS_REJECT_REWIND:
 			break;
 		default:
 			return 1;
@@ -463,8 +467,12 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
 		    (!has_sha1_file(ref->old_sha1)
 		      || !ref_newer(new_sha1, ref->old_sha1));
 
+
 		if (ref->nonfastforward && !ref->force && !args.force_update) {
-			ref->status = REF_STATUS_REJECT_NONFASTFORWARD;
+			if (ref_newer(ref->old_sha1, new_sha1))
+				ref->status = REF_STATUS_REJECT_REWIND;
+			else
+				ref->status = REF_STATUS_REJECT_NONFASTFORWARD;
 			continue;
 		}
 
@@ -522,6 +530,7 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
 		case REF_STATUS_NONE:
 		case REF_STATUS_UPTODATE:
 		case REF_STATUS_OK:
+		case REF_STATUS_REJECT_REWIND:
 			break;
 		default:
 			return -1;
Previous: Jeff KingNext: Johannes Schindelin
Message 16 of 71 in “Minor annoyance with git push”
  1. Martin LanghoffFeb 8, 2008
  2. Martin LanghoffFeb 8, 2008
  3. Junio C HamanoFeb 8, 2008
  4. Steffen ProhaskaFeb 9, 2008
  5. Junio C HamanoFeb 10, 2008
  6. Johannes SchindelinFeb 10, 2008
  7. Johannes SchindelinFeb 8, 2008
  8. Martin LanghoffFeb 8, 2008
  9. Mike HommeyFeb 8, 2008
  10. SeanFeb 8, 2008
  11. Steffen ProhaskaFeb 8, 2008
  12. Johannes SchindelinFeb 8, 2008
  13. Martin LanghoffFeb 8, 2008
  14. Johannes SchindelinFeb 8, 2008
  15. Jeff KingFeb 9, 2008
  16. Jeff KingFeb 9, 2008
  17. Johannes SchindelinFeb 9, 2008
  18. Jeff KingFeb 9, 2008
  19. Steffen ProhaskaFeb 9, 2008
  20. Jeff KingFeb 9, 2008
  21. Junio C HamanoFeb 9, 2008
  22. Jeff KingFeb 9, 2008
  23. Martin LanghoffFeb 9, 2008
  24. Johannes SchindelinFeb 9, 2008
  25. Junio C HamanoFeb 10, 2008
  26. Jeff KingFeb 10, 2008
  27. Johannes SchindelinFeb 10, 2008
  28. [RFC] checkout to notice forks (Re: Minor annoyance with git push)Junio C Hamano, Feb 17, 2008
  29. Daniel BarkalowFeb 17, 2008
  30. Junio C HamanoFeb 17, 2008
  31. Daniel BarkalowFeb 17, 2008
  32. Junio C HamanoFeb 17, 2008
  33. Daniel BarkalowFeb 17, 2008
  34. Jeff KingFeb 17, 2008
  35. Santi BéjarFeb 20, 2008
  36. Martin LanghoffFeb 19, 2008
  37. checkout: tone down the "forked status" diagnostic messagesJunio C Hamano, Feb 20, 2008
  38. Jeff KingFeb 21, 2008
  39. checkout: updates to tracking reportJunio C Hamano, Feb 21, 2008
  40. Jay SoffianFeb 21, 2008
  41. Daniel BarkalowFeb 21, 2008
  42. Jay SoffianFeb 21, 2008
  43. Steffen ProhaskaFeb 9, 2008
  44. Johannes SchindelinFeb 9, 2008
  45. Junio C HamanoFeb 10, 2008
  46. Johannes SchindelinFeb 10, 2008
  47. Jeff KingFeb 10, 2008
  48. Johannes SchindelinFeb 10, 2008
  49. Jeff KingFeb 10, 2008
  50. Johannes SchindelinFeb 10, 2008
  51. Jeff KingFeb 10, 2008
  52. Junio C HamanoFeb 20, 2008
  53. Johannes SchindelinFeb 20, 2008
  54. Jay SoffianFeb 20, 2008
  55. Johannes SchindelinFeb 20, 2008
  56. Steven WalterFeb 21, 2008
  57. Johannes SchindelinFeb 22, 2008
  58. Jeff KingFeb 20, 2008
  59. Junio C HamanoFeb 20, 2008
  60. Jeff KingFeb 20, 2008
  61. Jeff KingFeb 20, 2008
  62. Junio C HamanoFeb 20, 2008
  63. Jeff KingFeb 20, 2008
  64. Wincent ColaiutaFeb 10, 2008
  65. Steven WalterFeb 10, 2008
  66. Johannes SchindelinFeb 10, 2008
  67. Johannes SchindelinFeb 10, 2008
  68. Wincent ColaiutaFeb 10, 2008
  69. Jeff KingFeb 10, 2008
  70. Junio C HamanoFeb 10, 2008
  71. Jeff KingFeb 10, 2008

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.