Skip to content

Commit

Permalink
chore: display error message if push/pull manually
Browse files Browse the repository at this point in the history
  • Loading branch information
gyk authored and tiensonqin committed Dec 30, 2020
1 parent 4fdf595 commit 4a5de91
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/main/frontend/components/commit.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
[frontend.handler.repo :as repo-handler]
[frontend.state :as state]
[frontend.mixins :as mixins]
[frontend.handler.notification :as notification]
[promesa.core :as p]
[goog.dom :as gdom]
[goog.object :as gobj]))

(defn commit-and-push!
[]
(let [value (gobj/get (gdom/getElement "commit-message") "value")]
(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!))))

(rum/defcs add-commit-message <
Expand Down
30 changes: 23 additions & 7 deletions src/main/frontend/handler/repo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
(notification/show!
[:p.content
title
" "
[:span.mr-2
(util/format
"Please make sure that you've installed the logseq app for the repo %s on GitHub. "
Expand Down Expand Up @@ -375,7 +376,12 @@
(common-handler/check-changed-files-status repo-url)))
(p/catch (fn [error]
(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]
(println "Git pull error:")
(js/console.error error)
Expand All @@ -392,6 +398,7 @@
:error)
(route-handler/redirect! {:to :diff}))
(push repo-url {:merge-push-no-diff? true
:custom-commit? force-pull?
:commit-message "Merge push without diffed files"}))))))))
(p/catch
(fn [error]
Expand Down Expand Up @@ -426,8 +433,11 @@
(state/input-idle? repo-url)
(or (not= status :pushing)
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
(let [commit-message (if (string/blank? commit-message)
"Logseq auto save"
Expand All @@ -451,14 +461,18 @@
(do
(git-handler/set-git-status! repo-url :push-failed)
(git-handler/set-git-error! repo-url error)
(when (state/online?)
(if (state/online?)
(pull repo-url {:force-pull? true
:show-diff? true}))))))))))
:show-diff? true})
(when custom-commit?
(p/rejected error)))))))))))
(p/catch (fn [error]
(log/error :repo/push-error error)
(git-handler/set-git-status! repo-url :push-failed)
(git-handler/set-git-error! repo-url error)
(js/console.dir error)))))))

(when custom-commit?
(p/rejected error))))))))

(defn push-if-auto-enabled!
[repo]
Expand All @@ -469,7 +483,9 @@
(defn pull-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
[repo-url]
Expand Down

0 comments on commit 4a5de91

Please sign in to comment.