Create local git mirror _after_ creating project

* jeepyb/cmd/manage_projects.py: Gerrit's create-project API calls
are refused with a "fatal: project xyzzy exists" error if its
repository is already present on disk. In fact, the same is true if
it's configured to perform local replication and the destination
replication directory for a new project already exists.
Conditionally create these directories only after creating the
project in Gerrit, avoiding further pain.

Change-Id: I3d7545a348187dfce3eba1ec93a976bb510668f3
diff --git a/jeepyb/cmd/manage_projects.py b/jeepyb/cmd/manage_projects.py
index da9ec15..66d0ca6 100644
--- a/jeepyb/cmd/manage_projects.py
+++ b/jeepyb/cmd/manage_projects.py
@@ -356,6 +356,18 @@
             project_git = "%s.git" % project
             remote_url = "ssh://localhost:%s/%s" % (GERRIT_PORT, project)
 
+            # Create the project in Gerrit first, since it will fail
+            # spectacularly if its project directory or local replica
+            # already exist on disk
+            project_created = False
+            if project not in project_list:
+                try:
+                    gerrit.createProject(project)
+                    project_created = True
+                except Exception:
+                    log.exception(
+                        "Exception creating %s in Gerrit." % project)
+
             # Create the repo for the local git mirror
             git_mirror_path = os.path.join(LOCAL_GIT_DIR, project_git)
             if not os.path.exists(git_mirror_path):
@@ -371,7 +383,7 @@
                             remote_url=remote_url)
 
             # If we don't have a local copy already, get one
-            if not os.path.exists(repo_path):
+            if not os.path.exists(repo_path) or project_created:
                 if not os.path.exists(os.path.dirname(repo_path)):
                     os.makedirs(os.path.dirname(repo_path))
                 # Three choices
@@ -469,10 +481,8 @@
                 create_github_project(defaults, options, project,
                                       description, homepage)
 
-            if project not in project_list:
+            if project_created:
                 try:
-                    gerrit.createProject(project)
-
                     git_command(repo_path,
                                 push_string % remote_url,
                                 env=ssh_env)
@@ -480,7 +490,7 @@
                                 "push --tags %s" % remote_url, env=ssh_env)
                 except Exception:
                     log.exception(
-                        "Exception creating %s in Gerrit." % project)
+                        "Error pushing %s to Gerrit." % project)
 
             # If we're configured to track upstream, make sure we have
             # upstream's refs, and then push them to the appropriate