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

From: "Harald Nordgren via GitGitGadget" <[email-masked]>
Date: Fri, 09 Jan 2026 16:41:44 +0000

cc: Chris Torek [email-masked] cc: Yee Cheng Chin
[email-masked] cc: "brian m. carlson" [email-masked]
cc: Ben Knoble [email-masked] cc: "Kristoffer Haugsbakk"
[email-masked] cc: Phillip Wood [email-masked]
cc: Nico Williams [email-masked]

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

 remote.c                 | 174 ++++++++++++++++++++------
 t/t6040-tracking-info.sh | 262 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 401 insertions(+), 35 deletions(-)

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

Range-diff vs v17:

 1:  b62a9feb4d ! 1:  451d7a4986 refactor format_branch_comparison in preparation
     @@ remote.c: int stat_tracking_info(struct branch *branch, int *num_ours, int *num_
      -				_("  (use \"git branch --unset-upstream\" to fixup)\n"));
      -	} else if (!sti) {
      +static void format_branch_comparison(struct strbuf *sb,
     -+				     int sti,
     ++				     bool up_to_date,
      +				     int ours, int theirs,
      +				     const char *branch_name,
      +				     enum ahead_behind_flags abf,
     -+				     int show_divergence_advice)
     ++				     bool show_divergence_advice)
      +{
     -+	if (!sti) {
     ++	if (up_to_date) {
       		strbuf_addf(sb,
       			_("Your branch is up to date with '%s'.\n"),
      -			base);
     @@ remote.c: int format_tracking_info(struct branch *branch, struct strbuf *sb,
      +			strbuf_addstr(sb,
      +				_("  (use \"git branch --unset-upstream\" to fixup)\n"));
      +	} else {
     -+		format_branch_comparison(sb, sti, ours, theirs, base, abf, show_divergence_advice);
     ++		format_branch_comparison(sb, !sti, ours, theirs, base, abf, show_divergence_advice);
      +	}
      +
       	free(base);
 2:  1348542edc ! 2:  02476eb8e6 status: show comparison with push remote tracking branch
     @@ remote.c: int stat_tracking_info(struct branch *branch, int *num_ours, int *num_
      +}
      +
       static void format_branch_comparison(struct strbuf *sb,
     - 				     int sti,
     + 				     bool up_to_date,
       				     int ours, int theirs,
       				     const char *branch_name,
       				     enum ahead_behind_flags abf,
      +				     enum branch_mode_flags advice_flags,
     - 				     int show_divergence_advice)
     + 				     bool show_divergence_advice)
       {
     - 	if (!sti) {
     ++	bool want_push_advice = (advice_flags & BRANCH_MODE_PUSH) &&
     ++		advice_enabled(ADVICE_STATUS_HINTS);
     ++	bool want_pull_advice = (advice_flags & BRANCH_MODE_PULL) &&
     ++		advice_enabled(ADVICE_STATUS_HINTS);
     ++	bool want_divergence_advice = (advice_flags & BRANCH_MODE_PULL) &&
     ++		show_divergence_advice &&
     ++		advice_enabled(ADVICE_STATUS_HINTS);
     ++
     + 	if (up_to_date) {
     + 		strbuf_addf(sb,
     + 			_("Your branch is up to date with '%s'.\n"),
      @@ remote.c: static void format_branch_comparison(struct strbuf *sb,
       		strbuf_addf(sb,
       			    _("Your branch and '%s' refer to different commits.\n"),
       			    branch_name);
      -		if (advice_enabled(ADVICE_STATUS_HINTS))
     -+		if ((advice_flags & BRANCH_MODE_PUSH) &&
     -+		    advice_enabled(ADVICE_STATUS_HINTS))
     ++		if (want_push_advice)
       			strbuf_addf(sb, _("  (use \"%s\" for details)\n"),
       				    "git status --ahead-behind");
       	} else if (!theirs) {
     @@ remote.c: static void format_branch_comparison(struct strbuf *sb,
       			   ours),
       			branch_name, ours);
      -		if (advice_enabled(ADVICE_STATUS_HINTS))
     -+		if ((advice_flags & BRANCH_MODE_PUSH) &&
     -+		    advice_enabled(ADVICE_STATUS_HINTS))
     ++		if (want_push_advice)
       			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 ((advice_flags & BRANCH_MODE_PULL) &&
     -+		    advice_enabled(ADVICE_STATUS_HINTS))
     ++		if (want_pull_advice)
       			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 ((advice_flags & BRANCH_MODE_PULL) &&
     -+		    show_divergence_advice &&
     - 		    advice_enabled(ADVICE_STATUS_HINTS))
     +-		    advice_enabled(ADVICE_STATUS_HINTS))
     ++		if (want_divergence_advice)
       			strbuf_addstr(sb,
       				_("  (use \"git pull\" if you want to integrate the remote branch with yours)\n"));
     + 	}
      @@ remote.c: int format_tracking_info(struct branch *branch, struct strbuf *sb,
       	const char *full_base;
       	char *base;
     @@ remote.c: int format_tracking_info(struct branch *branch, struct strbuf *sb,
       			strbuf_addstr(sb,
       				_("  (use \"git branch --unset-upstream\" to fixup)\n"));
       	} else {
     --		format_branch_comparison(sb, sti, ours, theirs, base, abf, show_divergence_advice);
     -+		format_branch_comparison(sb, sti, ours, theirs, base, abf,
     +-		format_branch_comparison(sb, !sti, ours, theirs, base, abf, show_divergence_advice);
     ++		format_branch_comparison(sb, !sti, ours, theirs, base, abf,
      +					 base_branch_modes, show_divergence_advice);
      +	}
      +
      +	if (push_branch_modes & BRANCH_MODE_PUSH) {
      +		strbuf_addstr(sb, "\n");
     -+		format_branch_comparison(sb, push_sti, push_ours, push_theirs, push, abf,
     -+					 push_branch_modes, 0);
     ++		format_branch_comparison(sb, !push_sti, push_ours, push_theirs, push, abf,
     ++					 push_branch_modes, show_divergence_advice);
       	}
       
       	free(base);

-- 
gitgitgadget