'--protect [--] [<branch>]',
'--unprotect [--] [<branch>]',
'--delete [--force] [--] <branch>',
+ '--cleanup [--force] [--] [<branch>]',
'--description=<description> [--] [<branch>]']
description = """
Create, clone, switch between, rename, or delete development branches
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')]
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:
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:
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():
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()
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,