{"thread":{"id":"64142","subject":"[PATCH] gitk: fix error when remote tracking branch is deleted","startedAt":"2025-09-13T11:33:04Z","lastAt":"2025-09-14T18:33:15Z","messageCount":2,"participants":["Michael Rappazzo","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"526241","messageId":"20250913113253.74362-1-rappazzo@gmail.com","threadId":"64142","inReplyTo":null,"subject":"[PATCH] gitk: fix error when remote tracking branch is deleted","fromName":"Michael Rappazzo","fromEmail":"rappazzo@gmail.com","sentAt":"2025-09-13T11:31:51Z","receivedAt":"2025-09-13T11:33:04Z","isPatch":true,"sender":{"key":"rappazzo@gmail.com","avatar":"https://avatars.githubusercontent.com/u/525287?v=4"},"body":"When a remote tracking branch is deleted (e.g., via 'git push --delete\norigin branch'), the headids array entry for that branch is removed, but\nupstreamofref may still reference it. This causes gitk to show an error\nand prevents the Tags and Heads view from opening.\n\nFix by checking that headids($upstreamofref($n)) exists before accessing\nit in the refill_reflist function.\n\nSigned-off-by: Michael Rappazzo <rappazzo@gmail.com>\n---\nTo reproduce the case:\n```\nmkdir sample-repo-remote &&\ncd sample-repo-remote &&\ngit init --bare --initial-branch master && \ncd .. &&\ngit clone sample-repo-remote sample-repo &&\ncd sample-repo &&\ngit commit --allow-empty -m \"Sample commit\" &&\ngit push origin master &&\ngit push origin master:master2 &&\ngit branch master2 origin/master2 &&\ngit push --delete origin master2\n```\nThen run gitk --all then bring up the \"Tags and Heads\" view.\n\n\n gitk | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/gitk b/gitk\nindex 6e4d71d585..3cfc9ef291 100755\n--- a/gitk\n+++ b/gitk\n@@ -10294,7 +10294,9 @@ proc refill_reflist {} {\n         if {![string match \"remotes/*\" $n] && [string match $reflistfilter $n]} {\n             if {[commitinview $headids($n) $curview]} {\n                 lappend localrefs [list $n H]\n-                if {[info exists upstreamofref($n)] && [commitinview $headids($upstreamofref($n)) $curview]} {\n+                if {[info exists upstreamofref($n)] && \\\n+                        [info exists headids($upstreamofref($n))] && \\\n+                        [commitinview $headids($upstreamofref($n)) $curview]} {\n                     lappend trackedremoterefs [list $upstreamofref($n) R]\n                 }\n             } else {\n-- \n2.51.0\n\n"},{"id":"526280","messageId":"8cd33841-9959-4cd9-99f2-84cac042ceec@kdbg.org","threadId":"64142","inReplyTo":"20250913113253.74362-1-rappazzo@gmail.com","subject":"Re: [PATCH] gitk: fix error when remote tracking branch is deleted","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2025-09-14T18:32:14Z","receivedAt":"2025-09-14T18:33:15Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 13.09.25 um 13:31 schrieb Michael Rappazzo:\n> When a remote tracking branch is deleted (e.g., via 'git push --delete\n> origin branch'), the headids array entry for that branch is removed, but\n> upstreamofref may still reference it. This causes gitk to show an error\n> and prevents the Tags and Heads view from opening.\n> \n> Fix by checking that headids($upstreamofref($n)) exists before accessing\n> it in the refill_reflist function.\n> \n> Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>\n\nThank you, this looks reasonable. Queued.\n\n> ---\n> To reproduce the case:\n> ```\n> mkdir sample-repo-remote &&\n> cd sample-repo-remote &&\n> git init --bare --initial-branch master && \n> cd .. &&\n> git clone sample-repo-remote sample-repo &&\n> cd sample-repo &&\n> git commit --allow-empty -m \"Sample commit\" &&\n> git push origin master &&\n> git push origin master:master2 &&\n> git branch master2 origin/master2 &&\n> git push --delete origin master2\n> ```\n> Then run gitk --all then bring up the \"Tags and Heads\" view.\n> \n> \n>  gitk | 4 +++-\n>  1 file changed, 3 insertions(+), 1 deletion(-)\n> \n> diff --git a/gitk b/gitk\n> index 6e4d71d585..3cfc9ef291 100755\n> --- a/gitk\n> +++ b/gitk\n> @@ -10294,7 +10294,9 @@ proc refill_reflist {} {\n>          if {![string match \"remotes/*\" $n] && [string match $reflistfilter $n]} {\n>              if {[commitinview $headids($n) $curview]} {\n>                  lappend localrefs [list $n H]\n> -                if {[info exists upstreamofref($n)] && [commitinview $headids($upstreamofref($n)) $curview]} {\n> +                if {[info exists upstreamofref($n)] && \\\n> +                        [info exists headids($upstreamofref($n))] && \\\n> +                        [commitinview $headids($upstreamofref($n)) $curview]} {\n>                      lappend trackedremoterefs [list $upstreamofref($n) R]\n>                  }\n>              } else {\n\n"}]}