 (set! *warn-on-reflection* true)
 
 (defn git
-  [^File d & subcmd]
+  [{:keys [^File gitdir]} & subcmd]
   ;; We won't handle bare repos or displaced worktrees
-  (let [gitdir (.getPath d)
-        worktree (.getParent d)
-        rtn (apply sh "git" (str "--git-dir=" gitdir) (str "--work-tree=" worktree) subcmd)]
+  (let [dir-args (if (nil? gitdir)
+                   []
+                   [(str "--git-dir=" (.getPath gitdir))
+                    (str "--work-tree=" (.getParent gitdir))])
+        all-args (concat dir-args subcmd)
+        rtn (apply sh "git" all-args)]
     (when-not (zero? (:exit rtn))
-      (throw (ex-info "git error" rtn)))
+      (throw (ex-info "git error" (assoc rtn :git all-args))))
     rtn))
 
 ;; === git sha-based versions ===


(defn find-project-files
  [^File d]
  (let [{:keys [out err exit]} (git d "ls-files" "project.clj" "**/project.clj")
        projects (when-not (empty? out)
                   (s/split-lines out))]
    (map #(str (.getParent d) "/" %) projects)))

  (let [[kstrs sargs] (split-with #(.startsWith ^String % ":") args)
        kargset (set (map #(keyword (subs % 1)) kstrs))
        long-sha (kargset :long-sha)
        gver (-> project :root (get-voom-version :long-sha? long-sha))
        qual (format-voom-ver gver timestamp-fmt)
        upfn #(str (s/replace % #"-SNAPSHOT" "") qual)
        nproj (update-in project [:version] upfn)
