                  (fn [mapped-here]
                    (mapv #(hash-map :name %) mapped-here)))})
 
-(defn build-tree [root data]
-  (letfn [(build-node [name-segment data]
+(defn build-tree [data]
+  (letfn [(build-children [name-segments data]
+            (into []
+                  (comp (filter #(map? (second %)))
+                        (map (fn [[k v]]
+                               (build-node (conj name-segments k) v))))
+                  data))
+          (build-node [name-segments data]
             (cond
               (map? data)
-              (into {:name name-segment
-                     :children (->> data
-                                    (map (fn [[k v]]
-                                           (if (map? v)
-                                             (build-node k v))))
-                                    (keep identity)
-                                    (into []))}
+              (into {:name (str/join "/" name-segments)
+                     :children (build-children name-segments data)}
                     (remove #(map? (second %)) data))))
           (build-step [root [name-segment data]]
             (update root :children conj
-                    (build-node name-segment data)))]
-    (let [tree (reduce build-step root data)]
+                    (build-node [name-segment] data)))]
+    (let [root {:name [] :children ()}
+          tree (reduce build-step root data)]
       (-> tree
-          (process-down normalize-kind nil)
-          (process-down inject-name [])
-          (process-down inject-parent nil)
+          (process-down set-kind nil)
+          (process-down set-parent nil)
           (process-down create-mapped-here-links nil)))))
 
 (defn flatten-tree [node]

             (update node "kind" normalize)
             node)}))

(defn inject-name [node parent-segments]
  (let [segments (if (nil? (:name node))
                   parent-segments
                   (conj parent-segments (:name node)))]
    {:node (assoc node :name (str/join "/" segments))
     :ctx segments}))

(defn inject-parent [node ctx]
  (let [parent ctx]
    {:node (assoc node :parent (or (:parent node)
                                   (:name parent)))

            [gitiom.tree :as git-tree]
            [me.raynes.fs :as fs]))

;;;; Path utilities

(defn strip-extension [path]
  (last (first (re-seq #"(.*)\..*$" path))))

(defn relative-path [root path]
  (let [root-segments (fs/split root)
        path-segments (fs/split path)
        n (count root-segments)]
    (str/join "/"
              (condp = (take n path-segments)
                root-segments (drop n path-segments)
                path-segments))))

(defn path->segments [path]
  (fs/split (strip-extension path)))

(defn recursive-merge [a b]
  (if (and (map? a) (map? b))
