Thread (141 messages) 141 messages, 8 authors, 2026-03-04
STALE108d
Revisions (14)
  1. v12 [diff vs current]
  2. v13 current
  3. v14 [diff vs current]
  4. v15 [diff vs current]
  5. v16 [diff vs current]
  6. v17 [diff vs current]
  7. v18 [diff vs current]
  8. v19 [diff vs current]
  9. v20 [diff vs current]
  10. v21 [diff vs current]
  11. v22 [diff vs current]
  12. v23 [diff vs current]
  13. v24 [diff vs current]
  14. v25 [diff vs current]

[PATCH v13 0/2] status: show comparison with push remote tracking branch

From: Harald Nordgren via GitGitGadget <hidden>
Date: 2026-01-03 03:08:25

cc: Chris Torek chris.torek@gmail.com cc: Yee Cheng Chin
ychin.macvim@gmail.com cc: "brian m. carlson" sandals@crustytoothpaste.net
cc: Ben Knoble ben.knoble@gmail.com cc: "Kristoffer Haugsbakk"
kristofferhaugsbakk@fastmail.com cc: Phillip Wood phillip.wood123@gmail.com

Harald Nordgren (2):
  refactor: format_branch_comparison in preparation
  status: show comparison with push remote tracking branch

 remote.c                 | 152 ++++++++++++++++++++++++++---------
 t/t6040-tracking-info.sh | 168 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 283 insertions(+), 37 deletions(-)


base-commit: 68cb7f9e92a5d8e9824f5b52ac3d0a9d8f653dbe
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2138%2FHaraldNordgren%2Fahead_of_main_status-v13
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2138/HaraldNordgren/ahead_of_main_status-v13
Pull-Request: https://github.com/git/git/pull/2138

Range-diff vs v12:

 1:  a2c160c53e = 1:  a2c160c53e refactor: format_branch_comparison in preparation
 2:  a586038d1f ! 2:  891239211e status: show comparison with push remote tracking branch
     @@ remote.c: int format_tracking_info(struct branch *branch, struct strbuf *sb,
       	const char *full_base;
       	char *base;
       	int upstream_is_gone = 0;
     -+	int push_ours = 0, push_theirs = 0;
     -+	int push_stat_result = -1;
     -+	int will_show_push_comparison = 0;
     ++	int push_ours, push_theirs, push_sti;
     ++	char *full_push = NULL;
     ++	char *push = NULL;
     ++	int show_push_comparison = 0;
       
       	sti = stat_tracking_info(branch, &ours, &theirs, &full_base, 0, abf);
       	if (sti < 0) {
     @@ remote.c: int format_tracking_info(struct branch *branch, struct strbuf *sb,
       	base = refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
       					    full_base, 0);
       
     -+	if (!upstream_is_gone && abf != AHEAD_BEHIND_QUICK) {
     -+		char *push_full = NULL;
     -+		char *push_short = get_remote_push_branch(branch, &push_full);
     -+
     -+		if (push_short && strcmp(base, push_short)) {
     -+			push_stat_result = stat_branch_pair(branch->refname, push_full,
     -+							    &push_ours, &push_theirs, abf);
     -+			if (push_stat_result >= 0)
     -+				will_show_push_comparison = 1;
     -+		}
     -+
     -+		free(push_short);
     -+		free(push_full);
     ++	push = get_remote_push_branch(branch, &full_push);
     ++	if (push && strcmp(base, push)) {
     ++		push_sti = stat_branch_pair(branch->refname, full_push,
     ++					   &push_ours, &push_theirs, abf);
     ++		if (push_sti >= 0)
     ++			show_push_comparison = 1;
      +	}
      +
       	format_branch_comparison(sb, ours, theirs, base, upstream_is_gone, abf, sti);
       	if (sti > 0 && abf != AHEAD_BEHIND_QUICK) {
      -		if (!theirs && advice_enabled(ADVICE_STATUS_HINTS)) {
     -+		if (!theirs && !will_show_push_comparison &&
     ++		if (!theirs && !show_push_comparison &&
      +		    advice_enabled(ADVICE_STATUS_HINTS)) {
       			strbuf_addstr(sb,
       				_("  (use \"git push\" to publish your local commits)\n"));
     @@ remote.c: int format_tracking_info(struct branch *branch, struct strbuf *sb,
       		}
       	}
       
     -+	if (will_show_push_comparison) {
     -+		char *push_full = NULL;
     -+		char *push_short = get_remote_push_branch(branch, &push_full);
     -+
     -+		if (push_short && strcmp(base, push_short)) {
     -+			strbuf_addstr(sb, "\n");
     -+			format_branch_comparison(sb, push_ours, push_theirs, push_short, 0, abf,
     -+						push_ours || push_theirs);
     -+			if (push_ours > 0 && push_theirs == 0 &&
     -+			    advice_enabled(ADVICE_STATUS_HINTS)) {
     ++	if (show_push_comparison) {
     ++		strbuf_addstr(sb, "\n");
     ++		format_branch_comparison(sb, push_ours, push_theirs, push, 0, abf, push_sti);
     ++		if (push_sti > 0 && abf != AHEAD_BEHIND_QUICK) {
     ++			if (!push_theirs && advice_enabled(ADVICE_STATUS_HINTS)) {
      +				strbuf_addstr(sb,
      +					_("  (use \"git push\" to publish your local commits)\n"));
      +			}
      +		}
     -+
     -+		free(push_short);
     -+		free(push_full);
      +	}
      +
       	free(base);
     ++	free(full_push);
     ++	free(push);
       	return 1;
       }
     + 
      
       ## t/t6040-tracking-info.sh ##
      @@ t/t6040-tracking-info.sh: test_expect_success '--set-upstream-to @{-1}' '

-- 
gitgitgadget
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help