def rename(self, name): old_name = self.name patch_names = self.patchorder.all super(Stack, self).rename(name) old_ref_root = 'refs/patches/%s' % old_name new_ref_root = 'refs/patches/%s' % name empty_id = '0' * 40 ref_updates = '' for pn in patch_names: old_ref = '%s/%s' % (old_ref_root, pn) new_ref = '%s/%s' % (new_ref_root, pn) old_log_ref = old_ref + '.log' new_log_ref = new_ref + '.log' patch_commit_id = self.repository.refs.get(old_ref).sha1 log_commit_id = self.repository.refs.get(old_log_ref).sha1 ref_updates += 'update %s %s %s\n' % (new_ref, patch_commit_id, empty_id) ref_updates += 'update %s %s %s\n' % (new_log_ref, log_commit_id, empty_id) ref_updates += 'delete %s %s\n' % (old_ref, patch_commit_id) ref_updates += 'delete %s %s\n' % (old_log_ref, log_commit_id) self.repository.run(['git', 'update-ref', '--stdin' ]).raw_input(ref_updates).discard_output() config.rename_section('branch.%s.stgit' % old_name, 'branch.%s.stgit' % name) utils.rename( os.path.join(self.repository.directory, self._repo_subdir), old_name, name)
def rename(self, to_name): """Renames a series """ to_stack = Series(to_name) if to_stack.is_initialised(): raise StackException('"%s" already exists' % to_stack.get_name()) patches = self.get_applied() + self.get_unapplied() git.rename_branch(self.get_name(), to_name) for patch in patches: git.rename_ref('refs/patches/%s/%s' % (self.get_name(), patch), 'refs/patches/%s/%s' % (to_name, patch)) git.rename_ref('refs/patches/%s/%s.log' % (self.get_name(), patch), 'refs/patches/%s/%s.log' % (to_name, patch)) if os.path.isdir(self._dir()): rename(os.path.join(self._basedir(), 'patches'), self.get_name(), to_stack.get_name()) # Rename the config section for k in ['branch.%s', 'branch.%s.stgit']: config.rename_section(k % self.get_name(), k % to_name) self.__init__(to_name)
def rename(self, to_name): """Renames a series """ to_stack = Series(to_name) if to_stack.is_initialised(): raise StackException('"%s" already exists' % to_stack.get_name()) patches = self.get_applied() + self.get_unapplied() git.rename_branch(self.get_name(), to_name) for patch in patches: git.rename_ref('refs/patches/%s/%s' % (self.get_name(), patch), 'refs/patches/%s/%s' % (to_name, patch)) git.rename_ref('refs/patches/%s/%s.log' % (self.get_name(), patch), 'refs/patches/%s/%s.log' % (to_name, patch)) if os.path.isdir(self._dir()): rename(os.path.join(self._basedir(), 'patches'), self.get_name(), to_stack.get_name()) # Rename the config section for k in ['branch.%s', 'branch.%s.stgit']: config.rename_section(k % self.get_name(), k % to_name) self.__init__(to_name)
def rename_branch(from_name, to_name): """Rename a git branch.""" rename_ref('refs/heads/%s' % from_name, 'refs/heads/%s' % to_name) try: if get_head_file() == from_name: set_head_file(to_name) except DetachedHeadException: pass # detached HEAD, so the renamee can't be the current branch reflog_dir = os.path.join(basedir.get(), 'logs', 'refs', 'heads') if (os.path.exists(reflog_dir) and os.path.exists(os.path.join(reflog_dir, from_name))): rename(reflog_dir, from_name, to_name)
def rename_branch(from_name, to_name): """Rename a git branch.""" rename_ref('refs/heads/%s' % from_name, 'refs/heads/%s' % to_name) try: if get_head_file() == from_name: set_head_file(to_name) except DetachedHeadException: pass # detached HEAD, so the renamee can't be the current branch reflog_dir = os.path.join(basedir.get(), 'logs', 'refs', 'heads') if os.path.exists(reflog_dir) \ and os.path.exists(os.path.join(reflog_dir, from_name)): rename(reflog_dir, from_name, to_name)
def rename(self, new_name): old_name = self.name patch_names = self.patchorder.all super(Stack, self).rename(new_name) renames = [] for pn in patch_names: renames.append((_patch_ref(old_name, pn), _patch_ref(new_name, pn))) renames.append((_patch_log_ref(old_name, pn), _patch_log_ref(new_name, pn))) renames.append((_stack_state_ref(old_name), _stack_state_ref(new_name))) self.repository.refs.rename('rename %s to %s' % (old_name, new_name), *renames) config.rename_section( 'branch.%s.stgit' % old_name, 'branch.%s.stgit' % new_name, ) utils.rename( os.path.join(self.repository.directory, self._repo_subdir), old_name, new_name, )