From ff432158b249307d44177db1adc569f726eefb18 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Fri, 7 Dec 2007 21:19:25 +0000 Subject: [PATCH] Some clean-up of the branch manipulation commands Organization: Straylight/Edgeware From: Catalin Marinas 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 --- stgit/commands/branch.py | 7 ++----- stgit/stack.py | 8 ++++---- t/t1000-branch-create.sh | 9 ++++++++- t/t1005-branch-delete.sh | 5 +++++ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py index dd02103..50684bb 100644 --- a/stgit/commands/branch.py +++ b/stgit/commands/branch.py @@ -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): diff --git a/stgit/stack.py b/stgit/stack.py index 3139822..f1f75e4 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -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()) diff --git a/t/t1000-branch-create.sh b/t/t1000-branch-create.sh index bc796b4..f024501 100755 --- a/t/t1000-branch-create.sh +++ b/t/t1000-branch-create.sh @@ -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 ' diff --git a/t/t1005-branch-delete.sh b/t/t1005-branch-delete.sh index 7a0872e..00fc9eb 100755 --- a/t/t1005-branch-delete.sh +++ b/t/t1005-branch-delete.sh @@ -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)" ] ' -- [mdw]