Skip to content

Commit d3ac9f4

Browse files
author
Jason Duncan
committed
Now observes the limit argument sent by dashboard.
1 parent bddd773 commit d3ac9f4

File tree

2 files changed

+75
-22
lines changed

2 files changed

+75
-22
lines changed

dashboard-project-status.el

+23-16
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,28 @@
6161
" is behind the remote. (use \"git pull\" to update)"
6262
" is up-to-date.")))
6363

64-
(defun dashboard-project-status-insert-body ()
65-
"Insert lists of untracked, unstaged, and staged files."
66-
(dolist (section `(("Untracked Files:" . ,(git-untracked-files))
67-
("Unstaged Files:" . ,(dashboard-project-status-git-unstaged-files))
68-
("Staged Files:" . ,(git-staged-files))))
69-
(when (cdr section)
70-
(insert hard-newline)
71-
(dashboard-insert-recentf-list
72-
(car section)
73-
(reverse
74-
(let (ret)
75-
(dolist (cur (cdr section) ret)
76-
(setq ret (cons (expand-file-name
77-
(concat (file-name-as-directory git-repo) cur))
78-
ret)))))))))
64+
(defun dashboard-project-status-insert-body (limit)
65+
"Insert lists of untracked, unstaged, and staged files LIMIT -ed as specified."
66+
(let ((count 0))
67+
(dolist (section `(("Untracked Files:" . ,(git-untracked-files))
68+
("Unstaged Files:" . ,(dashboard-project-status-git-unstaged-files))
69+
("Staged Files:" . ,(git-staged-files))))
70+
(when (cdr section)
71+
(let* ((items (cdr section))
72+
(items (if (> (+ count (length items)) limit)
73+
(dashboard-subseq items 0 (- limit count))
74+
items)))
75+
(when items
76+
(setq count (+ count (length items)))
77+
(insert hard-newline)
78+
(dashboard-insert-recentf-list
79+
(car section)
80+
(reverse
81+
(let (ret)
82+
(dolist (cur items ret)
83+
(setq ret (cons (expand-file-name
84+
(concat (file-name-as-directory git-repo) cur))
85+
ret))))))))))))
7986

8087
(defun dashboard-project-status (project-dir &optional update)
8188
"Return a function which will insert git status for PROJECT-DIR.
@@ -84,7 +91,7 @@ If UPDATE is non-nil, update the remote first with 'git remote update'."
8491
(let ((git-repo ,project-dir))
8592
(when ,update (git-run "remote" "update"))
8693
(dashboard-project-status-insert-heading)
87-
(dashboard-project-status-insert-body))))
94+
(dashboard-project-status-insert-body list-size))))
8895

