From: Harald Nordgren via GitGitGadget Date: Sat, 03 Jan 2026 13:00:34 GMT Subject: [PATCH v14 0/2] status: show comparison with push remote tracking branch Message-ID: In-Reply-To: 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 | 171 ++++++++++++++++++++++++------- t/t6040-tracking-info.sh | 210 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 344 insertions(+), 37 deletions(-) base-commit: 68cb7f9e92a5d8e9824f5b52ac3d0a9d8f653dbe Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2138%2FHaraldNordgren%2Fahead_of_main_status-v14 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2138/HaraldNordgren/ahead_of_main_status-v14 Pull-Request: https://github.com/git/git/pull/2138 Range-diff vs v13: 1: a2c160c53e = 1: a2c160c53e refactor: format_branch_comparison in preparation 2: 891239211e ! 2: b9b2f15498 status: show comparison with push remote tracking branch @@ remote.c: int stat_tracking_info(struct branch *branch, int *num_ours, int *num_ +static char *get_remote_push_branch(struct branch *branch, char **full_ref_out) +{ ++ struct remote *remote; + const char *push_remote; ++ char *push_dst = NULL; ++ char *tracking_ref; + const char *resolved; -+ struct strbuf ref_buf = STRBUF_INIT; -+ char *ret = NULL; ++ char *ret; + + if (!branch) + return NULL; @@ remote.c: int stat_tracking_info(struct branch *branch, int *num_ours, int *num_ + if (!push_remote) + return NULL; + -+ strbuf_addf(&ref_buf, "refs/remotes/%s/%s", push_remote, branch->name); ++ remote = remotes_remote_get(the_repository, push_remote); ++ if (!remote) ++ return NULL; ++ ++ push_dst = remote_ref_for_branch(branch, 1); ++ if (!push_dst) { ++ if (remote->push.nr) ++ return NULL; ++ push_dst = xstrdup(branch->refname); ++ } ++ ++ tracking_ref = (char *)tracking_for_push_dest(remote, push_dst, NULL); ++ free(push_dst); ++ ++ if (!tracking_ref) ++ return NULL; + + resolved = refs_resolve_ref_unsafe( + get_main_ref_store(the_repository), -+ ref_buf.buf, ++ tracking_ref, + RESOLVE_REF_READING, + NULL, NULL); + -+ if (resolved) { -+ if (full_ref_out) -+ *full_ref_out = xstrdup(resolved); -+ ret = refs_shorten_unambiguous_ref( -+ get_main_ref_store(the_repository), resolved, 0); ++ if (!resolved) { ++ free(tracking_ref); ++ return NULL; + } + -+ strbuf_release(&ref_buf); ++ 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); + return ret; +} + @@ t/t6040-tracking-info.sh: test_expect_success '--set-upstream-to @{-1}' ' + EOF + test_cmp expect actual +' ++ ++test_expect_success 'status shows remapped push refspec' ' ++ ( ++ cd test && ++ git checkout -b feature8 origin/main && ++ git config remote.origin.push refs/heads/feature8:refs/heads/remapped && ++ git push && ++ advance work && ++ git status >../actual ++ ) && ++ cat >expect <<-EOF && ++ On branch feature8 ++ Your branch is ahead of ${SQ}origin/main${SQ} by 1 commit. ++ ++ Your branch is ahead of ${SQ}origin/remapped${SQ} by 1 commit. ++ (use "git push" to publish your local commits) ++ ++ nothing to commit, working tree clean ++ EOF ++ test_cmp expect actual ++' ++ ++test_expect_success 'status shows remapped push refspec with upstream remote' ' ++ ( ++ cd test && ++ git checkout -b feature9 upstream/main && ++ git config remote.origin.push refs/heads/feature9:refs/heads/remapped && ++ git push origin && ++ advance work && ++ git status >../actual ++ ) && ++ cat >expect <<-EOF && ++ On branch feature9 ++ Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit. ++ ++ Your branch is ahead of ${SQ}origin/remapped${SQ} by 1 commit. ++ (use "git push" to publish your local commits) ++ ++ nothing to commit, working tree clean ++ EOF ++ test_cmp expect actual ++' + test_done -- gitgitgadget