From 660ba985e6200c32fafdc545a74bd27e84cc2397 Mon Sep 17 00:00:00 2001 From: Chuck Lever Date: Sat, 5 Nov 2005 17:47:06 -0500 Subject: [PATCH] Generalize branch renaming The Series object already has the path names of all the pieces we need to rename, so let's reuse that information. Extract the rename branch logic from the "stg branch" command and put it in stack.py. Signed-off-by: Chuck Lever --- stgit/commands/branch.py | 28 +++++----------------------- stgit/stack.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py index 9b880f1..8997e20 100644 --- a/stgit/commands/branch.py +++ b/stgit/commands/branch.py @@ -95,28 +95,6 @@ def delete_branch(doomed_name, force = False): print 'Branch "%s" has been deleted.' % doomed_name -def rename_branch(from_name, to_name): - if from_name == 'master': - raise CmdException, 'Renaming the master branch is not allowed' - - to_patchdir = os.path.join(git.base_dir, 'patches', to_name) - if os.path.isdir(to_patchdir): - raise CmdException, '"%s" already exists' % to_patchdir - to_base = os.path.join(git.base_dir, 'refs', 'bases', to_name) - if os.path.isfile(to_base): - raise CmdException, '"%s" already exists' % to_base - - git.rename_branch(from_name, to_name) - - from_patchdir = os.path.join(git.base_dir, 'patches', from_name) - if os.path.isdir(from_patchdir): - os.rename(from_patchdir, to_patchdir) - from_base = os.path.join(git.base_dir, 'refs', 'bases', from_name) - if os.path.isfile(from_base): - os.rename(from_base, to_base) - - print 'Renamed branch "%s" as "%s".' % (from_name, to_name) - def func(parser, options, args): if options.create: @@ -177,7 +155,11 @@ def func(parser, options, args): if len(args) != 2: parser.error('incorrect number of arguments') - rename_branch(args[0], args[1]) + + stack.Series(args[0]).rename(args[1]) + + print 'Renamed branch "%s" as "%s".' % (args[0], args[1]) + return elif options.unprotect: diff --git a/stgit/stack.py b/stgit/stack.py index edabb27..1ffeaee 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -400,6 +400,24 @@ class Series: create_empty_file(self.__descr_file) self.__begin_stack_check() + def rename(self, to_name): + """Renames a series + """ + to_stack = Series(to_name) + if os.path.isdir(to_stack.__patch_dir): + raise StackException, '"%s" already exists' % to_stack.__patch_dir + if os.path.isfile(to_stack.__base_file): + raise StackException, '"%s" already exists' % to_stack.__base_file + + git.rename_branch(self.__name, to_name) + + if os.path.isdir(self.__patch_dir): + os.rename(self.__patch_dir, to_stack.__patch_dir) + if os.path.isfile(self.__base_file): + os.rename(self.__base_file, to_stack.__base_file) + + self.__init__(to_name) + def delete(self, force = False): """Deletes an stgit series """ -- 2.11.0