git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] gitk: fix error when remote tracking branch is deleted

From
Michael Rappazzo <rappazzo@gmail.com>
Date
Sep 13, 2025, 11:31 UTC
Message-ID
<20250913113253.74362-1-rappazzo@gmail.com>

When a remote tracking branch is deleted (e.g., via 'git push --delete origin branch'), the headids array entry for that branch is removed, but upstreamofref may still reference it. This causes gitk to show an error and prevents the Tags and Heads view from opening.

Fix by checking that headids($upstreamofref($n)) exists before accessing it in the refill_reflist function.

Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
---
To reproduce the case:
```
mkdir sample-repo-remote &&
cd sample-repo-remote &&
git init --bare --initial-branch master && 
cd .. &&
git clone sample-repo-remote sample-repo &&
cd sample-repo &&
git commit --allow-empty -m "Sample commit" &&
git push origin master &&
git push origin master:master2 &&
git branch master2 origin/master2 &&
git push --delete origin master2
```
Then run gitk --all then bring up the "Tags and Heads" view.
 gitk | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/gitk b/gitk
index 6e4d71d585..3cfc9ef291 100755
--- a/gitk
+++ b/gitk
@@ -10294,7 +10294,9 @@ proc refill_reflist {} {
         if {![string match "remotes/*" $n] && [string match $reflistfilter $n]} {
             if {[commitinview $headids($n) $curview]} {
                 lappend localrefs [list $n H]
-                if {[info exists upstreamofref($n)] && [commitinview $headids($upstreamofref($n)) $curview]} {
+                if {[info exists upstreamofref($n)] && \
+                        [info exists headids($upstreamofref($n))] && \
+                        [commitinview $headids($upstreamofref($n)) $curview]} {
                     lappend trackedremoterefs [list $upstreamofref($n) R]
                 }
             } else {
-- 
2.51.0
Next: Johannes Sixt
Message 1 of 2 in “gitk: fix error when remote tracking branch is deleted”
  1. gitk: fix error when remote tracking branch is deletedMichael Rappazzo, Sep 13, 2025
  2. Johannes SixtSep 14, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.