Explorar o código

chore: display error message if push/pull manually

Yukun Guo %!s(int64=4) %!d(string=hai) anos
pai
achega
4a5de9106e

+ 5 - 1
src/main/frontend/components/commit.cljs

@@ -4,6 +4,8 @@
             [frontend.handler.repo :as repo-handler]
             [frontend.handler.repo :as repo-handler]
             [frontend.state :as state]
             [frontend.state :as state]
             [frontend.mixins :as mixins]
             [frontend.mixins :as mixins]
+            [frontend.handler.notification :as notification]
+            [promesa.core :as p]
             [goog.dom :as gdom]
             [goog.dom :as gdom]
             [goog.object :as gobj]))
             [goog.object :as gobj]))
 
 
@@ -11,7 +13,9 @@
   []
   []
   (let [value (gobj/get (gdom/getElement "commit-message") "value")]
   (let [value (gobj/get (gdom/getElement "commit-message") "value")]
     (when (and value (>= (count value) 1))
     (when (and value (>= (count value) 1))
-      (repo-handler/git-commit-and-push! value)
+      (-> (repo-handler/git-commit-and-push! value)
+          (p/catch (fn [error]
+                     (notification/show! error :error false))))
       (state/close-modal!))))
       (state/close-modal!))))
 
 
 (rum/defcs add-commit-message <
 (rum/defcs add-commit-message <

+ 23 - 7
src/main/frontend/handler/repo.cljs

@@ -35,6 +35,7 @@
   (notification/show!
   (notification/show!
    [:p.content
    [:p.content
     title
     title
+    " "
     [:span.mr-2
     [:span.mr-2
      (util/format
      (util/format
       "Please make sure that you've installed the logseq app for the repo %s on GitHub. "
       "Please make sure that you've installed the logseq app for the repo %s on GitHub. "
@@ -375,7 +376,12 @@
                                                  (common-handler/check-changed-files-status repo-url)))
                                                  (common-handler/check-changed-files-status repo-url)))
                                        (p/catch (fn [error]
                                        (p/catch (fn [error]
                                                   (git-handler/set-git-status! repo-url :checkout-failed)
                                                   (git-handler/set-git-status! repo-url :checkout-failed)
-                                                  (git-handler/set-git-error! repo-url error))))))
+                                                  (git-handler/set-git-error! repo-url error)
+                                                  (when force-pull?
+                                                    (notification/show!
+                                                     (str "Failed to checkout: " error)
+                                                     :error
+                                                     false)))))))
                          (p/catch (fn [error]
                          (p/catch (fn [error]
                                     (println "Git pull error:")
                                     (println "Git pull error:")
                                     (js/console.error error)
                                     (js/console.error error)
@@ -392,6 +398,7 @@
                                            :error)
                                            :error)
                                           (route-handler/redirect! {:to :diff}))
                                           (route-handler/redirect! {:to :diff}))
                                         (push repo-url {:merge-push-no-diff? true
                                         (push repo-url {:merge-push-no-diff? true
+                                                        :custom-commit? force-pull?
                                                         :commit-message "Merge push without diffed files"}))))))))
                                                         :commit-message "Merge push without diffed files"}))))))))
                  (p/catch
                  (p/catch
                   (fn [error]
                   (fn [error]
@@ -426,8 +433,11 @@
          (state/input-idle? repo-url)
          (state/input-idle? repo-url)
          (or (not= status :pushing)
          (or (not= status :pushing)
              custom-commit?))
              custom-commit?))
-      (-> (p/let [files (git/add-all (state/get-current-repo))]
-            (when (or (seq files) merge-push-no-diff?)
+      (-> (p/let [files (git/add-all (state/get-current-repo))
+                  changed-files? (some? (seq files))
+                  _ (when (and custom-commit? (not changed-files?))
+                      (p/rejected "No need to commit as there are no unchanged files"))]
+            (when (or changed-files? merge-push-no-diff?)
               ;; auto commit if there are any un-committed changes
               ;; auto commit if there are any un-committed changes
               (let [commit-message (if (string/blank? commit-message)
               (let [commit-message (if (string/blank? commit-message)
                                      "Logseq auto save"
                                      "Logseq auto save"
@@ -451,14 +461,18 @@
                        (do
                        (do
                          (git-handler/set-git-status! repo-url :push-failed)
                          (git-handler/set-git-status! repo-url :push-failed)
                          (git-handler/set-git-error! repo-url error)
                          (git-handler/set-git-error! repo-url error)
-                         (when (state/online?)
+                         (if (state/online?)
                            (pull repo-url {:force-pull? true
                            (pull repo-url {:force-pull? true
-                                           :show-diff? true}))))))))))
+                                           :show-diff? true})
+                           (when custom-commit?
+                             (p/rejected error)))))))))))
           (p/catch (fn [error]
           (p/catch (fn [error]
                      (log/error :repo/push-error error)
                      (log/error :repo/push-error error)
                      (git-handler/set-git-status! repo-url :push-failed)
                      (git-handler/set-git-status! repo-url :push-failed)
                      (git-handler/set-git-error! repo-url error)
                      (git-handler/set-git-error! repo-url error)
-                     (js/console.dir error)))))))
+
+                     (when custom-commit?
+                       (p/rejected error))))))))
 
 
 (defn push-if-auto-enabled!
 (defn push-if-auto-enabled!
   [repo]
   [repo]
@@ -469,7 +483,9 @@
 (defn pull-current-repo
 (defn pull-current-repo
   []
   []
   (when-let [repo (state/get-current-repo)]
   (when-let [repo (state/get-current-repo)]
-    (pull repo {:force-pull? true})))
+    (-> (pull repo {:force-pull? true})
+        (p/catch (fn [error]
+                   (notification/show! error :error false))))))
 
 
 (defn- clone
 (defn- clone
   [repo-url]
   [repo-url]