+ 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)
+ 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(applied)
+
+ # Clone remote and merge settings
+ 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)
+
+ 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(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.__current_file):
+ os.remove(self.__current_file)
+ if os.path.exists(self.__descr_file):
+ os.remove(self.__descr_file)
+ if not os.listdir(self.__patch_dir):
+ os.rmdir(self.__patch_dir)
+ else:
+ print 'Patch directory %s is not empty.' % self.__name
+ if not os.listdir(self._dir()):
+ remove_dirs(os.path.join(self.__base_dir, 'patches'),
+ self.__name)
+ else:
+ print 'Series directory %s is not empty.' % self.__name
+ if not os.listdir(self.__refs_dir):
+ remove_dirs(os.path.join(self.__base_dir, 'refs', 'patches'),
+ self.__name)
+ else:
+ print 'Refs directory %s is not empty.' % self.__refs_dir
+
+ if os.path.exists(self.__base_file):
+ remove_file_and_dirs(
+ os.path.join(self.__base_dir, 'refs', 'bases'), self.__name)
+
+ def refresh_patch(self, files = None, message = None, edit = False,
+ show_patch = False,
+ cache_update = True,