aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Marinas <catalin.marinas@gmail.com>2010-10-22 16:44:13 +0100
committerCatalin Marinas <catalin.marinas@gmail.com>2010-10-22 16:44:13 +0100
commit0e84c57c4a9d3a198caa4ae2da2a6670e57ad917 (patch)
tree3b4e74f1ed74dca567256e8edeab6c8ef48c1d78
parent2d0f10fb98274e3b3827bf227e42e420f878f1d1 (diff)
downloadstgit-0e84c57c4a9d3a198caa4ae2da2a6670e57ad917.tar.gz
Add a branch --cleanup option
This has been required for some time. If you need to take a branch out of StGit control, use this option (keeps the branch but removes the metadata). Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
-rw-r--r--stgit/commands/branch.py33
-rw-r--r--stgit/stack.py16
2 files changed, 42 insertions, 7 deletions
diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py
index 614c3ae..98141a6 100644
--- a/stgit/commands/branch.py
+++ b/stgit/commands/branch.py
@@ -34,6 +34,7 @@ usage = ['',
'--protect [--] [<branch>]',
'--unprotect [--] [<branch>]',
'--delete [--force] [--] <branch>',
+ '--cleanup [--force] [--] [<branch>]',
'--description=<description> [--] [<branch>]']
description = """
Create, clone, switch between, rename, or delete development branches
@@ -100,6 +101,17 @@ options = [
If you delete the current branch, you are switched to the
"master" branch, if it exists."""),
+ opt('--cleanup', action = 'store_true',
+ short = 'Clean up the StGit metadata for a branch', long = """
+ Remove the StGit information for the current or given branch. If there
+ are patches left in the branch, StGit refuses the operation unless
+ '--force' is given.
+
+ A protected branch cannot be cleaned up; it must be unprotected first
+ (see '--unprotect' above).
+
+ A cleaned up branch can be re-initialised using the 'stg init'
+ command."""),
opt('-d', '--description', short = 'Set the branch description'),
opt('--force', action = 'store_true',
short = 'Force a delete when the series is not empty')]
@@ -137,6 +149,15 @@ def __delete_branch(doomed_name, force = False):
doomed.delete(force)
out.done()
+def __cleanup_branch(name, force = False):
+ branch = stack.Series(name)
+ if branch.get_protected():
+ raise CmdExcpetion('This branch is protected. Clean up is not permitted')
+
+ out.start('Cleaning up branch "%s"' % name)
+ branch.delete(force = force, cleanup = True)
+ out.done()
+
def func(parser, options, args):
if options.create:
@@ -231,6 +252,18 @@ def func(parser, options, args):
log.delete_log(log.default_repo(), args[0])
return
+ elif options.cleanup:
+
+ if not args:
+ name = crt_series.get_name()
+ elif len(args) == 1:
+ name = args[0]
+ else:
+ parser.error('incorrect number of arguments')
+ __cleanup_branch(name, options.force)
+ log.delete_log(log.default_repo(), name)
+ return
+
elif options.list:
if len(args) != 0:
diff --git a/stgit/stack.py b/stgit/stack.py
index f166aea..9cd43a3 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -623,7 +623,7 @@ class Series(PatchSet):
if value:
config.set('branch.%s.stgit.parentbranch' % target_series, value)
- def delete(self, force = False):
+ def delete(self, force = False, cleanup = False):
"""Deletes an stgit series
"""
if self.is_initialised():
@@ -631,7 +631,8 @@ class Series(PatchSet):
self.get_hidden();
if not force and patches:
raise StackException, \
- 'Cannot delete: the series still contains patches'
+ 'Cannot %s: the series still contains patches' % \
+ ('delete', 'clean up')[cleanup]
for p in patches:
self.get_patch(p).delete()
@@ -663,12 +664,13 @@ class Series(PatchSet):
raise StackException('Series directory %s is not empty'
% self._dir())
- try:
- git.delete_branch(self.get_name())
- except git.GitException:
- out.warn('Could not delete branch "%s"' % self.get_name())
+ if not cleanup:
+ try:
+ git.delete_branch(self.get_name())
+ except git.GitException:
+ out.warn('Could not delete branch "%s"' % self.get_name())
+ config.remove_section('branch.%s' % self.get_name())
- 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,