Browse Source

enhance: git auto-commit when detecting new changes from the disk

Tienson Qin 4 years ago
parent
commit
a378170c26

+ 3 - 0
src/electron/electron/handler.cljs

@@ -208,6 +208,9 @@
   (when (seq args)
     (git/raw! args)))
 
+(defmethod handle :gitCommitAll [_]
+  (git/add-all-and-commit!))
+
 (defmethod handle :default [args]
   (println "Error: no ipc handler for: " (bean/->js args)))
 

+ 1 - 1
src/main/frontend/extensions/code.cljs

@@ -48,7 +48,7 @@
             ["codemirror/mode/sparql/sparql"]
             ["codemirror/mode/turtle/turtle"]
             ["codemirror/mode/r/r"]
-            ))
+            ["codemirror/mode/julia/julia"]))
 
 ;; codemirror
 

+ 9 - 6
src/main/frontend/fs/watcher_handler.cljs

@@ -14,7 +14,8 @@
             [frontend.db.model :as model]
             [frontend.handler.editor :as editor]
             [frontend.handler.extract :as extract]
-            [promesa.core :as p]))
+            [promesa.core :as p]
+            [electron.ipc :as ipc]))
 
 (defn- set-missing-block-ids!
   [content]
@@ -51,11 +52,13 @@
           (and (= "change" type)
                (when-let [last-modified-at (db/get-file-last-modified-at repo path)]
                  (> mtime last-modified-at)))
-          (p/let [_ (file-handler/alter-file repo path content {:re-render-root? true
-                                                                :from-disk? true})]
-            (set-missing-block-ids! content)
-            (db/set-file-last-modified-at! repo path mtime)
-            nil)
+          (when-not (string/blank? content)
+            (p/let [result (ipc/ipc "gitCommitAll")
+                    _ (file-handler/alter-file repo path content {:re-render-root? true
+                                                                  :from-disk? true})]
+              (set-missing-block-ids! content)
+              (db/set-file-last-modified-at! repo path mtime)
+              nil))
 
           (contains? #{"add" "change" "unlink"} type)
           nil