mirror of https://github.com/logseq/logseq
Add sync button
parent
cd145d6020
commit
be190de930
|
@ -144,14 +144,25 @@
|
||||||
{:placeholder "Search"}]]]]
|
{:placeholder "Search"}]]]]
|
||||||
[:div.ml-4.flex.items-center.md:ml-6
|
[:div.ml-4.flex.items-center.md:ml-6
|
||||||
[:button.p-1.text-gray-400.rounded-full.hover:bg-gray-100.hover:text-gray-500.focus:outline-none.focus:shadow-outline.focus:text-gray-500
|
[:button.p-1.text-gray-400.rounded-full.hover:bg-gray-100.hover:text-gray-500.focus:outline-none.focus:shadow-outline.focus:text-gray-500
|
||||||
|
{:on-click handler/pull-current-repo}
|
||||||
[:svg.h-6.w-6
|
[:svg.h-6.w-6
|
||||||
{:viewBox "0 0 24 24", :fill "none", :stroke "currentColor"}
|
{:viewBox "0 0 24 24", :fill "none", :stroke "currentColor"}
|
||||||
[:path
|
[:path
|
||||||
{:d
|
{:d
|
||||||
"M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9",
|
"M6 18.7V21a1 1 0 0 1-2 0v-5a1 1 0 0 1 1-1h5a1 1 0 1 1 0 2H7.1A7 7 0 0 0 19 12a1 1 0 1 1 2 0 9 9 0 0 1-15 6.7zM18 5.3V3a1 1 0 0 1 2 0v5a1 1 0 0 1-1 1h-5a1 1 0 0 1 0-2h2.9A7 7 0 0 0 5 12a1 1 0 1 1-2 0 9 9 0 0 1 15-6.7z"
|
||||||
:stroke-width "2",
|
:stroke-width "2",
|
||||||
:stroke-linejoin "round",
|
:stroke-linejoin "round",
|
||||||
:stroke-linecap "round"}]]]
|
:stroke-linecap "round"}]]
|
||||||
|
|
||||||
|
;; [:svg.h-6.w-6
|
||||||
|
;; {:viewBox "0 0 24 24", :fill "none", :stroke "currentColor"}
|
||||||
|
;; [:path
|
||||||
|
;; {:d
|
||||||
|
;; "M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9",
|
||||||
|
;; :stroke-width "2",
|
||||||
|
;; :stroke-linejoin "round",
|
||||||
|
;; :stroke-linecap "round"}]]
|
||||||
|
]
|
||||||
(ui/dropdown-with-links
|
(ui/dropdown-with-links
|
||||||
[{:title "Your Profile"
|
[{:title "Your Profile"
|
||||||
:options {:href "/me"}}
|
:options {:href "/me"}}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[frontend.state :as state]))
|
[frontend.state :as state]))
|
||||||
|
|
||||||
|
(defonce default-branch "master")
|
||||||
;; only support Github now
|
;; only support Github now
|
||||||
(defn auth
|
(defn auth
|
||||||
[token]
|
[token]
|
||||||
|
@ -54,7 +55,7 @@
|
||||||
[repo-url token]
|
[repo-url token]
|
||||||
(js/git.fetch (with-auth token
|
(js/git.fetch (with-auth token
|
||||||
{:dir (get-repo-dir repo-url)
|
{:dir (get-repo-dir repo-url)
|
||||||
:ref "master"
|
:ref default-branch
|
||||||
:singleBranch true
|
:singleBranch true
|
||||||
:depth 1
|
:depth 1
|
||||||
:tags false})))
|
:tags false})))
|
||||||
|
@ -63,14 +64,21 @@
|
||||||
[repo-url]
|
[repo-url]
|
||||||
(js/git.merge (clj->js
|
(js/git.merge (clj->js
|
||||||
{:dir (get-repo-dir repo-url)
|
{:dir (get-repo-dir repo-url)
|
||||||
:ours "master"
|
:ours default-branch
|
||||||
:theirs "remotes/origin/master"})))
|
:theirs (str "remotes/origin/" default-branch)
|
||||||
|
:fastForwardOnly true})))
|
||||||
|
|
||||||
|
(defn checkout
|
||||||
|
[repo-url]
|
||||||
|
(js/git.checkout (clj->js
|
||||||
|
{:dir (get-repo-dir repo-url)
|
||||||
|
:ref default-branch})))
|
||||||
|
|
||||||
(defn log
|
(defn log
|
||||||
[repo-url token depth]
|
[repo-url token depth]
|
||||||
(js/git.log (with-auth token
|
(js/git.log (with-auth token
|
||||||
{:dir (get-repo-dir repo-url)
|
{:dir (get-repo-dir repo-url)
|
||||||
:ref "master"
|
:ref default-branch
|
||||||
:depth depth
|
:depth depth
|
||||||
:singleBranch true})))
|
:singleBranch true})))
|
||||||
|
|
||||||
|
@ -78,7 +86,7 @@
|
||||||
[repo-url token]
|
[repo-url token]
|
||||||
(js/git.pull (with-auth token
|
(js/git.pull (with-auth token
|
||||||
{:dir (get-repo-dir repo-url)
|
{:dir (get-repo-dir repo-url)
|
||||||
:ref "master"
|
:ref default-branch
|
||||||
:singleBranch true
|
:singleBranch true
|
||||||
:fast true})))
|
:fast true})))
|
||||||
(defn add
|
(defn add
|
||||||
|
@ -91,18 +99,17 @@
|
||||||
[repo-url message]
|
[repo-url message]
|
||||||
(let [{:keys [name email]} (:me @state/state)]
|
(let [{:keys [name email]} (:me @state/state)]
|
||||||
(js/git.commit (clj->js
|
(js/git.commit (clj->js
|
||||||
{:dir (get-repo-dir repo-url)
|
{:dir (get-repo-dir repo-url)
|
||||||
:message message
|
:message message
|
||||||
:author {:name name
|
:author {:name name
|
||||||
:email email}}))))
|
:email email}}))))
|
||||||
|
|
||||||
(defn push
|
(defn push
|
||||||
[repo-url token]
|
[repo-url token]
|
||||||
(js/git.push (with-auth token
|
(js/git.push (with-auth token
|
||||||
{:dir (get-repo-dir repo-url)
|
{:dir (get-repo-dir repo-url)
|
||||||
:remote "origin"
|
:remote "origin"
|
||||||
:ref "master"
|
:ref default-branch})))
|
||||||
})))
|
|
||||||
|
|
||||||
(defn add-commit-push
|
(defn add-commit-push
|
||||||
[repo-url file message token push-ok-handler push-error-handler]
|
[repo-url file message token push-ok-handler push-error-handler]
|
||||||
|
|
|
@ -218,8 +218,12 @@
|
||||||
(reset! remote-changed? true))
|
(reset! remote-changed? true))
|
||||||
_ (set-latest-commit! fetchHead)]
|
_ (set-latest-commit! fetchHead)]
|
||||||
(-> (git/merge repo-url)
|
(-> (git/merge repo-url)
|
||||||
(p/then (fn []
|
(p/then (fn [result]
|
||||||
(load-db-and-journals! repo-url @remote-changed? false)))
|
(-> (git/checkout repo-url)
|
||||||
|
(p/then (fn [result]
|
||||||
|
(load-db-and-journals! repo-url @remote-changed? false)))
|
||||||
|
(p/catch (fn [error]
|
||||||
|
(prn "checkout error: " error))))))
|
||||||
(p/catch (fn [_error]
|
(p/catch (fn [_error]
|
||||||
(show-notification!
|
(show-notification!
|
||||||
[:p.content
|
[:p.content
|
||||||
|
@ -233,6 +237,12 @@
|
||||||
" to pull the latest changes."]
|
" to pull the latest changes."]
|
||||||
:error))))))))
|
:error))))))))
|
||||||
|
|
||||||
|
(defn pull-current-repo
|
||||||
|
[]
|
||||||
|
(when-let [repo (db/get-current-repo)]
|
||||||
|
(when-let [token (get-github-token)]
|
||||||
|
(pull repo token))))
|
||||||
|
|
||||||
(defn periodically-pull
|
(defn periodically-pull
|
||||||
[repo-url pull-now?]
|
[repo-url pull-now?]
|
||||||
(when-let [token (get-github-token)]
|
(when-let [token (get-github-token)]
|
||||||
|
|
Loading…
Reference in New Issue