Skip to content

Commit 1874ca0

Browse files
committed
Extract author resolving
1 parent 9376569 commit 1874ca0

2 files changed

Lines changed: 29 additions & 23 deletions

File tree

magit-standup.el

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,22 @@ the org link prefix string, or nil for plain text."
157157
hash)
158158
rest)))
159159

160+
(defun magit-standup--resolve-author (repo-path)
161+
"Return the author string to filter commits by in REPO-PATH.
162+
Uses `magit-standup-author' if set, otherwise falls back to
163+
`git config user.email' in REPO-PATH."
164+
(let ((default-directory (file-name-as-directory repo-path)))
165+
(or magit-standup-author
166+
(magit-git-string "config" "user.email")
167+
(user-error "Cannot determine author for %s; set `magit-standup-author' or git config user.email" repo-path))))
168+
160169
(defun magit-standup--collect-commits (repo-path since-date)
161170
"Collect commits from REPO-PATH since SINCE-DATE.
162171
Returns an alist of (BRANCH-NAME . COMMITS) where COMMITS is a
163172
list of raw commit strings with hash and message separated by a
164-
null byte. The author is determined from `magit-standup-author'
165-
or `git config user.email' in REPO-PATH."
173+
null byte."
166174
(let* ((default-directory (file-name-as-directory repo-path))
167-
(author (or magit-standup-author
168-
(magit-git-string "config" "user.email")
169-
(user-error "Cannot determine author for %s; set `magit-standup-author' or git config user.email" repo-path)))
175+
(author (magit-standup--resolve-author repo-path))
170176
(branches (magit-git-lines "branch" "--format=%(refname:short)")))
171177
(mapcar (lambda (branch)
172178
(cons branch

test/magit-standup-test.el

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,40 +81,40 @@
8181
"/home/user/repo" '("stale-branch"))
8282
:to-be nil)))
8383

84-
(describe "magit-standup--collect-commits"
85-
(it "sets default-directory to the repo path"
86-
(let ((magit-standup-author "alice")
87-
captured-dirs)
88-
(spy-on 'magit-git-lines :and-call-fake
89-
(lambda (&rest _)
90-
(push default-directory captured-dirs)
91-
nil))
92-
(magit-standup--collect-commits "/tmp/my-repo" "2026-01-05")
93-
(expect captured-dirs :not :to-be nil)
94-
(dolist (dir captured-dirs)
95-
(expect dir :to-equal "/tmp/my-repo/"))))
96-
84+
(describe "magit-standup--resolve-author"
9785
(it "uses magit-standup-author when set"
9886
(let ((magit-standup-author "alice"))
9987
(spy-on 'magit-git-string)
100-
(spy-on 'magit-git-lines :and-return-value nil)
101-
(magit-standup--collect-commits "/tmp/repo" "2026-01-05")
88+
(magit-standup--resolve-author "/tmp/repo")
10289
(expect 'magit-git-string :not :to-have-been-called)))
10390

10491
(it "falls back to git config user.email"
10592
(let ((magit-standup-author nil))
10693
(spy-on 'magit-git-string :and-return-value "bob@example.com")
107-
(spy-on 'magit-git-lines :and-return-value nil)
108-
(magit-standup--collect-commits "/tmp/repo" "2026-01-05")
94+
(expect (magit-standup--resolve-author "/tmp/repo")
95+
:to-equal "bob@example.com")
10996
(expect 'magit-git-string
11097
:to-have-been-called-with "config" "user.email")))
11198

11299
(it "signals error when no author can be determined"
113100
(let ((magit-standup-author nil))
114101
(spy-on 'magit-git-string :and-return-value nil)
115-
(expect (magit-standup--collect-commits "/tmp/repo" "2026-01-05")
102+
(expect (magit-standup--resolve-author "/tmp/repo")
116103
:to-throw 'user-error))))
117104

105+
(describe "magit-standup--collect-commits"
106+
(it "sets default-directory to the repo path"
107+
(let ((magit-standup-author "alice")
108+
captured-dirs)
109+
(spy-on 'magit-git-lines :and-call-fake
110+
(lambda (&rest _)
111+
(push default-directory captured-dirs)
112+
nil))
113+
(magit-standup--collect-commits "/tmp/my-repo" "2026-01-05")
114+
(expect captured-dirs :not :to-be nil)
115+
(dolist (dir captured-dirs)
116+
(expect dir :to-equal "/tmp/my-repo/")))))
117+
118118
(describe "magit-standup--resolve-repos"
119119
:var (tmpdir)
120120

0 commit comments

Comments
 (0)