Browse Source

refactor(git): remove our own changed-files cache

Tienson Qin 5 years ago
parent
commit
7a5324a08e

+ 5 - 5
src/main/frontend/components/draw.cljs

@@ -28,7 +28,7 @@
             [frontend.config :as config]
             [frontend.state :as state]
             [frontend.search :as search]
-            [frontend.components.widgets :as widgets]
+            [frontend.components.repo :as repo]
             [promesa.core :as p]
             [reitit.frontend.easy :as rfe]))
 
@@ -437,10 +437,10 @@
      (when current-repo
        [:div.absolute.top-4.right-4.hidden.md:block
         [:div.flex.flex-row.items-center
-         (widgets/sync-status current-repo)
-         (widgets/repos true
-                        (fn [repo]
-                          (reset! *current-file (get-last-file repo))))]])]))
+         (repo/sync-status current-repo)
+         (repo/repos-dropdown true
+                     (fn [repo]
+                       (reset! *current-file (get-last-file repo))))]])]))
 
 (rum/defcs draw-2 < rum/reactive
   {:init (fn [state]

+ 112 - 3
src/main/frontend/components/repo.cljs

@@ -5,10 +5,16 @@
             [frontend.state :as state]
             [frontend.db :as db]
             [frontend.handler.repo :as repo-handler]
+            [frontend.handler.common :as common-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.export :as export-handler]
             [frontend.util :as util]
-            [reitit.frontend.easy :as rfe]))
+            [frontend.config :as config]
+            [reitit.frontend.easy :as rfe]
+            [frontend.version :as version]
+            [frontend.components.commit :as commit]
+            [frontend.context.i18n :as i18n]
+            [clojure.string :as string]))
 
 (rum/defc add-repo
   []
@@ -25,8 +31,8 @@
        [:div.pl-1.content
         [:div.flex.my-4 {:key "add-button"}
          (ui/button
-          "Add another repo"
-          :href (rfe/href :repo-add))]
+           "Add another repo"
+           :href (rfe/href :repo-add))]
 
         (for [{:keys [id url] :as repo} repos]
           [:div.flex.justify-between.mb-1 {:key id}
@@ -52,3 +58,106 @@
 
        [:a#download-as-json.hidden]]
       (widgets/add-repo))))
