Allow the cloning of branches not under StGIT control
authorCatalin Marinas <catalin.marinas@gmail.com>
Tue, 5 Dec 2006 22:07:24 +0000 (22:07 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Tue, 5 Dec 2006 22:07:24 +0000 (22:07 +0000)
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
TODO
stgit/stack.py
t/t1002-branch-clone.sh [new file with mode: 0755]

diff --git a/TODO b/TODO
index 2f40657..3b07ff6 100644 (file)
--- a/TODO
+++ b/TODO
@@ -31,13 +31,6 @@ The future, when time allows or if someone else does them:
 
 Bugs:
 
 
 Bugs:
 
-- cannot branch off arbitrary branch when current branch not under
-stgit control:
-|$ stg branch 
-|bar
-|$ stg branch -c foo2 foo
-|stg branch: Branch "bar" not initialised
-
 - patch created with empty description ("stg new" and quit editor
 without saving) confuse "series -d":
 |$ stg series -ds
 - patch created with empty description ("stg new" and quit editor
 without saving) confuse "series -d":
 |$ stg series -ds
index 69fa03b..0a20f4b 100644 (file)
@@ -534,7 +534,11 @@ class Series(StgitObject):
     def clone(self, target_series):
         """Clones a series
         """
     def clone(self, target_series):
         """Clones a series
         """
-        base = read_string(self.get_base_file())
+        try:
+            # allow cloning of branches not under StGIT control
+            base = read_string(self.get_base_file())
+        except:
+            base = git.get_head()
         Series(target_series).init(create_at = base)
         new_series = Series(target_series)
 
         Series(target_series).init(create_at = base)
         new_series = Series(target_series)
 
@@ -542,8 +546,14 @@ class Series(StgitObject):
         new_series.set_description('clone of "%s"' % self.__name)
 
         # clone self's entire series as unapplied patches
         new_series.set_description('clone of "%s"' % self.__name)
 
         # clone self's entire series as unapplied patches
-        patches = self.get_applied() + self.get_unapplied()
-        patches.reverse()
+        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(),
         for p in patches:
             patch = self.get_patch(p)
             new_series.new_patch(p, message = patch.get_description(),
@@ -555,7 +565,7 @@ class Series(StgitObject):
                                  author_date = patch.get_authdate())
 
         # fast forward the cloned series to self's top
                                  author_date = patch.get_authdate())
 
         # fast forward the cloned series to self's top
-        new_series.forward_patches(self.get_applied())
+        new_series.forward_patches(applied)
 
     def delete(self, force = False):
         """Deletes an stgit series
 
     def delete(self, force = False):
         """Deletes an stgit series
diff --git a/t/t1002-branch-clone.sh b/t/t1002-branch-clone.sh
new file mode 100755 (executable)
index 0000000..12dd0e6
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/sh
+#
+# Copyright (c) 2006 Catalin Marinas
+#
+
+test_description='Branch renames.
+
+Exercises branch cloning options.
+'
+
+. ./test-lib.sh
+
+test_expect_success \
+    'Create a GIT commit' \
+    '
+    echo bar > bar.txt &&
+    git add bar.txt &&
+    git commit -a -m bar
+    '
+
+test_expect_failure \
+    'Try to create a patch in a GIT branch' \
+    '
+    stg new p0 -m "p0"
+    '
+
+test_expect_success \
+    'Clone the current GIT branch' \
+    '
+    stg branch --clone foo &&
+    stg new p1 -m "p1" &&
+    test $(stg applied -c) -eq 1
+    '
+
+test_expect_success \
+    'Clone the current StGIT branch' \
+    '
+    stg branch --clone bar &&
+    test $(stg applied -c) -eq 1 &&
+    stg new p2 -m "p2" &&
+    test $(stg applied -c) -eq 2
+    '
+
+test_done