diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2025-07-02 12:17:12 +0200 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2025-07-02 12:17:12 +0200 |
| commit | a64f246f71ea61f0dec5263ef65b27ac3ef29d6f (patch) | |
| tree | 8b0d4e5fbe8a8359c048a12d94bf82bffe5ea7c0 /lisp/magit-git.el | |
| parent | 0ea29a615a33743e08a457402a4cbea37a4a4a88 (diff) | |
magit-discard: On "Untracked files" delete exactly the listed files
Use the same code to generate a list of untracked fils, when
`magit-discard' is invoked on the "Untracked files" section as
was used to populate the list of files displayed in that section.
We should do that even if it weren't for the following issue, but
that is how we noticed something had to be done.
Contrary to what the documentation claims, "git ls-files --other
--directory --exclude-standard" does not honor ".gitignore" from
sub-directories.
Closes #5405.
Diffstat (limited to 'lisp/magit-git.el')
| -rw-r--r-- | lisp/magit-git.el | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lisp/magit-git.el b/lisp/magit-git.el index 2e6a14c..9ff3fbe 100644 --- a/lisp/magit-git.el +++ b/lisp/magit-git.el @@ -63,6 +63,9 @@ (defvar magit-this-error) (defvar magit-process-error-message-regexps) +;; From `magit-status'. +(defvar magit-status-show-untracked-files) + (eval-when-compile (cl-pushnew 'orig-rev eieio--known-slot-names) (cl-pushnew 'number eieio--known-slot-names)) @@ -1069,10 +1072,42 @@ tracked file." (magit-list-files "--cached" args)) (defun magit-untracked-files (&optional all files &rest args) + "Return a list of untracked files. + +Note that when using \"--directory\", the rules from \".gitignore\" +files from sub-directories are ignore, which is probably a Git bug. +See also `magit-list-untracked-files', which does not have this +issue." (magit-list-files "--other" args (and (not all) "--exclude-standard") "--" files)) +(defun magit-list-untracked-files (&optional files) + "Return a list of untracked files. + +List files if `magit-status-show-untracked-files' is non-nil, but also +take the local value of Git variable `status.showUntrackedFiles' into +account. The local value of the Lisp variable takes precedence over the +local value of the Git variable. The global value of the Git variable +is always ignored. + +See also `magit-untracked-files'." + (and-let* + ((value (or (and (local-variable-p 'magit-status-show-untracked-files) + magit-status-show-untracked-files) + (pcase (magit-get "--local" "status.showUntrackedFiles") + ((or "no" "off" "false" "0") 'no) + ((or "yes" "on" "true" "1") t) + ("all" 'all)) + magit-status-show-untracked-files)) + ((not (eq value 'no)))) + (mapcan (##and (eq (aref % 0) ??) + (list (substring % 3))) + (apply #'magit-git-items "status" "-z" "--porcelain" + (format "--untracked-files=%s" + (if (eq value 'all) "all" "normal")) + "--" files)))) + (defun magit-ignored-files (&rest args) (magit-list-files "--others" "--ignored" "--exclude-standard" args)) |
