Bläddra i källkod

fix: git init into the current graph folder

instead of a separate git directory because .gitdir might has
different paths on multiple devices, another reason is that the graph
might have different histories considering the .git directory is not
synced.
Tienson Qin 4 år sedan
förälder
incheckning
7e44d81f1d
1 ändrade filer med 18 tillägg och 20 borttagningar
  1. 18 20
      src/electron/electron/git.cljs

+ 18 - 20
src/electron/electron/git.cljs

@@ -48,32 +48,30 @@
     (catch js/Error e
       nil)))
 
+(defn delete-existing-separate-dot-git!
+  []
+  (when-let [graph-path (get-graph-path)]
+    (let [p (.join path graph-path ".git")]
+     (when (.isFile (fs/statSync p))
+       (let [content (fs/readFileSync p)]
+         (when (and content
+                    (string/starts-with? content "gitdir:")
+                    (string/includes? content ".logseq/"))
+           (fs/unlinkSync p)))))))
+
 (defn init!
   []
-  (let [separate-git-dir (get-graph-git-dir)
-        args (cond
-               (git-dir-exists?)
-               ["init"]
-               separate-git-dir
-               ["init" (str "--separate-git-dir=" separate-git-dir)]
-               :else
-               ["init"])]
-    (-> (p/let [_ (run-git! (clj->js args))]
-          (when utils/win32?
-            (run-git! ["config" "core.safecrlf" "false"])))
-        (p/catch (fn [error]
-                   (when (string/starts-with? error "fatal: not a git repository")
-                     (let [p (.join path (get-graph-path) ".git")]
-                       (when (.isFile (fs/statSync p))
-                         (let [content (fs/readFileSync p)]
-                           (when (and content (string/starts-with? content "gitdir:"))
-                             (fs/unlinkSync p)))))))))))
+  (delete-existing-separate-dot-git!)
+  (let [args ["init"]]
+    (p/let [_ (run-git! (clj->js args))]
+      (when utils/win32?
+        (run-git! ["config" "core.safecrlf" "false"])))))
 
 (defn add-all!
   []
-  (-> (run-git! #js ["add" "./*"])
+  (-> (run-git! #js ["add" "--ignore-errors" "./*"])
       (p/catch (fn [error]
-                 (if (string/includes? error "permission denied error: unable to index file")
+                 (if (string/includes? (string/lower-case error) "permission denied")
                    (js/console.error error)
                    (p/rejected error))))))