localrepo: move the repo creation code, fail if the repo exists
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Sat, 02 Sep 2006 23:06:47 +0200
changeset 3035 4d0e0f149581
parent 3034 2b0bc36a48d8
child 3036 adf7f3421c55
localrepo: move the repo creation code, fail if the repo exists
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Sat Sep 02 21:08:54 2006 +0200
+++ b/mercurial/localrepo.py	Sat Sep 02 23:06:47 2006 +0200
@@ -31,8 +31,16 @@
             path = p
         self.path = os.path.join(path, ".hg")
 
-        if not create and not os.path.isdir(self.path):
-            raise repo.RepoError(_("repository %s not found") % path)
+        if not os.path.isdir(self.path):
+            if create:
+                if not os.path.exists(path):
+                    os.mkdir(path)
+                os.mkdir(self.path)
+                os.mkdir(self.join("data"))
+            else:
+                raise repo.RepoError(_("repository %s not found") % path)
+        elif create:
+            raise repo.RepoError(_("repository %s already exists") % path)
 
         self.root = os.path.abspath(path)
         self.origroot = path
@@ -75,12 +83,6 @@
         self.decodepats = None
         self.transhandle = None
 
-        if create:
-            if not os.path.exists(path):
-                os.mkdir(path)
-            os.mkdir(self.path)
-            os.mkdir(self.join("data"))
-
         self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root)
 
     def url(self):