Thread (141 messages) 141 messages, 8 authors, 2026-03-04
STALE115d
Revisions (14)
  1. v12 [diff vs current]
  2. v13 [diff vs current]
  3. v14 [diff vs current]
  4. v15 [diff vs current]
  5. v16 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 v16 0/2] status: show comparison with push remote tracking branch

From: Harald Nordgren via GitGitGadget <hidden>
Date: 2026-01-04 23:21: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
cc: Nico Williams nico@cryptonector.com

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

 remote.c                 | 171 ++++++++++++++++++++++++-------
 t/t6040-tracking-info.sh | 210 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 345 insertions(+), 36 deletions(-)


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

Range-diff vs v15:

 1:  cf4e9779c5 = 1:  cf4e9779c5 refactor format_branch_comparison in preparation
 2:  a435cf4ce4 ! 2:  06cb483f61 status: show comparison with push remote tracking branch
     @@ remote.c
       
       enum map_direction { FROM_SRC, FROM_DST };
       
     -+enum branch_type {
     -+	PUSH = 1 << 0,
     -+	PULL = 1 << 1
     ++enum branch_mode_flags {
     ++	BRANCH_MODE_PULL = (1 << 0),
     ++	BRANCH_MODE_PUSH = (1 << 1),
      +};
      +
       struct counted_string {
     @@ remote.c: int stat_tracking_info(struct branch *branch, int *num_ours, int *num_
      +
      +	if (full_ref_out)
      +		*full_ref_out = xstrdup(resolved);
     ++
      +	ret = refs_shorten_unambiguous_ref(
      +		get_main_ref_store(the_repository), resolved, 0);
      +	free(tracking_ref);
     @@ remote.c: int stat_tracking_info(struct branch *branch, int *num_ours, int *num_
       				     int ours, int theirs,
       				     const char *branch_name,
       				     enum ahead_behind_flags abf,
     -+				     enum branch_type bt,
     ++				     enum branch_mode_flags advice_flags,
       				     int show_divergence_advice)
       {
       	if (abf == AHEAD_BEHIND_QUICK) {
     @@ remote.c: static void format_branch_comparison(struct strbuf *sb,
       			   ours),
       			branch_name, ours);
      -		if (advice_enabled(ADVICE_STATUS_HINTS))
     -+		if ((bt & PUSH) && advice_enabled(ADVICE_STATUS_HINTS))
     ++		if ((advice_flags & BRANCH_MODE_PUSH) &&
     ++		    advice_enabled(ADVICE_STATUS_HINTS))
       			strbuf_addstr(sb,
       				_("  (use \"git push\" to publish your local commits)\n"));
       	} else if (!ours) {
     @@ remote.c: static void format_branch_comparison(struct strbuf *sb,
       			   theirs),
       			branch_name, theirs);
      -		if (advice_enabled(ADVICE_STATUS_HINTS))
     -+		if ((bt & PULL) && advice_enabled(ADVICE_STATUS_HINTS))
     ++		if ((advice_flags & BRANCH_MODE_PULL) &&
     ++		    advice_enabled(ADVICE_STATUS_HINTS))
       			strbuf_addstr(sb,
       				_("  (use \"git pull\" to update your local branch)\n"));
       	} else {
     @@ remote.c: static void format_branch_comparison(struct strbuf *sb,
       			   ours + theirs),
       			branch_name, ours, theirs);
      -		if (show_divergence_advice &&
     -+		if ((bt & PULL) &&
     ++		if ((advice_flags & BRANCH_MODE_PULL) &&
      +		    show_divergence_advice &&
       		    advice_enabled(ADVICE_STATUS_HINTS))
       			strbuf_addstr(sb,
     @@ remote.c: int format_tracking_info(struct branch *branch, struct strbuf *sb,
       	const char *full_base;
       	char *base;
       	int upstream_is_gone = 0;
     -+	enum branch_type base_bt = PUSH | PULL;
     ++	enum branch_mode_flags base_branch_modes = BRANCH_MODE_PULL | BRANCH_MODE_PUSH;
      +	int push_ours, push_theirs, push_sti;
      +	char *full_push = NULL;
      +	char *push = NULL;
     -+	enum branch_type push_bt = 0;
     ++	enum branch_mode_flags push_branch_modes = 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,
      +		push_sti = stat_branch_pair(branch->refname, full_push,
      +					   &push_ours, &push_theirs, abf);
      +		if (push_sti >= 0) {
     -+			base_bt = PULL;
     -+			push_bt = PUSH;
     ++			base_branch_modes = BRANCH_MODE_PULL;
     ++			push_branch_modes = BRANCH_MODE_PUSH;
      +		}
      +	}
      +
     @@ remote.c: int format_tracking_info(struct branch *branch, struct strbuf *sb,
       				_("  (use \"git branch --unset-upstream\" to fixup)\n"));
       	} else {
      -		format_branch_comparison(sb, ours, theirs, base, abf, show_divergence_advice);
     -+		format_branch_comparison(sb, ours, theirs, base, abf, base_bt,
     -+					 show_divergence_advice);
     ++		format_branch_comparison(sb, ours, theirs, base, abf,
     ++					 base_branch_modes, show_divergence_advice);
      +	}
      +
     -+	if (push_bt & PUSH) {
     ++	if (push_branch_modes & BRANCH_MODE_PUSH) {
      +		strbuf_addstr(sb, "\n");
      +		format_branch_comparison(sb, push_ours, push_theirs, push, abf,
     -+					 push_bt, 0);
     ++					 push_branch_modes, 0);
       	}
       
       	free(base);

-- 
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