8996
(provide 'dashboard-project-status)
9097
;;; dashboard-project-status.el ends here

test/dashboard-project-status-test.el

+52-6
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@
1212
(stub dashboard-project-status-insert-heading)
1313
(stub dashboard-project-status-insert-body)
1414
(funcall (dashboard-project-status "foo") nil))
15+
1516
(desc "dashboard-project-status with non-nil UPDATE value")
1617
(expect (mock (git-run "remote" "update") => nil)
1718
(stub dashboard-project-status-insert-heading)
1819
(stub dashboard-project-status-insert-body)
1920
(funcall (dashboard-project-status "foo" t) nil))
21+
2022
(desc "dashboard-project-status inserts a heading")
2123
(expect (mock (dashboard-project-status-insert-heading) => nil)
2224
(stub dashboard-project-status-insert-body)
2325
(funcall (dashboard-project-status "foo") nil))
26+
2427
(desc "dashboard-project-status inserts a body")
25-
(expect (mock (dashboard-project-status-insert-body) => nil)
28+
(expect (mock (dashboard-project-status-insert-body 7) => nil)
2629
(stub dashboard-project-status-insert-heading)
27-
(funcall (dashboard-project-status "foo") nil))
30+
(funcall (dashboard-project-status "foo") 7))
31+
2832
(desc "dashboard-project-status-insert-heading when magit is present inserts status text")
2933
;; the blank in the middle is where the widget should go,
3034
;; but I cannot as yet figure out a way to test that
@@ -36,6 +40,7 @@
3640
(mocklet (((functionp 'magit-status) => t))
3741
(dashboard-project-status-insert-heading)))
3842
(buffer-string)))
43+
3944
(desc "dashboard-project-status-insert-heading when magit is not present only inserts text")
4045
(expect "Project foo is up-to-date."
4146
(stub dashboard-project-status-git-local-is-behind?)
@@ -44,14 +49,16 @@
4449
(mocklet (((functionp 'magit-status)))
4550
(dashboard-project-status-insert-heading)))
4651
(buffer-string)))
52+
4753
(desc "dashboard-project-status-insert-body inserts nothing when no items")
4854
(expect ""
4955
(stub git-untracked-files)
5056
(stub dashboard-project-status-git-unstaged-files)
5157
(stub git-staged-files)
5258
(with-temp-buffer
53-
(dashboard-project-status-insert-body)
59+
(dashboard-project-status-insert-body 5)
5460
(buffer-string)))
61+
5562
(desc "dashboard-project-status-insert-body inserts untracked files")
5663
(expect (concat "\nUntracked Files:"
5764
"\n "
@@ -69,8 +76,9 @@
6976
(let ((git-repo "foo"))
7077
(flet ((widget-create (&rest args)
7178
(insert (car (last args)))))
72-
(dashboard-project-status-insert-body)))
79+
(dashboard-project-status-insert-body 5)))
7380
(buffer-string)))
81+
7482
(desc "dashboard-project-status-insert-body inserts unstaged files")
7583
(expect (concat "\nUnstaged Files:"
7684
"\n "
@@ -88,8 +96,9 @@
8896
(let ((git-repo "foo"))
8997
(flet ((widget-create (&rest args)
9098
(insert (car (last args)))))
91-
(dashboard-project-status-insert-body)))
99+
(dashboard-project-status-insert-body 5)))
92100
(buffer-string)))
101+
93102
(desc "dashboard-project-status-insert-body inserts staged files")
94103
(expect (concat "\nStaged Files:"
95104
"\n "
@@ -107,16 +116,53 @@
107116
(let ((git-repo "foo"))
108117
(flet ((widget-create (&rest args)
109118
(insert (car (last args)))))
110-
(dashboard-project-status-insert-body)))
119+
(dashboard-project-status-insert-body 5)))
120+
(buffer-string)))
121+
122+
(desc "dashboard-project-status-insert-body observes limit")
123+
(expect (concat "\nUntracked Files:"
124+
"\n "
125+
(abbreviate-file-name
126+
(expand-file-name
127+
(concat (file-name-as-directory "foo") "foo")))
128+
"\n "
129+
(abbreviate-file-name
130+
(expand-file-name
131+
(concat (file-name-as-directory "foo") "bar")))
132+
"\nUnstaged Files:"
133+
"\n "
134+
(abbreviate-file-name
135+
(expand-file-name
136+
(concat (file-name-as-directory "foo") "foo")))
137+
"\n "
138+
(abbreviate-file-name
139+
(expand-file-name
140+
(concat (file-name-as-directory "foo") "bar")))
141+
"\nStaged Files:"
142+
"\n "
143+
(abbreviate-file-name
144+
(expand-file-name
145+
(concat (file-name-as-directory "foo") "foo"))))
146+
(stub git-untracked-files => '("foo" "bar"))
147+
(stub dashboard-project-status-git-unstaged-files => '("foo" "bar"))
148+
(stub git-staged-files => '("foo" "bar"))
149+
(with-temp-buffer
150+
(let ((git-repo "foo"))
151+
(flet ((widget-create (&rest args)
152+
(insert (car (last args)))))
153+
(dashboard-project-status-insert-body 5)))
111154
(buffer-string)))
155+
112156
(desc "dashboard-project-status-git-local-is-behind? returns non nil when branch is behind")
113157
(expect t
114158
(mock (git-run "status" "-uno") => "Your branch is behind")
115159
(dashboard-project-status-git-local-is-behind?))
160+
116161
(desc "dashboard-project-status-git-local-is-behind? returns nil when branch is not behind")
117162
(expect nil
118163
(mock (git-run "status" "-uno") => "")
119164
(dashboard-project-status-git-local-is-behind?))
165+
120166
(desc "dashboard-project-status-git-unstaged-files returns a list of unstaged files")
121167
(expect '("foo" "bar")
122168
(mock (git-run "diff" "--name-only") => "foo\nbar")

0 commit comments

Comments
 (0)