From c29f7eb3e4d398f02fb2f5c641cc277da0d7f7b3 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Wed, 8 Apr 2026 08:46:28 +0200 Subject: magit-list-files: Never limit to subdirectory Never limit the list of files to those in `default-directory' and always return paths relative to the top-level. This affects other `magit-*-files' functions and their callers. Some callers of these functions explicitly used `magit-with-toplevel' and we can stop doing that now. Other callers did not use that macro but should have done so. Among those, many were always called from the top-level, so this bug was theoretical in those cases. Others are more likely to be called from a subdirectory. There are no callers that actually need just the files from a subdirectory. --- lisp/magit-diff.el | 11 +++++------ lisp/magit-files.el | 17 ++++++++--------- lisp/magit-git.el | 3 ++- lisp/magit-gitignore.el | 24 ++++++++++-------------- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el index 9d46576..4ccc51b 100644 --- a/lisp/magit-diff.el +++ b/lisp/magit-diff.el @@ -1136,12 +1136,11 @@ and `:slant'." :multi-value t) (defun magit-read-files (prompt initial-input history &optional list-fn) - (magit-with-toplevel - (magit-completing-read-multiple prompt - (funcall (or list-fn #'magit-list-files)) - nil nil - (or initial-input (magit-file-at-point)) - history))) + (magit-completing-read-multiple prompt + (funcall (or list-fn #'magit-list-files)) + nil nil + (or initial-input (magit-file-at-point)) + history)) (transient-define-argument magit-diff:-U () :description "Context lines" diff --git a/lisp/magit-files.el b/lisp/magit-files.el index f98edee..6ad6b19 100644 --- a/lisp/magit-files.el +++ b/lisp/magit-files.el @@ -710,15 +710,14 @@ Git, then fallback to using `delete-file'." (car (member (or default (magit-current-file)) files))))) (defun magit-read-file (prompt &optional tracked-only) - (magit-with-toplevel - (let ((choices (nconc (magit-list-files) - (and (not tracked-only) - (magit-untracked-files))))) - (magit-completing-read - prompt choices nil t nil nil - (car (member (or (magit-section-value-if '(file submodule)) - (magit-file-relative-name nil tracked-only)) - choices)))))) + (let ((choices (nconc (magit-list-files) + (and (not tracked-only) + (magit-untracked-files))))) + (magit-completing-read + prompt choices nil t nil nil + (car (member (or (magit-section-value-if '(file submodule)) + (magit-file-relative-name nil tracked-only)) + choices))))) (defun magit-read-tracked-file (prompt) (magit-read-file prompt t)) diff --git a/lisp/magit-git.el b/lisp/magit-git.el index c09bb7f..f3d9341 100644 --- a/lisp/magit-git.el +++ b/lisp/magit-git.el @@ -1126,7 +1126,8 @@ a bare repository." ;;;; File Lists (defun magit-list-files (&rest args) - (apply #'magit-git-items "ls-files" "-z" "--full-name" args)) + (magit-with-toplevel + (apply #'magit-git-items "ls-files" "-z" args))) (defun magit-tracked-files (&rest args) (magit-list-files "--cached" args)) diff --git a/lisp/magit-gitignore.el b/lisp/magit-gitignore.el index 8fd239b..d6fbf4d 100644 --- a/lisp/magit-gitignore.el +++ b/lisp/magit-gitignore.el @@ -158,11 +158,10 @@ Rules that are defined in that file affect all local repositories." "Call \"git update-index --skip-worktree -- FILE\"." (interactive (list (magit-read-file-choice "Skip worktree for" - (magit-with-toplevel - (cl-set-difference - (magit-list-files) - (magit-skip-worktree-files) - :test #'equal))))) + (cl-set-difference + (magit-list-files) + (magit-skip-worktree-files) + :test #'equal)))) (magit-with-toplevel (magit-run-git "update-index" "--skip-worktree" "--" file))) @@ -171,8 +170,7 @@ Rules that are defined in that file affect all local repositories." "Call \"git update-index --no-skip-worktree -- FILE\"." (interactive (list (magit-read-file-choice "Do not skip worktree for" - (magit-with-toplevel - (magit-skip-worktree-files))))) + (magit-skip-worktree-files)))) (magit-with-toplevel (magit-run-git "update-index" "--no-skip-worktree" "--" file))) @@ -183,11 +181,10 @@ Rules that are defined in that file affect all local repositories." "Call \"git update-index --assume-unchanged -- FILE\"." (interactive (list (magit-read-file-choice "Assume file to be unchanged" - (magit-with-toplevel - (cl-set-difference - (magit-list-files) - (magit-assume-unchanged-files) - :test #'equal))))) + (cl-set-difference + (magit-list-files) + (magit-assume-unchanged-files) + :test #'equal)))) (magit-with-toplevel (magit-run-git "update-index" "--assume-unchanged" "--" file))) @@ -196,8 +193,7 @@ Rules that are defined in that file affect all local repositories." "Call \"git update-index --no-assume-unchanged -- FILE\"." (interactive (list (magit-read-file-choice "Do not assume file to be unchanged" - (magit-with-toplevel - (magit-assume-unchanged-files))))) + (magit-assume-unchanged-files)))) (magit-with-toplevel (magit-run-git "update-index" "--no-assume-unchanged" "--" file))) -- cgit v1.0