Some clean-up of the branch manipulation commands
authorCatalin Marinas <catalin.marinas@gmail.com>
Fri, 7 Dec 2007 21:19:25 +0000 (21:19 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 7 Dec 2007 21:19:25 +0000 (21:19 +0000)
A GIT branch couldn't be deleted if it wasn't a StGIT stack. Added
tests for the creation of branches when the current branch isn't a
stack.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/branch.py
stgit/stack.py
t/t1000-branch-create.sh
t/t1005-branch-delete.sh

index dd02103..50684bb 100644 (file)
@@ -91,16 +91,13 @@ def __print_branch(branch_name, length):
 def __delete_branch(doomed_name, force = False):
     doomed = stack.Series(doomed_name)
 
+    if __is_current_branch(doomed_name):
+        raise CmdException('Cannot delete the current branch')
     if doomed.get_protected():
         raise CmdException, 'This branch is protected. Delete is not permitted'
 
     out.start('Deleting branch "%s"' % doomed_name)
-
-    if __is_current_branch(doomed_name):
-        raise CmdException('Cannot delete the current branch')
-
     doomed.delete(force)
-
     out.done()
 
 def func(parser, options, args):
index 3139822..f1f75e4 100644 (file)
@@ -753,10 +753,10 @@ class Series(PatchSet):
                 raise StackException('Series directory %s is not empty'
                                      % self._dir())
 
-            try:
-                git.delete_branch(self.get_name())
-            except GitException:
-                out.warn('Could not delete branch "%s"' % self.get_name())
+        try:
+            git.delete_branch(self.get_name())
+        except GitException:
+            out.warn('Could not delete branch "%s"' % self.get_name())
 
         config.remove_section('branch.%s' % self.get_name())
         config.remove_section('branch.%s.stgit' % self.get_name())
index bc796b4..f024501 100755 (executable)
@@ -10,10 +10,17 @@ Exercises the "stg branch" commands.
 
 . ./test-lib.sh
 
-stg init
+test_expect_success \
+    'Create a branch when the current one is not an StGIT stack' '
+    git branch origin &&
+    stg branch --create new origin &&
+    test $(stg branch) == "new"
+'
 
 test_expect_success \
     'Create a spurious patches/ entry' '
+    stg branch master &&
+    stg init &&
     find .git -name foo | xargs rm -rf &&
     mkdir -p .git/patches && touch .git/patches/foo
 '
index 7a0872e..00fc9eb 100755 (executable)
@@ -14,6 +14,11 @@ test_expect_success 'Delete a branch' '
     stg branch --delete master
     '
 
+test_expect_success 'Create a non-StGIT branch and delete it' '
+    git branch bar &&
+    stg branch --delete bar
+    '
+
 test_expect_success 'Make sure the branch ref was deleted' '
     [ -z "$(git show-ref | grep master | tee /dev/stderr)" ]
     '