|
|
@@ -303,90 +303,81 @@
|
|
|
(db/get-conn repo-url true)
|
|
|
(db/cloned? repo-url)
|
|
|
token)
|
|
|
- (let [remote-latest-commit (db/get-key-value repo-url :git/remote-latest-commit)
|
|
|
- local-latest-commit (db/get-key-value repo-url :git/latest-commit)]
|
|
|
- (p/let [descendent? (git/descendent? repo-url local-latest-commit remote-latest-commit)]
|
|
|
- (when (or (= local-latest-commit remote-latest-commit)
|
|
|
- (nil? local-latest-commit)
|
|
|
- (not descendent?)
|
|
|
- force-pull?)
|
|
|
- (p/let [files (js/window.workerThread.getChangedFiles (util/get-repo-dir repo-url))]
|
|
|
- (when (empty? files)
|
|
|
- (let [status (db/get-key-value repo-url :git/status)]
|
|
|
- (when (or
|
|
|
- force-pull?
|
|
|
- (and
|
|
|
- ;; (not= status :push-failed)
|
|
|
- (not= status :pushing)
|
|
|
- (not (state/get-edit-input-id))
|
|
|
- (not (state/in-draw-mode?))))
|
|
|
- (git-handler/set-git-status! repo-url :pulling)
|
|
|
- (let [latest-commit (db/get-key-value repo-url :git/latest-commit)]
|
|
|
- (->
|
|
|
- (p/let [result (git/fetch repo-url token)]
|
|
|
- (let [{:keys [fetchHead]} (bean/->clj result)]
|
|
|
- (when fetchHead
|
|
|
- (git-handler/set-remote-latest-commit! repo-url fetchHead))
|
|
|
- (-> (git/merge repo-url)
|
|
|
- (p/then (fn [result]
|
|
|
- (-> (git/checkout repo-url)
|
|
|
- (p/then (fn [result]
|
|
|
- (git-handler/set-git-status! repo-url nil)
|
|
|
- (git-handler/set-git-last-pulled-at! repo-url)
|
|
|
- (when (and latest-commit fetchHead
|
|
|
- (not= latest-commit fetchHead))
|
|
|
- (p/let [diffs (git/get-diffs repo-url latest-commit fetchHead)]
|
|
|
- (when (seq diffs)
|
|
|
- (load-db-and-journals! repo-url diffs false)
|
|
|
- (git-handler/set-latest-commit! repo-url fetchHead))))))
|
|
|
- (p/catch (fn [error]
|
|
|
- (git-handler/set-git-status! repo-url :checkout-failed)
|
|
|
- (git-handler/set-git-error! repo-url error))))
|
|
|
- (state/set-changed-files! repo-url nil)))
|
|
|
- (p/catch (fn [error]
|
|
|
- (println "Git pull error:")
|
|
|
- (js/console.error error)
|
|
|
- (git-handler/set-git-status! repo-url :merge-failed)
|
|
|
- (git-handler/set-git-error! repo-url error)
|
|
|
- (git-handler/get-latest-commit
|
|
|
- repo-url
|
|
|
- (fn [commit]
|
|
|
- (let [local-oid (gobj/get commit "oid")
|
|
|
- remote-oid (db/get-key-value repo-url
|
|
|
- :git/remote-latest-commit)]
|
|
|
- (p/let [result (git/get-local-diffs repo-url local-oid remote-oid)]
|
|
|
- (if (seq result)
|
|
|
- (do
|
|
|
- (notification/show!
|
|
|
- [:p.content
|
|
|
- "Failed to merge, please "
|
|
|
- [:span.text-gray-700.font-bold
|
|
|
- "resolve any diffs first."]]
|
|
|
- :error)
|
|
|
- (route-handler/redirect! {:to :diff}))
|
|
|
- (push repo-url {:commit-push? true
|
|
|
- :force? true
|
|
|
- :commit-message "Merge push without diffed files"})))))))))))
|
|
|
- (p/catch (fn [error]
|
|
|
- (println "Pull error:" (str error))
|
|
|
- (js/console.error error)
|
|
|
- ;; token might be expired, request new token
|
|
|
-
|
|
|
- (cond
|
|
|
- (and (or (string/includes? (str error) "401")
|
|
|
- (string/includes? (str error) "404"))
|
|
|
- (not fallback?))
|
|
|
- (request-app-tokens!
|
|
|
- (fn []
|
|
|
- (pull repo-url (state/get-github-token repo-url) {:fallback? true}))
|
|
|
- nil)
|
|
|
-
|
|
|
- (or (string/includes? (str error) "401")
|
|
|
- (string/includes? (str error) "404"))
|
|
|
- (show-install-error! repo-url (util/format "Failed to fetch %s." repo-url))
|
|
|
-
|
|
|
- :else
|
|
|
- nil))))))))))))))
|
|
|
+ (p/let [remote-latest-commit (common-handler/get-remote-ref repo-url)
|
|
|
+ local-latest-commit (common-handler/get-ref repo-url)
|
|
|
+ descendent? (git/descendent? repo-url local-latest-commit remote-latest-commit)]
|
|
|
+ (when (or (= local-latest-commit remote-latest-commit)
|
|
|
+ (nil? local-latest-commit)
|
|
|
+ (not descendent?)
|
|
|
+ force-pull?)
|
|
|
+ (p/let [files (js/window.workerThread.getChangedFiles (util/get-repo-dir repo-url))]
|
|
|
+ (when (empty? files)
|
|
|
+ (let [status (db/get-key-value repo-url :git/status)]
|
|
|
+ (when (or
|
|
|
+ force-pull?
|
|
|
+ (and
|
|
|
+ (not= status :pushing)
|
|
|
+ (not (state/get-edit-input-id))
|
|
|
+ (not (state/in-draw-mode?))))
|
|
|
+ (git-handler/set-git-status! repo-url :pulling)
|
|
|
+ (->
|
|
|
+ (p/let [result (git/fetch repo-url token)]
|
|
|
+ (let [{:keys [fetchHead]} (bean/->clj result)]
|
|
|
+ (-> (git/merge repo-url)
|
|
|
+ (p/then (fn [result]
|
|
|
+ (-> (git/checkout repo-url)
|
|
|
+ (p/then (fn [result]
|
|
|
+ (git-handler/set-git-status! repo-url nil)
|
|
|
+ (git-handler/set-git-last-pulled-at! repo-url)
|
|
|
+ (when (and local-latest-commit fetchHead
|
|
|
+ (not= local-latest-commit fetchHead))
|
|
|
+ (p/let [diffs (git/get-diffs repo-url local-latest-commit fetchHead)]
|
|
|
+ (when (seq diffs)
|
|
|
+ (load-db-and-journals! repo-url diffs false))))))
|
|
|
+ (p/catch (fn [error]
|
|
|
+ (git-handler/set-git-status! repo-url :checkout-failed)
|
|
|
+ (git-handler/set-git-error! repo-url error))))
|
|
|
+ (state/set-changed-files! repo-url nil)))
|
|
|
+ (p/catch (fn [error]
|
|
|
+ (println "Git pull error:")
|
|
|
+ (js/console.error error)
|
|
|
+ (git-handler/set-git-status! repo-url :merge-failed)
|
|
|
+ (git-handler/set-git-error! repo-url error)
|
|
|
+ (p/let [remote-latest-commit (common-handler/get-remote-ref repo-url)
|
|
|
+ local-latest-commit (common-handler/get-ref repo-url)
|
|
|
+ result (git/get-local-diffs repo-url local-latest-commit remote-latest-commit)]
|
|
|
+ (if (seq result)
|
|
|
+ (do
|
|
|
+ (notification/show!
|
|
|
+ [:p.content
|
|
|
+ "Failed to merge, please "
|
|
|
+ [:span.text-gray-700.font-bold
|
|
|
+ "resolve any diffs first."]]
|
|
|
+ :error)
|
|
|
+ (route-handler/redirect! {:to :diff}))
|
|
|
+ (push repo-url {:commit-push? true
|
|
|
+ :force? true
|
|
|
+ :commit-message "Merge push without diffed files"}))))))))
|
|
|
+ (p/catch (fn [error]
|
|
|
+ (println "Pull error:" (str error))
|
|
|
+ (js/console.error error)
|
|
|
+ ;; token might be expired, request new token
|
|
|
+
|
|
|
+ (cond
|
|
|
+ (and (or (string/includes? (str error) "401")
|
|
|
+ (string/includes? (str error) "404"))
|
|
|
+ (not fallback?))
|
|
|
+ (request-app-tokens!
|
|
|
+ (fn []
|
|
|
+ (pull repo-url (state/get-github-token repo-url) {:fallback? true}))
|
|
|
+ nil)
|
|
|
+
|
|
|
+ (or (string/includes? (str error) "401")
|
|
|
+ (string/includes? (str error) "404"))
|
|
|
+ (show-install-error! repo-url (util/format "Failed to fetch %s." repo-url))
|
|
|
+
|
|
|
+ :else
|
|
|
+ nil))))))))))))
|
|
|
|
|
|
(defn push
|
|
|
[repo-url {:keys [commit-message fallback? diff-push? commit-push? force?]
|
|
|
@@ -410,7 +401,6 @@
|
|
|
"Logseq auto save"
|
|
|
commit-message)]
|
|
|
(p/let [commit-oid (git/commit repo-url commit-message)]
|
|
|
- (git-handler/set-latest-commit-if-exists! repo-url)
|
|
|
(git-handler/set-git-status! repo-url :pushing)
|
|
|
(when-let [token (state/get-github-token repo-url)]
|
|
|
(util/p-handle
|
|
|
@@ -418,8 +408,7 @@
|
|
|
(fn [result]
|
|
|
(git-handler/set-git-status! repo-url nil)
|
|
|
(git-handler/set-git-error! repo-url nil)
|
|
|
- (state/set-changed-files! repo-url nil)
|
|
|
- (git-handler/set-remote-latest-commit! repo-url commit-oid))
|
|
|
+ (state/set-changed-files! repo-url nil))
|
|
|
(fn [error]
|
|
|
(println "Git push error: ")
|
|
|
(js/console.error error)
|
|
|
@@ -476,9 +465,7 @@
|
|
|
(state/set-git-clone-repo! "")
|
|
|
(state/set-current-repo! repo-url)
|
|
|
(db/start-db-conn! (:me @state/state) repo-url)
|
|
|
- (db/mark-repo-as-cloned repo-url)
|
|
|
- (git-handler/set-latest-commit-if-exists! repo-url)
|
|
|
- (git-handler/set-remote-latest-commit-if-exists! repo-url))
|
|
|
+ (db/mark-repo-as-cloned repo-url))
|
|
|
(fn [e]
|
|
|
(if (and (not fallback?)
|
|
|
(or (string/includes? (str e) "401")
|