# [PATCH] gitk: Fix warning when removing a branch (take 2)

3 messages from 2007-08-16 to 2007-08-16. Participants: Mark Levedahl, Paul Mackerras.
Thread: https://gitlist.dev/t/9548

## Mark Levedahl, 2007-08-16 01:08

Subject: [PATCH] gitk: Fix warning when removing a branch (take 2)
Message-ID: <11872265153600-git-send-email-mdl123@verizon.net>
URL: https://gitlist.dev/e/11872265153600-git-send-email-mdl123%40verizon.net

```
Issue a warning about branch deletion unless gitk knows by name at least
two branch heads pointing to the referenced commit.

Signed-off-by: Mark Levedahl <mdl123@verizon.net>
---

Paul - your commit b1054ac98 did not solve this for me. Playing around, I've
several times received errors like this when trying to delete a branch:

can't read "idheads(f7b9ebd595c954cd0803e6b6f1f0f96a966e04c9 a890c4fca84a2a5c7835fe6432ede3e7c4e5426b)": no such element in array
can't read "idheads(f7b9ebd595c954cd0803e6b6f1f0f96a966e04c9 a890c4fca84a2a5c7835fe6432ede3e7c4e5426b)": no such element in array
    while executing
"if {$idheads($dheads) eq $head} {
	# the stuff on this branch isn't on any other branch
	if {![confirm_popup "The commits on branch $head aren't on an..."
    (procedure "rmbranch" line 13)
    invoked from within
"rmbranch"
    (menu invoke)

However, I took a different approach: if the commit in question has at
least two branch heads as descendents, deleting one will not leave it
dangling. I am not sure your code attempted to do this anyway.


 gitk |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/gitk b/gitk
index aa8baf8..d99a974 100755
--- a/gitk
+++ b/gitk
@@ -6208,10 +6208,16 @@ proc rmbranch {} {
 	return
     }
     set dheads [descheads $id]
-    if {$idheads($dheads) eq $head} {
-	# the stuff on this branch isn't on any other branch
-	if {![confirm_popup "The commits on branch $head aren't on any other\
-			branch.\nReally delete branch $head?"]} return
+    set nheads [llength $dheads]
+    if {$nheads < 2} {
+	catch {
+	    set nheads [llength $idheads($dheads)]
+	}
+	if {$nheads < 2} {
+	    # the stuff on this branch isn't on any other branch that we know about
+	    if {![confirm_popup "The commits on branch $head aren't on any other\
+			    branch.\nReally delete branch $head?"]} return
+	}
     }
     nowbusy rmbranch
     update
--
1.5.3.rc4.85.g3ba6

```

## Paul Mackerras, 2007-08-16 01:57

Subject: Re: [PATCH] gitk: Fix warning when removing a branch (take 2)
Message-ID: <18115.44826.758536.30810@cargo.ozlabs.ibm.com>
URL: https://gitlist.dev/e/18115.44826.758536.30810%40cargo.ozlabs.ibm.com
In-Reply-To: <11872265153600-git-send-email-mdl123@verizon.net>

```
Mark Levedahl writes:

> Paul - your commit b1054ac98 did not solve this for me. Playing around, I've
> several times received errors like this when trying to delete a branch:
> 
> can't read "idheads(f7b9ebd595c954cd0803e6b6f1f0f96a966e04c9 a890c4fca84a2a5c7835fe6432ede3e7c4e5426b)": no such element in array
> can't read "idheads(f7b9ebd595c954cd0803e6b6f1f0f96a966e04c9 a890c4fca84a2a5c7835fe6432ede3e7c4e5426b)": no such element in array

Yeah, I missed that case.  Sorry.

>     while executing
> "if {$idheads($dheads) eq $head} {

I think

	if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {

should be what we want.  Could you try that?

Paul.

```

## Mark Levedahl, 2007-08-16 11:46

Subject: Re: [PATCH] gitk: Fix warning when removing a branch (take 2)
Message-ID: <30e4a070708160446v5bdd177cn81553f5365b06460@mail.gmail.com>
URL: https://gitlist.dev/e/30e4a070708160446v5bdd177cn81553f5365b06460%40mail.gmail.com
In-Reply-To: <18115.44826.758536.30810@cargo.ozlabs.ibm.com>

```
On 8/15/07, Paul Mackerras <paulus@samba.org> wrote:
> Mark Levedahl writes:
>
>
> Yeah, I missed that case.  Sorry.
>
> >     while executing
> > "if {$idheads($dheads) eq $head} {
>
> I think
>
>         if {[llength $dheads] == 1 && $idheads($dheads) eq $head} {
>
> should be what we want.  Could you try that?
>
> Paul.

That works. Thanks.

Mark

```
