Skip to content

Commit 8da7a8e

Browse files
committed
Change: (magit-todos-branch-list-merge-base-ref) Detect automatically
Fixes #151. Closes #152. Reported-by: Aaron Zeng <https://github.com/bcc32>
1 parent 8f22fa5 commit 8da7a8e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ Helm and Ivy are also supported. Note that the =helm= and =ivy= packages are no
133133

134134
*Changed*
135135
+ Improve behavior when scanner backend exits with an error. (Now an error is signaled and the command's output is shown.)
136+
+ Option ~magit-todos-branch-list-merge-base-ref~ defaults to nil, which automatically detects the default branch name using function ~magit-main-branch~. ([[https://github.com/alphapapa/magit-todos/issues/151][#151]]. Thanks to [[https://github.com/bcc32][Aaron Zeng]] for reporting.)
136137

137138
*Fixed*
138139
+ Updated ~find|grep~ scanner for newer versions of GNU ~find~ that interpret some arguments differently. (Tested on v4.8.0.)

magit-todos.el

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ This can be toggled locally in Magit buffers with command
370370
(const :tag "In non-master branches" branch)
371371
(const :tag "Always" t)))
372372

373-
(defcustom magit-todos-branch-list-merge-base-ref "master"
373+
(defcustom magit-todos-branch-list-merge-base-ref nil
374374
"Commit ref passed to command \"git merge-base HEAD\".
375375
Determines the ancestor commit from which the current branch's
376376
todos should be searched for. May be overridden in the case that
@@ -387,7 +387,8 @@ By default, the branch todo list would show todos from both the
387387
\"topic\" branch and the \"topic2\" branch. To show only todos
388388
from the \"topic2\" branch, this option could be set to
389389
\"topic\"."
390-
:type 'string)
390+
:type '(choice (const :tag "Automatic" :doc "Value returned by `magit-main-branch'" nil)
391+
(string :tag "Specified branch name")))
391392

392393
(defcustom magit-todos-submodule-list nil
393394
"Show submodule to-do list."
@@ -760,12 +761,14 @@ This function should be called from inside a ‘magit-status’ buffer."
760761
(magit-todos--insert-items (current-buffer) magit-todos-item-cache)))
761762
(when (or (eq magit-todos-branch-list t)
762763
(and (eq magit-todos-branch-list 'branch)
763-
(not (string= "master" (magit-get-current-branch)))))
764+
(not (equal (or magit-todos-branch-list-merge-base-ref (magit-main-branch))
765+
(magit-get-current-branch)))))
764766
;; Insert branch-local items.
765767
(magit-todos--scan-with-git-diff :magit-status-buffer (current-buffer)
766768
:directory default-directory
767769
:depth magit-todos-depth
768-
:heading (format "TODOs (branched from %s)" magit-todos-branch-list-merge-base-ref))))
770+
:heading (format "TODOs (branched from %s)"
771+
(or magit-todos-branch-list-merge-base-ref (magit-main-branch))))))
769772

770773
(cl-defun magit-todos--insert-items (magit-status-buffer items &key branch-p)
771774
"Insert to-do ITEMS into MAGIT-STATUS-BUFFER.
@@ -1396,7 +1399,7 @@ When SYNC is non-nil, match items are returned."
13961399
;; Silence byte-compiler warnings about these vars we don't use in this scanner.
13971400
(ignore search-regexp-elisp search-regexp-pcre extra-args directory depth)
13981401
(let ((merge-base-ref (-> "git merge-base HEAD "
1399-
(concat magit-todos-branch-list-merge-base-ref)
1402+
(concat (or magit-todos-branch-list-merge-base-ref (magit-main-branch)))
14001403
shell-command-to-string
14011404
string-trim)))
14021405
(unless (string-empty-p merge-base-ref)

0 commit comments

Comments
 (0)