   "Clone a git repo at url, writing the directory to path"
   [url & {:keys [path ssh-key]}]
   (let [path (or path (default-repo-path url))]
+
     (infof "git clone %s %s" url path)
+    (fs/mkdirs path)
     (git-fn* (sh/q
               (git clone ~url ~path))
              :ssh-key
-             ssh-key)))
+             ssh-key
+             :repo path)))
 
 (defn checkout
   "git checkout cmd"

(defn git-fn*
  "Takes a seq of stevedore code. Executes it locally, with GIT_SSH and GIT_SSH_KEY set up."
  [steve & {:keys [ssh-key repo]}]
  (with-temp-ssh-key-file [f ssh-key]
    (let [result (sh/sh steve
                        :environment (when ssh-key
                                       {"GIT_SSH" git-ssh-path
                                        "GIT_SSH_KEY" f})
                        :pwd repo)]
      (throw-if-not (zero? (-> result :exit)) "git command %s returned %s: %s" (first steve) (-> result :exit) (-> result :err))
      result)))



(defn default-repo-path [url]
  {:pre [url]}
  (fs/join repo-root (project-name url)))

(defmacro with-temp-ssh-key-file
  "Writes the ssh-key to a temp file, executes body. f is the name of the variable that will hold the File for the ssh-key. Deletes the temp key file when done"
