stg branch --delete doesn't work
[review@linux-review-ext4]$ git checkout master Switched to branch "master" [master@linux-review-ext4]$ stg branch --delete --force review Deleting branch "review" ... fatal: Needed a single revision stg branch: refs/heads/review does not exist
And it leaves in .git/config
[branch "test2.stgit"]
stackformatversion = 2
So a later stg init also fails.
-aneesh
Quoted 7 lines · Aneesh Kumar
[review@linux-review-ext4]$ git checkout master Switched to branch "master" [master@linux-review-ext4]$ stg branch --delete --force review Deleting branch "review" ... fatal: Needed a single revision stg branch: refs/heads/review does not exist
Quoted 5 lines
And it leaves in .git/config
[branch "test2.stgit"]
stackformatversion = 2So a later stg init also fails.
Ow! You'd think we'd have a test for that ...
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
cover Fix "stg branch --delete"
This fixes the two issues Aneesh reported (failed branch deletion, leftover config stuff), and adds a test. The test is added after the fixes this time, so the test suite passes at every step.
Also available from
git://repo.or.cz/stgit/kha.git safe
---
Karl Hasselström (4):
Add simple test for "stg branch --delete" Properly remove all config for a deleted branch Don't try to delete the branch twice
Don't special-case the "master" branch during branch delete
stgit/commands/branch.py | 10 +--------- stgit/config.py | 7 +++++++ stgit/stack.py | 9 ++------- t/t1005-branch-delete.sh | 29 +++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 16 deletions(-) create mode 100755 t/t1005-branch-delete.sh
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/4 Don't special-case the "master" branch during branch delete
It's unintuitive, unsymmetric and doesn't work if there is no "master". Instead, prohibit deletion of the current branch.
---
stgit/commands/branch.py | 11 ++--------- 1 files changed, 2 insertions(+), 9 deletions(-)
stgit/commands/branch.py +2 -9
@@ -96,17 +96,10 @@ def __delete_branch(doomed_name, force = False): out.start('Deleting branch "%s"' % doomed_name) if __is_current_branch(doomed_name): - check_local_changes() - check_conflicts() - check_head_top_equal() - - if doomed_name != 'master': - git.switch_branch('master') + raise CmdException('Cannot delete the current branch') doomed.delete(force) - - if doomed_name != 'master': - git.delete_branch(doomed_name) + git.delete_branch(doomed_name) out.done()
PATCH 2/4 Don't try to delete the branch twice
In reply to Karl HasselströmWe already delete it in Stack.delete(), so don't do it here too.
---
stgit/commands/branch.py | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
stgit/commands/branch.py +0 -1
@@ -99,7 +99,6 @@ def __delete_branch(doomed_name, force = False): raise CmdException('Cannot delete the current branch') doomed.delete(force) - git.delete_branch(doomed_name) out.done()
PATCH 3/4 Properly remove all config for a deleted branch
In reply to Karl HasselströmThis uses "git-config --remove-section", which was first released in git 1.5.1-rc1. I'm not sure if this is later than what we used to depend on; we already use "git-config --rename-section", but that's been in since git 1.5.0-rc0.
---
stgit/config.py | 7 +++++++ stgit/stack.py | 9 ++------- 2 files changed, 9 insertions(+), 7 deletions(-)
stgit/config.py +7 -0
@@ -76,6 +76,13 @@ class GitConfig: ).returns([0, 1]).run() self.__cache.clear() + def remove_section(self, name): + """Remove a section in the config file. Silently do nothing if + the section doesn't exist.""" + Run('git-repo-config', '--remove-section', name + ).returns([0, 1]).discard_stderr().discard_output() + self.__cache.clear() + def set(self, name, value): Run('git-repo-config', name, value).run() self.__cache[name] = value
stgit/stack.py +2 -7
@@ -744,13 +744,8 @@ class Series(PatchSet): except GitException: out.warn('Could not delete branch "%s"' % self.get_name()) - # Cleanup parent informations - # FIXME: should one day make use of git-config --section-remove, - # scheduled for 1.5.1 - config.unset('branch.%s.remote' % self.get_name()) - config.unset('branch.%s.merge' % self.get_name()) - config.unset('branch.%s.stgit.parentbranch' % self.get_name()) - config.unset(self.format_version_key()) + config.remove_section('branch.%s' % self.get_name()) + config.remove_section('branch.%s.stgit' % self.get_name()) def refresh_patch(self, files = None, message = None, edit = False, show_patch = False,
PATCH 4/4 Add simple test for "stg branch --delete"
In reply to Karl Hasselström---
t/t1005-branch-delete.sh | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) create mode 100755 t/t1005-branch-delete.sh
t/t1005-branch-delete.sh new file +29 -0
@@ -0,0 +1,29 @@ +#!/bin/sh + +test_description='Attempt to delete branches' + +. ./test-lib.sh + +stg init + +test_expect_success 'Create a branch (and switch to it)' ' + stg branch --create foo + ' + +test_expect_success 'Delete a branch' ' + stg branch --delete master + ' + +test_expect_success 'Make sure the branch ref was deleted' ' + [ -z "$(git show-ref | grep master | tee /dev/stderr)" ] + ' + +test_expect_success 'Make sure the branch config was deleted' ' + [ -z "$(git config -l | grep branch\\.master | tee /dev/stderr)" ] + ' + +test_expect_success 'Make sure the branch files were deleted' ' + [ -z "$(find .git -type f | grep master | tee /dev/stderr)" ] + ' + +test_done