Merge "Remove now-deprecated fetch-remotes command"
diff --git a/jeepyb/cmd/manage_projects.py b/jeepyb/cmd/manage_projects.py
index 23b121f..853dde2 100644
--- a/jeepyb/cmd/manage_projects.py
+++ b/jeepyb/cmd/manage_projects.py
@@ -132,7 +132,7 @@
         return False
     # Because the following fails if executed more than once you should only
     # run fetch_config once in each repo.
-    status = git_command(repo_path, "checkout -b config "
+    status = git_command(repo_path, "checkout -B config "
                          "remotes/gerrit-meta/config")
     if status != 0:
         log.error("Failed to checkout config for project: %s" % project)
@@ -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
@@ -416,7 +428,7 @@
                     run_command("git init %s" % repo_path)
                     git_command(
                         repo_path,
-                        "remote add origin %(remote_url)" % git_opts)
+                        "remote add origin %(remote_url)s" % git_opts)
                     with open(os.path.join(repo_path,
                                            ".gitreview"),
                               'w') as gitreview:
@@ -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
@@ -513,7 +523,7 @@
                     # Branches on gerrit. Also, push all of the tags
                     git_command(
                         repo_path,
-                        "push origin +refs/heads/*:refs/heads/*",
+                        "push origin refs/heads/*:refs/heads/*",
                         env=ssh_env)
                     git_command(repo_path, 'push --tags', env=ssh_env)
                 except Exception:
@@ -551,6 +561,7 @@
                     log.exception(
                         "Exception processing ACLS for %s." % project)
                 finally:
+                    git_command(repo_path, 'reset --hard')
                     git_command(repo_path, 'checkout master')
                     git_command(repo_path, 'branch -D config')
 
diff --git a/jeepyb/projects.py b/jeepyb/projects.py
index 4e74b78..c1de885 100644
--- a/jeepyb/projects.py
+++ b/jeepyb/projects.py
@@ -144,6 +144,7 @@
         'openstack/python-quantumclient': 'python-neutronclient',
         'openstack/oslo-incubator': 'oslo',
         'openstack/tripleo-incubator': 'tripleo',
+        'openstack/django_openstack_auth': 'django-openstack-auth',
         'openstack-infra/askbot-theme': 'openstack-ci',
         'openstack-infra/config': 'openstack-ci',
         'openstack-infra/devstack-gate': 'openstack-ci',