cli: refine gerrit metadata discovery from local branch configs

This commit is contained in:
Paul Irish 2026-04-27 10:29:43 -07:00
parent bbbcc0f0f2
commit 661c9dbb9d
No known key found for this signature in database

View file

@ -98,7 +98,8 @@ filterarg=${GIT_RECENT_QUERY:+"--filter=$GIT_RECENT_QUERY"}
# Chromium/Gerrit/GitHub hackers may want reference to their relevant CL/PR.
if [[ "$show_links" = true ]]; then
# 1. Try Gerrit/git-cl configs (very fast, but only works if cl has been uploaded)
GERRIT_CONFIGS=$(git config --get-regexp "branch\..*\.gerritissue" 2>/dev/null)
# We fetch all gerrit-related configs for branches to avoid multiple git calls.
GERRIT_CONFIGS=$(git config --get-regexp "branch\..*\.gerrit" 2>/dev/null)
GERRIT_SERVER=$(git config --get "gerritserver" 2>/dev/null)
GERRIT_PROJECT=$(git config --get "gerrit.project" 2>/dev/null)
@ -163,11 +164,21 @@ _browse_branches() {
if [[ "$sl" == true ]]; then
# Check Gerrit configs first
cl_num=$(echo "$gc" | grep "branch\.${branch_name}\.gerritissue" | awk '{print $2}')
if [[ -n "$cl_num" && -n "$gs" ]]; then
if [[ -n "$cl_num" ]]; then
# Use branch-specific server if available, otherwise fallback to inferred/global server
branch_server=$(echo "$gc" | grep "branch\.${branch_name}\.gerritserver" | awk '{print $2}' | sed -E 's|https?://||')
current_gs="${branch_server:-$gs}"
# Special case: If we inferred an internal Google host but the config has a public one,
# we prefer the internal one for better connectivity/UX.
if [[ "$gs" == *.git.corp.google.com && "$branch_server" == *.googlesource.com ]]; then
current_gs="$gs"
fi
if [[ -n "$gp" ]]; then
link_url="https://$gs/c/$gp/+/$cl_num"
link_url="https://$current_gs/c/$gp/+/$cl_num"
else
link_url="https://$gs/c/$cl_num"
link_url="https://$current_gs/c/$cl_num"
fi
link_label="$cl_num"
elif [[ -n "$cs" ]]; then