summaryrefslogtreecommitdiff
path: root/lisp/km-magit.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2017-01-26 23:05:37 -0500
committerKyle Meyer <kyle@kyleam.com>2017-01-26 23:05:37 -0500
commit4791ff89fafaa785394cad771bc84749d5dfb064 (patch)
treedadb6b2bd99202a823ed5c43a6cea3ac3e78c6fb /lisp/km-magit.el
parente2551619ece269cf0e425f6f619d39856c8aa255 (diff)
downloademacs.d-4791ff89fafaa785394cad771bc84749d5dfb064.tar.gz
magit: Add remote counts section to status buffer
Diffstat (limited to 'lisp/km-magit.el')
-rw-r--r--lisp/km-magit.el58
1 files changed, 58 insertions, 0 deletions
diff --git a/lisp/km-magit.el b/lisp/km-magit.el
index 0c4a344..1ec6bba 100644
--- a/lisp/km-magit.el
+++ b/lisp/km-magit.el
@@ -646,6 +646,64 @@ argument. Interactively, this can be accessed using the command
(magit-log (list range) args files)
(call-interactively #'magit-log))))
+(defun km/magit--insert-count-lines (rev counts)
+ (-let [(n-behind n-ahead) counts]
+ (when (> n-ahead 0)
+ (magit-insert-section (unpushed (concat rev ".."))
+ (magit-insert-heading
+ (format "%3s ahead of %s"
+ (propertize (number-to-string n-ahead)
+ 'face 'magit-diffstat-added)
+ rev))))
+ (when (> n-behind 0)
+ (magit-insert-section (unpulled (concat ".." rev))
+ (magit-insert-heading
+ (format "%3s behind %s"
+ (propertize (number-to-string n-behind)
+ 'face 'magit-diffstat-removed)
+ rev))))))
+
+(defun km/magit-insert-remote-counts ()
+ "Insert section showing number of unpushed and unpulled commits.
+
+This function is a lightweight replacement of four
+`magit-status-sections-hook' functions:
+`magit-insert-unpulled-from-upstream',
+`magit-insert-unpulled-from-pushremote',
+`magit-insert-unpushed-to-upstream', and
+`magit-insert-unpushed-to-pushremote'.
+
+Unlike the above functions, this function does not insert a log
+of unpulled or unpushed commits, but instead inserts a combined
+section that only reports the number of commits in each
+category."
+ (when (magit-get-current-branch)
+ (let* ((up-counts (and (magit-git-success "rev-parse" "@{upstream}")
+ (magit-rev-diff-count "@{upstream}" "")))
+ ;; Unlike `magit-insert-unpushed-to-pushremote' and
+ ;; `magit-insert-unpulled-from-pushremote', just use
+ ;; "@{push}". This drops support for the push-remote if
+ ;; push.default isn't set to a compatible value. See
+ ;; Magit's 6505f4cd.
+ (pu-counts (and (magit-git-success "rev-parse" "@{push}")
+ (magit-rev-diff-count "@{push}" "")))
+ (up-any (and up-counts (or (> (car up-counts) 0)
+ (> (cadr up-counts) 0))))
+ (pu-any (and pu-counts (or (> (car pu-counts) 0)
+ (> (cadr pu-counts) 0)))))
+ (when (or up-any pu-any)
+ (magit-insert-section (remote-counts)
+ (magit-insert-heading "Remote counts")
+ (when up-any
+ (km/magit--insert-count-lines "@{upstream}" up-counts))
+ (when (and pu-any (not (and up-any
+ (equal (magit-rev-name "@{upstream}")
+ (magit-rev-name "@{push}")))))
+ (km/magit--insert-count-lines "@{push}" pu-counts)))))))
+
+(magit-define-section-jumper magit-jump-to-remote-counts
+ "Remote counts" remote-counts)
+
;;; Git Rebase mode