branch: elpa/magit
commit b9b68e26788af49250208a5c0327daf434b613f2
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit--gitignore-patterns: Spin out new function
---
lisp/magit-gitignore.el | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/lisp/magit-gitignore.el b/lisp/magit-gitignore.el
index 141b2abc0c..71f3d38623 100644
--- a/lisp/magit-gitignore.el
+++ b/lisp/magit-gitignore.el
@@ -108,27 +108,10 @@ Rules that are defined in that file affect all local
repositories."
(magit-refresh)))
(defun magit-gitignore-read-pattern ()
- (let* ((default (magit-current-file))
- (base (car magit-buffer-diff-files))
+ (let* ((base (car magit-buffer-diff-files))
(base (and base (file-directory-p base) base))
- (choices
- (delete-dups
- (mapcan
- (lambda (file)
- (cons (concat "/" file)
- (and$ (file-name-extension file)
- (list (concat "/" (file-name-directory file) "*." $)
- (concat "*." $)))))
- (sort (nconc
- (magit-untracked-files nil base)
- ;; The untracked section of the status buffer lists
- ;; directories containing only untracked files.
- ;; Add those as candidates.
- (seq-filter #'directory-name-p
- (magit-list-files
- "--other" "--exclude-standard" "--directory"
- "--no-empty-directory" "--" base)))
- #'string-lessp)))))
+ (choices (magit--gitignore-patterns base))
+ (default (magit-current-file)))
(when default
(setq default (concat "/" default))
(unless (member default choices)
@@ -138,6 +121,25 @@ Rules that are defined in that file affect all local
repositories."
(magit-completing-read "File or pattern to ignore"
choices nil 'any nil nil default)))
+(defun magit--gitignore-patterns (&optional directory)
+ (delete-dups
+ (mapcan
+ (lambda (file)
+ (cons (concat "/" file)
+ (and$ (file-name-extension file)
+ (list (concat "/" (file-name-directory file) "*." $)
+ (concat "*." $)))))
+ (sort (nconc
+ (magit-untracked-files nil directory)
+ ;; The untracked section of the status buffer lists
+ ;; directories containing only untracked files.
+ ;; Add those as candidates.
+ (seq-filter #'directory-name-p
+ (magit-list-files
+ "--other" "--exclude-standard" "--directory"
+ "--no-empty-directory" "--" directory)))
+ #'string-lessp))))
+
;;; Skip Worktree Commands
;;;###autoload