|
|
@@ -423,56 +423,59 @@
|
|
|
|
|
|
(defn push
|
|
|
[repo-url {:keys [commit-message merge-push-no-diff? custom-commit?]
|
|
|
- :or {custom-commit false
|
|
|
- commit-message "Logseq auto save"
|
|
|
+ :or {custom-commit? false
|
|
|
merge-push-no-diff? false}}]
|
|
|
(spec/validate :repos/url repo-url)
|
|
|
- (let [status (db/get-key-value repo-url :git/status)]
|
|
|
- (if (and
|
|
|
- (db/cloned? repo-url)
|
|
|
- (state/input-idle? repo-url)
|
|
|
- (or (not= status :pushing)
|
|
|
- custom-commit?))
|
|
|
- (-> (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"
|
|
|
- commit-message)]
|
|
|
- (p/let [commit-oid (git/commit repo-url commit-message)
|
|
|
- token (common-handler/get-github-token repo-url)
|
|
|
- status (db/get-key-value repo-url :git/status)]
|
|
|
- (when (and token (or (not= status :pushing)
|
|
|
- custom-commit?))
|
|
|
- (git-handler/set-git-status! repo-url :pushing)
|
|
|
- (util/p-handle
|
|
|
- (git/push repo-url token merge-push-no-diff?)
|
|
|
- (fn [result]
|
|
|
- (git-handler/set-git-status! repo-url nil)
|
|
|
- (git-handler/set-git-error! repo-url nil)
|
|
|
- (common-handler/check-changed-files-status repo-url))
|
|
|
- (fn [error]
|
|
|
- (log/error :git/push-error error)
|
|
|
- (js/console.error error)
|
|
|
- (common-handler/check-changed-files-status repo-url)
|
|
|
- (do
|
|
|
- (git-handler/set-git-status! repo-url :push-failed)
|
|
|
- (git-handler/set-git-error! repo-url error)
|
|
|
- (if (state/online?)
|
|
|
- (pull repo-url {:force-pull? 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)
|
|
|
-
|
|
|
- (when custom-commit?
|
|
|
- (p/rejected error))))))))
|
|
|
+ (let [status (db/get-key-value repo-url :git/status)
|
|
|
+ commit-message (if (string/blank? commit-message)
|
|
|
+ "Logseq auto save"
|
|
|
+ commit-message)]
|
|
|
+ (when (and
|
|
|
+ (db/cloned? repo-url)
|
|
|
+ (state/input-idle? repo-url)
|
|
|
+ (or (not= status :pushing)
|
|
|
+ custom-commit?))
|
|
|
+ (->
|
|
|
+ (p/let [files (git/add-all (state/get-current-repo))
|
|
|
+ changed-files? (some? (seq files))
|
|
|
+ should-commit? (or changed-files? merge-push-no-diff?)
|
|
|
+
|
|
|
+ _commit (when should-commit?
|
|
|
+ (git/commit repo-url commit-message))
|
|
|
+
|
|
|
+ token (common-handler/get-github-token repo-url)
|
|
|
+ status (db/get-key-value repo-url :git/status)]
|
|
|
+ (when (and token
|
|
|
+ (or custom-commit?
|
|
|
+ (and (not= status :pushing)
|
|
|
+ changed-files?)))
|
|
|
+ (git-handler/set-git-status! repo-url :pushing)
|
|
|
+ (util/p-handle
|
|
|
+ (git/push repo-url token merge-push-no-diff?)
|
|
|
+ (fn [_result]
|
|
|
+ (git-handler/set-git-status! repo-url nil)
|
|
|
+ (git-handler/set-git-error! repo-url nil)
|
|
|
+ (common-handler/check-changed-files-status repo-url))
|
|
|
+ (fn [error]
|
|
|
+ (log/error :git/push-error error)
|
|
|
+ (js/console.error error)
|
|
|
+ (common-handler/check-changed-files-status repo-url)
|
|
|
+
|
|
|
+ (git-handler/set-git-status! repo-url :push-failed)
|
|
|
+ (git-handler/set-git-error! repo-url error)
|
|
|
+
|
|
|
+ (if (state/online?)
|
|
|
+ (pull repo-url {:force-pull? 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)
|
|
|
+
|
|
|
+ (when custom-commit?
|
|
|
+ (p/rejected error))))))))
|
|
|
|
|
|
(defn push-if-auto-enabled!
|
|
|
[repo]
|