chiark / gitweb /
Allow "branch --create" to be given a tag id
authorCatalin Marinas <catalin.marinas@gmail.com>
Fri, 2 Nov 2007 21:25:58 +0000 (21:25 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 2 Nov 2007 21:25:58 +0000 (21:25 +0000)
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 <catalin.marinas@gmail.com>
stgit/commands/branch.py
stgit/stack.py

index cbb97f67a302a30aea71482dcee5bd784f9bafa9..a18ef2ac34960002fdca622c2d0d17098466aa27 100644 (file)
@@ -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)
index ad1ed2b67ed76b1075a9c11f3548242e7163d9c3..f72f83b0bd4eb3711da5a98b204ae0d5facb55bf 100644 (file)
@@ -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)