# [PATCH] Fix "stg branch --delete" on a nonexistent branch

2 messages from 2008-02-13 to 2008-02-14. Participants: Toby Allsopp, Karl Hasselström.
Thread: https://gitlist.dev/t/12080

## Toby Allsopp, 2008-02-13 22:25

Subject: [PATCH] Fix "stg branch --delete" on a nonexistent branch
Message-ID: <87r6fgjwoi.fsf@nav-akl-pcn-343.mitacad.com>
URL: https://gitlist.dev/e/87r6fgjwoi.fsf%40nav-akl-pcn-343.mitacad.com

```
Before this patch, I get the following:

 $ stg branch --delete tmp
 Deleting branch "tmp" ... Traceback (most recent call last):
   File "/usr/bin/stg", line 43, in ?
     main()
   File "/var/lib/python-support/python2.4/stgit/main.py", line 281, in main
     command.func(parser, options, args)
   File "/var/lib/python-support/python2.4/stgit/commands/branch.py", line 190, in func
     __delete_branch(args[0], options.force)
   File "/var/lib/python-support/python2.4/stgit/commands/branch.py", line 100, in __delete_branch
     doomed.delete(force)
   File "/var/lib/python-support/python2.4/stgit/stack.py", line 758, in delete
     except GitException:
 NameError: global name 'GitException' is not defined

After it, I get:

 Deleting branch "tmp" ...
   Warning: Could not delete branch "tmp"
 done

Signed-off-by: Toby Allsopp <toby.allsopp@navman.co.nz>
---
 stgit/stack.py           |    2 +-
 t/t1005-branch-delete.sh |    4 ++++
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/stgit/stack.py b/stgit/stack.py
index 7fe9f2b..1f01295 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -661,7 +661,7 @@ class Series(PatchSet):
 
         try:
             git.delete_branch(self.get_name())
-        except GitException:
+        except git.GitException:
             out.warn('Could not delete branch "%s"' % self.get_name())
 
         config.remove_section('branch.%s' % self.get_name())
diff --git a/t/t1005-branch-delete.sh b/t/t1005-branch-delete.sh
index 00fc9eb..e061baf 100755
--- a/t/t1005-branch-delete.sh
+++ b/t/t1005-branch-delete.sh
@@ -19,6 +19,10 @@ test_expect_success 'Create a non-StGIT branch and delete it' '
     stg branch --delete bar
     '
 
+test_expect_success 'Delete a nonexistent branch' '
+   stg branch --delete bar
+   '
+
 test_expect_success 'Make sure the branch ref was deleted' '
     [ -z "$(git show-ref | grep master | tee /dev/stderr)" ]
     '
-- 
1.5.4.1.97.g40aab-dirty

```

## Karl Hasselström, 2008-02-14 00:06

Subject: Re: [PATCH] Fix "stg branch --delete" on a nonexistent branch
Message-ID: <20080214000616.GB10335@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20080214000616.GB10335%40diana.vm.bytemark.co.uk
In-Reply-To: <87r6fgjwoi.fsf@nav-akl-pcn-343.mitacad.com>

```
On 2008-02-14 11:25:29 +1300, Toby Allsopp wrote:

>  stgit/stack.py           |    2 +-
>  t/t1005-branch-delete.sh |    4 ++++
>  2 files changed, 5 insertions(+), 1 deletions(-)

Thanks -- and with a test case! I'll push this out on

  git://repo.or.cz/stgit/kha.git safe

later tonight.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

```
