Fix the clone command failure
authorCatalin Marinas <catalin.marinas@gmail.com>
Thu, 12 Jan 2006 21:04:30 +0000 (21:04 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Thu, 12 Jan 2006 21:04:30 +0000 (21:04 +0000)
The clone command fails because there is no GIT tree available, which is
wrong. The patch fixes the Series.__init__() function and also creates a
new Series object in clone.py once a GIT tree was initialised.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/clone.py
stgit/main.py
stgit/stack.py

index f4e3f6b..9ad76a6 100644 (file)
@@ -51,6 +51,6 @@ def func(parser, options, args):
     os.chdir(local_dir)
     git.checkout(tree_id = 'HEAD')
 
-    crt_series.init()
+    stack.Series().init()
 
     print 'done'
index b84d91d..2336a43 100644 (file)
@@ -150,16 +150,14 @@ def main():
                           option_list = command.options)
     options, args = parser.parse_args()
     try:
-        # 'clone' doesn't expect an already initialised GIT tree
-        if cmd == 'clone':
-            stgit.commands.common.crt_series = stack.Series('master')
-        elif hasattr(options, 'branch') and options.branch:
-            stgit.commands.common.crt_series = stack.Series(options.branch)
-        else:
-            stgit.commands.common.crt_series = stack.Series()
-        # the line below is a simple way to avoid an exception when
-        # stgit is run outside an initialised tree
-        setattr(command, 'crt_series', stgit.commands.common.crt_series)
+        # 'clone' doesn't expect an already initialised GIT tree. A Series
+        # object will be created after the GIT tree is cloned
+        if cmd != 'clone':
+            if hasattr(options, 'branch') and options.branch:
+                command.crt_series = stack.Series(options.branch)
+            else:
+                command.crt_series = stack.Series()
+            stgit.commands.common.crt_series = command.crt_series
 
         command.func(parser, options, args)
     except (IOError, CmdException, stack.StackException, git.GitException), \
index 8b7c296..c2adeb9 100644 (file)
@@ -257,21 +257,23 @@ class Series:
     def __init__(self, name = None):
         """Takes a series name as the parameter.
         """
-        if name:
-            self.__name = name
-        else:
-            self.__name = git.get_head_file()
-
-        if self.__name:
+        try:
+            if name:
+                self.__name = name
+            else:
+                self.__name = git.get_head_file()
             base_dir = git.get_base_dir()
-            self.__patch_dir = os.path.join(base_dir, 'patches',
-                                            self.__name)
-            self.__base_file = os.path.join(base_dir, 'refs', 'bases',
-                                            self.__name)
-            self.__applied_file = os.path.join(self.__patch_dir, 'applied')
-            self.__unapplied_file = os.path.join(self.__patch_dir, 'unapplied')
-            self.__current_file = os.path.join(self.__patch_dir, 'current')
-            self.__descr_file = os.path.join(self.__patch_dir, 'description')
+        except git.GitException, ex:
+            raise StackException, 'GIT tree not initialised: %s' % ex
+
+        self.__patch_dir = os.path.join(base_dir, 'patches',
+                                        self.__name)
+        self.__base_file = os.path.join(base_dir, 'refs', 'bases',
+                                        self.__name)
+        self.__applied_file = os.path.join(self.__patch_dir, 'applied')
+        self.__unapplied_file = os.path.join(self.__patch_dir, 'unapplied')
+        self.__current_file = os.path.join(self.__patch_dir, 'current')
+        self.__descr_file = os.path.join(self.__patch_dir, 'description')
 
     def get_branch(self):
         """Return the branch name for the Series object