         [top-hash objs] (files-map-to-objs files-map)]
     [top-hash objs]))
 
-
+; Creates a new commit object (and all required tree objects)
+; from the current index
+(defn create-commit [message parent-hash]
+  (let [[tree-hash tree-structs] (index-to-tree-objects)
+        timestamp (str (current-unix-time) " +0000")
+        text (str "tree " tree-hash "\n"
+                  "parent " parent-hash "\n"
+                  "author " (get-author) " " timestamp "\n"
+                  "committer " (get-committer) " " timestamp "\n"
+                  "\n"
+                  message "\n")]
+    (doseq [e tree-structs] (write-tree (:contents e)))
+    (write-commit text)))


(defn to-str [x] (apply str (map char x)))

(defn ok-sh [command & args]
  (let [res (apply sh (cons command args))]
    (assert (= 0 (:exit res)))

        (with-open [wrtr (output-stream filepath)]
          (.write wrtr bdata))
        (unset-writable filepath)))
    filepath))

(defn write-tree [tree-struct]
  (-> tree-struct
      (tree-data)
      (byte-array)
      (write-object)))

(defn write-blob [text]
  (write-object (str "blob " (count text) "\0" text)))

(defn write-commit [text]
  (write-object (str "commit " (count text) "\0" text)))

(defn hash-file [filepath]
  (hash-str (slurp filepath)))
