+ if os.path.isdir(self._dir()):
+ rename(os.path.join(self.__base_dir, 'patches'),
+ self.__name, to_stack.__name)
+ if os.path.exists(self.__refs_dir):
+ rename(os.path.join(self.__base_dir, 'refs', 'patches'),
+ self.__name, to_stack.__name)
+
+ # Rename the config section
+ config.rename_section("branch.%s" % self.__name,
+ "branch.%s" % to_name)
+
+ self.__init__(to_name)
+
+ def clone(self, target_series):
+ """Clones a series
+ """
+ try:
+ # allow cloning of branches not under StGIT control
+ base = self.get_base()
+ except:
+ base = git.get_head()
+ Series(target_series).init(create_at = base)
+ new_series = Series(target_series)
+
+ # generate an artificial description file
+ new_series.set_description('clone of "%s"' % self.__name)
+
+ # clone self's entire series as unapplied patches
+ try:
+ # allow cloning of branches not under StGIT control
+ applied = self.get_applied()
+ unapplied = self.get_unapplied()
+ patches = applied + unapplied
+ patches.reverse()
+ except:
+ patches = applied = unapplied = []
+ for p in patches:
+ patch = self.get_patch(p)
+ newpatch = 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())
+ if patch.get_log():
+ print "setting log to %s" % patch.get_log()
+ newpatch.set_log(patch.get_log())
+ else:
+ print "no log for %s" % patchname
+
+ # fast forward the cloned series to self's top
+ new_series.forward_patches(applied)
+
+ # Clone parent informations
+ value = config.get('branch.%s.remote' % self.__name)
+ if value:
+ config.set('branch.%s.remote' % target_series, value)
+
+ value = config.get('branch.%s.merge' % self.__name)
+ if value:
+ config.set('branch.%s.merge' % target_series, value)
+
+ value = config.get('branch.%s.stgit.parentbranch' % self.__name)
+ if value:
+ config.set('branch.%s.stgit.parentbranch' % target_series, value)
+
+ def delete(self, force = False):
+ """Deletes an stgit series
+ """
+ if self.is_initialised():
+ patches = self.get_unapplied() + self.get_applied()
+ if not force and patches:
+ raise StackException, \
+ 'Cannot delete: the series still contains patches'
+ for p in patches:
+ Patch(p, self.__patch_dir, self.__refs_dir).delete()
+
+ # remove the trash directory
+ for fname in os.listdir(self.__trash_dir):
+ os.remove(os.path.join(self.__trash_dir, fname))
+ os.rmdir(self.__trash_dir)
+
+ # FIXME: find a way to get rid of those manual removals
+ # (move functionality to StgitObject ?)
+ if os.path.exists(self.__applied_file):
+ os.remove(self.__applied_file)
+ if os.path.exists(self.__unapplied_file):
+ os.remove(self.__unapplied_file)
+ if os.path.exists(self.__hidden_file):
+ os.remove(self.__hidden_file)
+ if os.path.exists(self.__descr_file):
+ os.remove(self.__descr_file)
+ if os.path.exists(self._dir()+'/orig-base'):
+ os.remove(self._dir()+'/orig-base')
+
+ if not os.listdir(self.__patch_dir):
+ os.rmdir(self.__patch_dir)
+ else:
+ print 'Patch directory %s is not empty.' % self.__patch_dir
+
+ try:
+ os.removedirs(self._dir())
+ except OSError:
+ raise StackException, 'Series directory %s is not empty.' % self._dir()
+
+ try:
+ os.removedirs(self.__refs_dir)
+ except OSError:
+ print 'Refs directory %s is not empty.' % self.__refs_dir
+
+ # 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.__name)
+ config.unset('branch.%s.merge' % self.__name)
+ config.unset('branch.%s.stgit.parentbranch' % self.__name)
+
+ def refresh_patch(self, files = None, message = None, edit = False,
+ show_patch = False,