+
+(rum/defc sync-status < rum/reactive
+  {:did-mount (fn [state]
+                (js/setTimeout common-handler/check-changed-files-status 1000)
+                state)}
+  []
+  (let [repo (state/get-current-repo)]
+    (when-not (= repo config/local-repo)
+      (let [changed-files (state/sub [:repo/changed-files repo])
+            should-push? (seq changed-files)
+            git-status (state/sub [:git/status repo])
+            pushing? (= :pushing git-status)
+            pulling? (= :pulling git-status)
+            last-pulled-at (db/sub-key-value repo :git/last-pulled-at)]
+        [:div.flex-row.flex.items-center
+         (when pushing?
+           [:span.lds-dual-ring.mt-1])
+         (ui/dropdown
+          (fn [{:keys [toggle-fn]}]
+            [:div.cursor.w-2.h-2.sync-status.mr-2
+             {:class (if (or should-push? pushing?) "bg-orange-400" "bg-green-600")
+              :style {:border-radius "50%"
+                      :margin-top 2}
+              :on-mouse-over
+              (fn [e]
+                (toggle-fn)
+                (js/setTimeout common-handler/check-changed-files-status 0))}])
+          (fn [{:keys [toggle-fn]}]
+            (rum/with-context [[t] i18n/*tongue-context*]
+      [:div.p-2.rounded-md.shadow-xs.bg-base-3.flex.flex-col.sync-content
+       {:on-mouse-leave toggle-fn}
+       [:div
+        [:div
+         (if (and should-push? (seq changed-files))
+           [:div.changes
+            [:ul
+             (for [file changed-files]
+               [:li {:key (str "sync-" file)}
+                [:div.flex.flex-row.justify-between.align-items
+                 [:a {:href (rfe/href :file {:path file})}
+                  file]
+                 [:a.ml-4.text-sm.mt-1
+                  {:on-click (fn [e]
+                               (export-handler/download-file! file))}
+                  [:span (t :download)]]]])]]
+           [:p (t :git/local-changes-synced)])]
+        ;; [:a.text-sm.font-bold {:href "/diff"} "Check diff"]
+        [:div.flex.flex-row.justify-between.align-items.mt-2
+         (ui/button (t :git/push)
+           :on-click (fn [] (state/set-modal! commit/add-commit-message)))
+         (if pushing?
+           [:span.lds-dual-ring.mt-1])]]
+       [:hr]
+       [:div
+        (when-not (string/blank? last-pulled-at)
+          [:p {:style {:font-size 12}} (t :git/last-pull)
+           (str ": " last-pulled-at)])
+        [:div.flex.flex-row.justify-between.align-items
+         (ui/button (t :git/pull)
+           :on-click (fn [] (repo-handler/pull-current-repo)))
+         (if pulling?
+           [:span.lds-dual-ring.mt-1])]
+        [:p.pt-2.text-sm.opacity-50
+         (t :git/version) (str " " version/version)]]])))]))))
+
+(rum/defc repos-dropdown < rum/reactive
+  [head? on-click]
+  (let [current-repo (state/sub :git/current-repo)
+        logged? (state/logged?)
+        local-repo? (= current-repo config/local-repo)
+        get-repo-name-f (fn [repo]
+                          (if head?
+                            (db/get-repo-path repo)
+                            (util/take-at-most (db/get-repo-name repo) 20)))]
+    (when logged?
+      (if current-repo
+        (let [repos (state/sub [:me :repos])]
+          (if (> (count repos) 1)
+            (ui/dropdown-with-links
+             (fn [{:keys [toggle-fn]}]
+               [:a#repo-switch {:on-click toggle-fn}
+                [:span (get-repo-name-f current-repo)]
+                [:span.dropdown-caret.ml-1 {:style {:border-top-color "#6b7280"}}]])
+             (mapv
+              (fn [{:keys [id url]}]
+                {:title (get-repo-name-f url)
+                 :options {:on-click (fn []
+                                       (state/set-current-repo! url)
+                                       (when-not (= :draw (state/get-current-route))
+                                         (route-handler/redirect-to-home!))
+                                       (when on-click
+                                         (on-click url)))}})
+              (remove (fn [repo]
+                        (= current-repo (:url repo)))
+                      repos))
+             {:modal-class (util/hiccup->class
+                            "origin-top-right.absolute.left-0.mt-2.w-48.rounded-md.shadow-lg ")})
+            (if local-repo?
+              [:span (get-repo-name-f current-repo)]
+              [:a
+               {:href current-repo
+                :target "_blank"}
+               (get-repo-name-f current-repo)])))))))

+ 7 - 10
src/main/frontend/components/sidebar.cljs

@@ -11,6 +11,7 @@
             [frontend.components.settings :as settings]
             [frontend.components.svg :as svg]
             [frontend.components.project :as project]
+            [frontend.components.repo :as repo]
             [frontend.components.commit :as commit]
             [frontend.components.right-sidebar :as right-sidebar]
             [frontend.storage :as storage]
@@ -236,13 +237,9 @@
                        (not (gobj/get e "altKey"))
                        (not (gobj/get e "metaKey")))
               (when-let [repo-url (state/get-current-repo)]
-                (if (and
-                     (not (state/get-edit-input-id))
-                     (seq (state/get-changed-files repo-url)))
-                  (do
-                    (util/stop e)
-                    (state/set-modal! commit/add-commit-message))
-                  (notification/show! "No changed files yet!" :warning)))))}
+                (when-not (state/get-edit-input-id)
+                  (util/stop e)
+                  (state/set-modal! commit/add-commit-message)))))}
       (fn [e key-code]
         nil))))
   {:did-mount (fn [state]
@@ -295,7 +292,7 @@
                  :stroke-linejoin "round"
                  :stroke-linecap "round"}]]]])
           [:div.flex-shrink-0.flex.items-center.px-4.h-16 {:style {:background-color "#002b36"}}
-           (widgets/repos false)]
+           (repo/repos-dropdown false)]
           [:div.flex-1.h-0.overflow-y-auto
            (sidebar-nav route-match close-fn)]]]
         [:div.flex.flex-col.w-0.flex-1.overflow-hidden
@@ -326,10 +323,10 @@
                             (storage/remove :git/current-repo))}
                (t :login-github)])
 
-            (widgets/sync-status)
+            (repo/sync-status)
 
             [:div.repos.hidden.md:block
-             (widgets/repos true)]
+             (repo/repos-dropdown true)]
 
             (when-let [project (and current-repo (state/get-current-project))]
               [:a.opacity-70.hover:opacity-100.ml-4

+ 0 - 98
src/main/frontend/components/widgets.cljs

@@ -39,104 +39,6 @@
        :on-click
        #(user-handler/set-preferred-format! :org))]]))
 
-(rum/defc sync-status < rum/reactive
-  []
-  (let [repo (state/get-current-repo)]
-    (when-not (= repo config/local-repo)
-      (let [git-status (state/sub [:git/status repo])
-            pulling? (= :pulling git-status)
-            pushing? (= :pushing git-status)
-            last-pulled-at (db/sub-key-value repo :git/last-pulled-at)
-            changed-files (state/sub [:repo/changed-files repo])
-            should-push? (seq changed-files)]
-        (rum/with-context [[t] i18n/*tongue-context*]
-          [:div.flex-row.flex.items-center
-           (when pushing?
-             [:span.lds-dual-ring.mt-1])
-           (ui/dropdown
-            (fn [{:keys [toggle-fn]}]
-              [:div.cursor.w-2.h-2.sync-status.mr-2
-               {:class (if (or should-push? pushing?) "bg-orange-400" "bg-green-600")
-                :style {:border-radius "50%"
-                        :margin-top 2}
-                :on-mouse-over
-                (fn [e]
-                  (toggle-fn)
-                  (js/setTimeout repo-handler/check-changed-files-status 0))}])
-            (fn [{:keys [toggle-fn]}]
-              [:div.p-2.rounded-md.shadow-xs.bg-base-3.flex.flex-col.sync-content
-               {:on-mouse-leave toggle-fn}
-               (if (and should-push? (seq changed-files))
-                 [:div
-                  [:div.changes
-                   [:ul
-                    (for [file changed-files]
-                      [:li {:key (str "sync-" file)}
-                       [:div.flex.flex-row.justify-between.align-items
-                        [:a {:href (rfe/href :file {:path file})}
-                         file]
-                        [:a.ml-4.text-sm.mt-1
-                         {:on-click (fn [e]
-                                      (export-handler/download-file! file))}
-                         [:span (t :download)]]]])]]
-                  ;; [:a.text-sm.font-bold {:href "/diff"} "Check diff"]
-                  [:div.flex.flex-row.justify-between.align-items.mt-2
-                   (ui/button (t :git/push)
-                              :on-click (fn [] (state/set-modal! commit/add-commit-message)))
-                   (if pushing?
-                     [:span.lds-dual-ring.mt-1])]]
-                 [:p (t :git/local-changes-synced)])
-               [:hr]
-               [:div
-                [:p {:style {:font-size 12}} (t :git/last-pull)
-                 last-pulled-at]
-                [:div.flex.flex-row.justify-between.align-items
-                 (ui/button (t :git/pull)
-                            :on-click (fn [] (repo-handler/pull-current-repo)))
-                 (if pulling?
-                   [:span.lds-dual-ring.mt-1])]
-                [:p.pt-2.text-sm.opacity-50
-                 (t :git/version) (str " " version/version)]]]))])))))
-
-(rum/defc repos < rum/reactive
-  [head? on-click]
-  (let [current-repo (state/sub :git/current-repo)
-        logged? (state/logged?)
-        local-repo? (= current-repo config/local-repo)
-        get-repo-name-f (fn [repo]
-                          (if head?
-                            (db/get-repo-path repo)
-                            (util/take-at-most (db/get-repo-name repo) 20)))]
-    (when logged?
-      (if current-repo
-        (let [repos (state/sub [:me :repos])]
-          (if (> (count repos) 1)
-            (ui/dropdown-with-links
-             (fn [{:keys [toggle-fn]}]
-               [:a#repo-switch {:on-click toggle-fn}
-                [:span (get-repo-name-f current-repo)]
-                [:span.dropdown-caret.ml-1 {:style {:border-top-color "#6b7280"}}]])
-             (mapv
-              (fn [{:keys [id url]}]
-                {:title (get-repo-name-f url)
-                 :options {:on-click (fn []
-                                       (state/set-current-repo! url)
-                                       (when-not (= :draw (state/get-current-route))
-                                         (route-handler/redirect-to-home!))
-                                       (when on-click
-                                         (on-click url)))}})
-              (remove (fn [repo]
-                        (= current-repo (:url repo)))
-                      repos))
-             {:modal-class (util/hiccup->class
-                            "origin-top-right.absolute.left-0.mt-2.w-48.rounded-md.shadow-lg ")})
-            (if local-repo?
-              [:span (get-repo-name-f current-repo)]
-              [:a
-               {:href current-repo
-                :target "_blank"}
-               (get-repo-name-f current-repo)])))))))
-
 (rum/defcs add-repo <
   (rum/local "" ::repo)
   (rum/local "" ::branch)

+ 19 - 0
src/main/frontend/handler/common.cljs

@@ -0,0 +1,19 @@
+(ns frontend.handler.common
+  (:require [goog.object :as gobj]
+            [frontend.state :as state]
+            [cljs-bean.core :as bean]
+            [promesa.core :as p]
+            [frontend.util :as util]))
+
+(defn check-changed-files-status
+  []
+  (when-let [repo (state/get-current-repo)]
+    (when (and
+           (gobj/get js/window "workerThread")
+           (gobj/get js/window.workerThread "getChangedFiles"))
+      (->
+       (p/let [files (js/window.workerThread.getChangedFiles (util/get-repo-dir repo))]
+         (let [files (bean/->clj files)]
+           (state/set-changed-files! repo files)))
+       (p/catch (fn [error]
+                  (js/console.dir error)))))))

+ 4 - 5
src/main/frontend/handler/dnd.cljs

@@ -511,8 +511,7 @@
           :else
           (move-block-in-different-repos target-block-repo to-block-repo target-block to-block top-block bottom-block nested? top? target-child? direction target-content target-file original-top-block-start-pos block-changes))
 
-        ;; (when (state/git-auto-push?)
-        ;;   (doseq [repo (->> #{target-block-repo to-block-repo}
-        ;;                     (remove nil?))]
-        ;;     (repo-handler/push repo nil)))
-        ))))
+        (when (state/git-auto-push?)
+          (doseq [repo (->> #{target-block-repo to-block-repo}
+                            (remove nil?))]
+            (repo-handler/push repo nil)))))))

+ 2 - 3
src/main/frontend/handler/editor.cljs

@@ -545,9 +545,8 @@
              (when (or (seq retract-refs) pre-block?)
                (ui-handler/re-render-root!))
 
-             ;; (when (state/git-auto-push?)
-             ;;     (repo-handler/push repo nil))
-             )
+             (when (state/git-auto-push?)
+                 (repo-handler/push repo nil)))
 
            :else
            nil))))))

+ 3 - 2
src/main/frontend/handler/file.cljs

@@ -6,6 +6,7 @@
             [frontend.state :as state]
             [frontend.db :as db]
             [frontend.git :as git]
+            [frontend.handler.common :as common-handler]
             [frontend.handler.git :as git-handler]
             [frontend.handler.ui :as ui-handler]
             [datascript.core :as d]
@@ -107,7 +108,7 @@
                    (js/console.dir error))))))
 
 (defn alter-file
-  [repo path content {:keys [reset? re-render-root? add-history?]
+  [repo path content {:keys [reset? re-render-root? add-history? update-status?]
                       :or {reset? true
                            re-render-root? false
                            add-history? true}}]
@@ -161,8 +162,8 @@
                                     "/"
                                     file)
                                nil)]
-       (state/git-add! repo (str "- " file))
        (when-let [file (db/entity repo [:file/path file])]
+         (common-handler/check-changed-files-status)
          (let [file-id (:db/id file)
                page-id (db/get-file-page-id (:file/path file))
                tx-data (map

+ 7 - 4
src/main/frontend/handler/git.cljs

@@ -15,6 +15,7 @@
             [goog.object :as gobj]
             [frontend.handler.notification :as notification]
             [frontend.handler.route :as route-handler]
+            [frontend.handler.common :as common-handler]
             [clojure.string :as string]
             [cljs-time.local :as tl]
             [cljs-time.core :as t]
@@ -43,9 +44,12 @@
   (db/set-key-value repo-url :git/error (if value (str value))))
 
 (defn git-add
-  [repo-url file]
-  (p/let [result (git/add repo-url file)]
-    (state/git-add! repo-url file)))
+  ([repo-url file]
+   (git-add repo-url file true))
+  ([repo-url file update-status?]
+   (p/let [_result (git/add repo-url file)]
+     (when update-status?
+       (common-handler/check-changed-files-status)))))
 
 (defn get-latest-commit
   ([repo-url handler]
@@ -86,7 +90,6 @@
                                     (state/get-github-token repo)
                                     true)]
         (reset! pushing? false)
-        (state/clear-changed-files! repo)
         (notification/clear! nil)
         (route-handler/redirect! {:to :home})))))
 

+ 6 - 5
src/main/frontend/handler/page.cljs

@@ -6,6 +6,7 @@
             [frontend.util :as util :refer-macros [profile]]
             [frontend.tools.html-export :as html-export]
             [frontend.config :as config]
+            [frontend.handler.common :as common-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.file :as file-handler]
             [frontend.handler.git :as git-handler]
@@ -250,11 +251,11 @@
               ;; remove file
               (->
                (p/let [_ (git/remove-file repo file-path)
-                       _result (fs/unlink (str (util/get-repo-dir repo)
-                                               "/"
-                                               file-path)
-                                          nil)]
-                 (state/git-add! repo (str "- " file-path)))
+                       _ (fs/unlink (str (util/get-repo-dir repo)
+                                         "/"
+                                         file-path)
+                                    nil)]
+                 (common-handler/check-changed-files-status))
                (p/catch (fn [err]
                           (prn "error: " err))))))
 

+ 68 - 83
src/main/frontend/handler/repo.cljs

@@ -22,6 +22,7 @@
             [frontend.handler.notification :as notification]
             [frontend.handler.route :as route-handler]
             [frontend.handler.user :as user-handler]
+            [frontend.handler.common :as common-handler]
             [frontend.ui :as ui]
             [cljs-time.local :as tl]
             [cljs-time.core :as t]
@@ -317,82 +318,69 @@
          (db/get-conn repo-url true)
          (db/cloned? repo-url)
          token)
-    (let [status (db/get-key-value repo-url :git/status)]
-      (when (or
-             force-pull?
-             (and
-              ;; (not= status :push-failed)
-              (not= status :pushing)
-              (empty? (state/get-changed-files repo-url))
-              (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)
-                                                 (when (seq (state/get-changed-files repo-url))
-                                                   ;; FIXME: no need to create a new commit
-                                                   (push repo-url {:diff-push? true})))))))
-                                 (p/catch (fn [error]
-                                            (git-handler/set-git-status! repo-url :checkout-failed)
-                                            (git-handler/set-git-error! repo-url error))))))
-                   (p/catch (fn [error]
-                              (git-handler/set-git-status! repo-url :merge-failed)
-                              (git-handler/set-git-error! repo-url error)
-                              (notification/show!
-                               [:p.content
-                                "Failed to merge, please "
-                                [:span.text-gray-700.font-bold
-                                 "resolve any diffs first."]]
-                               :error)
-                              (route-handler/redirect! {:to :diff}))))))
-           (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 check-changed-files-status
-  [f]
-  (when (gobj/get js/window.workerThread "getChangedFiles")
-    (->
-     (p/let [files (js/window.workerThread.getChangedFiles (util/get-repo-dir (state/get-current-repo)))]
-       (let [files (bean/->clj files)]
-         (when (empty? files)
-           ;; FIXME: getChangedFiles not return right result
-           (state/reset-changed-files! files))))
-     (p/catch (fn [error]
-                (js/console.dir error))))))
+    (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]
+                                  (git-handler/set-git-status! repo-url :merge-failed)
+                                  (git-handler/set-git-error! repo-url error)
+                                  (notification/show!
+                                   [:p.content
+                                    "Failed to merge, please "
+                                    [:span.text-gray-700.font-bold
+                                     "resolve any diffs first."]]
+                                   :error)
+                                  (route-handler/redirect! {:to :diff}))))))
+               (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? force?]
@@ -407,9 +395,7 @@
       (-> (p/let [files (js/window.workerThread.getChangedFiles (util/get-repo-dir (state/get-current-repo)))]
             (when (or
                    force?
-                   (and
-                    (seq (state/get-changed-files repo-url))
-                    (seq files))
+                   (seq files)
                    fallback?
                    diff-push?)
               ;; auto commit if there are any un-committed changes
@@ -425,9 +411,10 @@
                      (fn [result]
                        (git-handler/set-git-status! repo-url nil)
                        (git-handler/set-git-error! repo-url nil)
-                       (state/clear-changed-files! repo-url))
+                       (state/set-changed-files! repo-url nil))
                      (fn [error]
                        (js/console.error error)
+                       (common-handler/check-changed-files-status)
                        (let [permission? (or (string/includes? (str error) "401")
                                              (string/includes? (str error) "404"))]
                          (cond
@@ -519,8 +506,7 @@
                  (db/remove-db! url)
                  (db/remove-files-db! url)
                  (fs/rmdir (util/get-repo-dir url))
-                 (state/delete-repo! repo)
-                 (state/clear-changed-files! repo))
+                 (state/delete-repo! repo))
                (fn [error]
                  (prn "Delete repo failed, error: " error))))
 
@@ -617,7 +603,6 @@
   [{:keys [id url] :as repo}]
   (db/remove-conn! url)
   (db/clear-query-state!)
-  (state/clear-changed-files! url)
   (-> (p/let [_ (db/remove-db! url)
               _ (db/remove-files-db! url)]
         (fs/rmdir (util/get-repo-dir url)))

+ 9 - 24
src/main/frontend/state.cljs

@@ -23,9 +23,7 @@
     :repo/loading-files? nil
     :repo/importing-to-db? nil
     :repo/sync-status {}
-    :repo/changed-files (or
-                         (storage/get "git-changed-files")
-                         {})
+    :repo/changed-files nil
     :indexeddb/support? true
     ;; TODO: save in local storage so that if :changed? is true when user
     ;; reloads the browser, the app should re-index the repo (another way
@@ -718,27 +716,6 @@
   [value]
   (set-state! :indexeddb/support? value))
 
-(defn git-add!
-  [repo file]
-  (update-state! [:repo/changed-files repo]
-                 (fn [files] (distinct (conj files file))))
-  (storage/set "git-changed-files" (:repo/changed-files @state)))
-
-(defn reset-changed-files!
-  [files]
-  (when-let [repo (get-current-repo)]
-    (swap! state assoc-in [:repo/changed-files repo] files)))
-
-(defn clear-changed-files!
-  [repo]
-  (set-state! [:repo/changed-files repo] nil)
-  (set-state! [:git/status repo] nil)
-  (storage/set "git-changed-files" (:repo/changed-files @state)))
-
-(defn get-changed-files
-  [repo]
-  (get-in @state [:repo/changed-files repo]))
-
 (defn set-modal!
   [modal-panel-content]
   (swap! state assoc
@@ -838,3 +815,11 @@
 (defn git-auto-push?
   []
   (true? (:git-auto-push (get-config (get-current-repo)))))
+
+(defn set-changed-files!
+  [repo changed-files]
+  (set-state! [:repo/changed-files repo] changed-files))
+
+(defn get-changed-files
+  []
+  (get-in @state [:repo/changed-files (get-current-repo)]))