From 42cd003ef2a190ec7f32068676d831ef6478c39f Mon Sep 17 00:00:00 2001 Message-Id: <42cd003ef2a190ec7f32068676d831ef6478c39f.1715161347.git.mdw@distorted.org.uk> From: Mark Wooding Date: Fri, 2 Nov 2007 21:25:58 +0000 Subject: [PATCH] Allow "branch --create" to be given a tag id Organization: Straylight/Edgeware From: Catalin Marinas In the past, this used to lead to a broken branch which could be difficult to even delete. This patch allows the branch to be created properly and be more tolerant to branch deletion. Signed-off-by: Catalin Marinas --- stgit/commands/branch.py | 2 +- stgit/stack.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py index cbb97f6..a18ef2a 100644 --- a/stgit/commands/branch.py +++ b/stgit/commands/branch.py @@ -141,7 +141,7 @@ def func(parser, options, args): # exception in branch = rev_parse() leaves branchpoint unbound branchpoint = None - tree_id = branchpoint or git_id(crt_series, args[1]) + tree_id = git_id(crt_series, branchpoint or args[1]) if parentbranch: out.info('Recording "%s" as parent branch' % parentbranch) diff --git a/stgit/stack.py b/stgit/stack.py index ad1ed2b..f72f83b 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -166,10 +166,17 @@ class Patch(StgitObject): self.create_empty_field('top') def delete(self): - for f in os.listdir(self._dir()): - os.remove(os.path.join(self._dir(), f)) - os.rmdir(self._dir()) - git.delete_ref(self.__top_ref) + if os.path.isdir(self._dir()): + for f in os.listdir(self._dir()): + os.remove(os.path.join(self._dir(), f)) + os.rmdir(self._dir()) + else: + out.warn('Patch directory "%s" does not exist' % self._dir()) + try: + # the reference might not exist if the repository was corrupted + git.delete_ref(self.__top_ref) + except git.GitException, e: + out.warn(str(e)) if git.ref_exists(self.__log_ref): git.delete_ref(self.__log_ref) -- [mdw]