|
@@ -13,8 +13,8 @@
|
|
|
(def log-error (partial logger/error "[Git]"))
|
|
|
|
|
|
(defn get-graph-git-dir
|
|
|
- []
|
|
|
- (when-let [graph-path (some-> (state/get-graph-path)
|
|
|
+ [graph-path]
|
|
|
+ (when-let [graph-path (some-> graph-path
|
|
|
(string/replace "/" "_")
|
|
|
(string/replace ":" "comma"))]
|
|
|
(let [dir (.join node-path (.homedir os) ".logseq" "git" graph-path ".git")]
|
|
@@ -22,38 +22,35 @@
|
|
|
dir)))
|
|
|
|
|
|
(defn run-git!
|
|
|
- [commands]
|
|
|
- (when-let [path (state/get-graph-path)]
|
|
|
- (when (fs/existsSync path)
|
|
|
- (p/let [result (.exec GitProcess commands path)]
|
|
|
- (if (zero? (gobj/get result "exitCode"))
|
|
|
- (let [result (gobj/get result "stdout")]
|
|
|
- (p/resolved result))
|
|
|
- (let [error (gobj/get result "stderr")]
|
|
|
- (when-not (string/blank? error)
|
|
|
- (log-error error))
|
|
|
- (p/rejected error)))))))
|
|
|
+ [graph-path commands]
|
|
|
+ (when (and graph-path (fs/existsSync graph-path))
|
|
|
+ (p/let [result (.exec GitProcess commands graph-path)]
|
|
|
+ (if (zero? (gobj/get result "exitCode"))
|
|
|
+ (let [result (gobj/get result "stdout")]
|
|
|
+ (p/resolved result))
|
|
|
+ (let [error (gobj/get result "stderr")]
|
|
|
+ (when-not (string/blank? error)
|
|
|
+ (log-error error))
|
|
|
+ (p/rejected error))))))
|
|
|
|
|
|
(defn run-git2!
|
|
|
- [commands]
|
|
|
- (when-let [path (state/get-graph-path)]
|
|
|
- (when (fs/existsSync path)
|
|
|
- (p/let [^js result (.exec GitProcess commands path)]
|
|
|
- result))))
|
|
|
+ [graph-path commands]
|
|
|
+ (when (and graph-path (fs/existsSync graph-path))
|
|
|
+ (p/let [^js result (.exec GitProcess commands graph-path)]
|
|
|
+ result)))
|
|
|
|
|
|
(defn git-dir-exists?
|
|
|
- []
|
|
|
+ [graph-path]
|
|
|
(try
|
|
|
- (let [p (.join node-path (state/get-graph-path) ".git")]
|
|
|
+ (let [p (.join node-path graph-path ".git")]
|
|
|
(.isDirectory (fs/statSync p)))
|
|
|
(catch :default _e
|
|
|
nil)))
|
|
|
|
|
|
(defn remove-dot-git-file!
|
|
|
- []
|
|
|
+ [graph-path]
|
|
|
(try
|
|
|
- (let [graph-path (state/get-graph-path)
|
|
|
- _ (when (string/blank? graph-path)
|
|
|
+ (let [_ (when (string/blank? graph-path)
|
|
|
(utils/send-to-renderer :setCurrentGraph {})
|
|
|
(throw (js/Error. "Empty graph path")))
|
|
|
p (.join node-path graph-path ".git")]
|
|
@@ -70,23 +67,23 @@
|
|
|
(log-error e))))
|
|
|
|
|
|
(defn init!
|
|
|
- []
|
|
|
- (let [_ (remove-dot-git-file!)
|
|
|
- separate-git-dir (get-graph-git-dir)
|
|
|
+ [graph-path]
|
|
|
+ (let [_ (remove-dot-git-file! graph-path)
|
|
|
+ separate-git-dir (get-graph-git-dir graph-path)
|
|
|
args (cond
|
|
|
- (git-dir-exists?)
|
|
|
+ (git-dir-exists? graph-path)
|
|
|
["init"]
|
|
|
separate-git-dir
|
|
|
["init" (str "--separate-git-dir=" separate-git-dir)]
|
|
|
:else
|
|
|
["init"])]
|
|
|
- (p/let [_ (run-git! (clj->js args))]
|
|
|
+ (p/let [_ (run-git! graph-path (clj->js args))]
|
|
|
(when utils/win32?
|
|
|
- (run-git! #js ["config" "core.safecrlf" "false"])))))
|
|
|
+ (run-git! graph-path #js ["config" "core.safecrlf" "false"])))))
|
|
|
|
|
|
(defn add-all!
|
|
|
- []
|
|
|
- (-> (run-git! #js ["add" "--ignore-errors" "./*"])
|
|
|
+ [graph-path]
|
|
|
+ (-> (run-git! graph-path #js ["add" "--ignore-errors" "./*"])
|
|
|
(p/catch (fn [error]
|
|
|
(let [error (string/lower-case (str error))]
|
|
|
(if (or (string/includes? error "permission denied")
|
|
@@ -97,34 +94,38 @@
|
|
|
;; git log -100 --oneline -p ~/Desktop/org/pages/contents.org
|
|
|
|
|
|
(defn commit!
|
|
|
- [message]
|
|
|
+ [graph-path message]
|
|
|
(p/do!
|
|
|
- (run-git! #js ["config" "core.quotepath" "false"])
|
|
|
- (run-git! #js ["commit" "-m" message])))
|
|
|
+ (run-git! graph-path #js ["config" "core.quotepath" "false"])
|
|
|
+ (run-git! graph-path #js ["commit" "-m" message])))
|
|
|
+
|
|
|
+(defn add-all-and-commit-single-graph!
|
|
|
+ [graph-path message]
|
|
|
+ (let [message (if (string/blank? message)
|
|
|
+ "Auto saved by Logseq"
|
|
|
+ message)]
|
|
|
+ (->
|
|
|
+ (p/let [_ (init! graph-path)
|
|
|
+ _ (add-all! graph-path)]
|
|
|
+ (commit! graph-path message))
|
|
|
+ (p/catch (fn [error]
|
|
|
+ (when (and
|
|
|
+ (string? error)
|
|
|
+ (not (string/blank? error)))
|
|
|
+ (if (string/starts-with? error "Author identity unknown")
|
|
|
+ (utils/send-to-renderer "setGitUsernameAndEmail" {:type "git"})
|
|
|
+ (utils/send-to-renderer "notification" {:type "error"
|
|
|
+ :payload (str error "\nIf you don't want to see those errors or don't need git, you can disable the \"Git auto commit\" feature on Settings > Version control.")}))))))))
|
|
|
|
|
|
(defn add-all-and-commit!
|
|
|
([]
|
|
|
(add-all-and-commit! nil))
|
|
|
([message]
|
|
|
- (let [message (if (string/blank? message)
|
|
|
- "Auto saved by Logseq"
|
|
|
- message)]
|
|
|
- (->
|
|
|
- (p/let [_ (init!)
|
|
|
- _ (add-all!)]
|
|
|
- (commit! message))
|
|
|
- (p/catch (fn [error]
|
|
|
- (when (and
|
|
|
- (string? error)
|
|
|
- (not (string/blank? error)))
|
|
|
- (if (string/starts-with? error "Author identity unknown")
|
|
|
- (utils/send-to-renderer "setGitUsernameAndEmail" {:type "git"})
|
|
|
- (utils/send-to-renderer "notification" {:type "error"
|
|
|
- :payload (str error "\nIf you don't want to see those errors or don't need git, you can disable the \"Git auto commit\" feature on Settings > Version control.")})))))))))
|
|
|
+ (doseq [path (state/get-all-graph-paths)] (add-all-and-commit-single-graph! path message))))
|
|
|
|
|
|
(defn short-status!
|
|
|
- []
|
|
|
- (run-git! #js ["status" "--porcelain"]))
|
|
|
+ [graph-path]
|
|
|
+ (run-git! graph-path #js ["status" "--porcelain"]))
|
|
|
|
|
|
(defonce quotes-regex #"\"[^\"]+\"")
|
|
|
(defn wrapped-by-quotes?
|
|
@@ -152,8 +153,8 @@
|
|
|
(remove string/blank?))))
|
|
|
|
|
|
(defn raw!
|
|
|
- [args]
|
|
|
- (init!)
|
|
|
+ [graph-path args]
|
|
|
+ (init! graph-path)
|
|
|
(let [args (if (string? args)
|
|
|
(split-args args)
|
|
|
args)
|
|
@@ -166,8 +167,8 @@
|
|
|
(p/rejected error)))]
|
|
|
(->
|
|
|
(p/let [_ (when (= (first args) "commit")
|
|
|
- (add-all!))
|
|
|
- result (run-git! (clj->js args))]
|
|
|
+ (add-all! graph-path))
|
|
|
+ result (run-git! graph-path (clj->js args))]
|
|
|
(p/resolved result))
|
|
|
(p/catch error-handler))))
|
|
|
|