Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-import sys, os
+import sys, os, time
from optparse import OptionParser, make_option
from stgit.commands.common import *
help = 'manage development branches'
usage = """%prog [options] branch-name [commit-id]
-Create, list, switch between, rename, or delete development branches
+Create, clone, switch between, rename, or delete development branches
within a git repository. By default, a single branch called 'master'
is always created in a new repository. This subcommand allows you to
-manage several patch series in the same repository.
+manage several patch series in the same repository via GIT branches.
When displaying the branches, the names can be prefixed with
's' (StGIT managed) or 'p' (protected)."""
options = [make_option('-c', '--create',
help = 'create a new development branch',
action = 'store_true'),
+ make_option('--clone',
+ help = 'clone the contents of the current branch',
+ action = 'store_true'),
make_option('--delete',
help = 'delete an existing development branch',
action = 'store_true'),
print 'Branch "%s" created.' % args[0]
return
+ elif options.clone:
+
+ if len(args) == 0:
+ clone = crt_series.get_branch() + \
+ time.strftime('-%C%y%m%d-%H%M%S')
+ elif len(args) == 1:
+ clone = args[0]
+ else:
+ parser.error('incorrect number of arguments')
+
+ check_local_changes()
+ check_conflicts()
+ check_head_top_equal()
+
+ print 'Cloning current branch to "%s"...' % clone,
+ sys.stdout.flush()
+ crt_series.clone(clone)
+ print 'done'
+
+ return
+
elif options.delete:
if len(args) != 1:
self.__init__(to_name)
+ def clone(self, target_series):
+ """Clones a series
+ """
+ base = read_string(self.get_base_file())
+ git.create_branch(target_series, tree_id = base)
+ Series(target_series).init()
+ new_series = Series(target_series)
+
+ # generate an artificial description file
+ write_string(new_series.__descr_file, 'clone of "%s"' % self.__name)
+
+ # clone self's entire series as unapplied patches
+ patches = self.get_applied() + self.get_unapplied()
+ patches.reverse()
+ for p in patches:
+ patch = self.get_patch(p)
+ new_series.new_patch(p, message = patch.get_description(),
+ can_edit = False, unapplied = True,
+ bottom = patch.get_bottom(),
+ top = patch.get_top(),
+ author_name = patch.get_authname(),
+ author_email = patch.get_authemail(),
+ author_date = patch.get_authdate())
+
+ # fast forward the cloned series to self's top
+ new_series.forward_patches(self.get_applied())
+
def delete(self, force = False):
"""Deletes an stgit series
"""