I had the same request (I actually opened the issue that added this feature here), but was not satisfied with the requirement to add a new file every time I wanted to limit the magit status, so I created magit-status-current-dir
to open magit in the current directory.
(defun magit-status-in-dir (dir)
"limit magit status to directory"
(interactive "D")
(require 'magit)
(let* ((root (vc-git-root dir))
(dir (list (file-relative-name dir root)))
(magit-status-mode-hook (cons (lambda () (setq-local magit-diff-section-file-args dir))
magit-status-mode-hook)))
(magit-status-internal root)))
(defun magit-status-current-dir ()
"run magit in current dir"
(interactive)
(magit-status-in-dir default-directory))
(defun magit-clear-diff-args-if-not-dir-local ()
(unless (assq 'magit-diff-section-file-args dir-local-variables-alist)
(setq-local magit-diff-section-file-args nil)))
(advice-add 'magit-status :around
(defun magit-remove-diff-args (fn &rest args)
(let ((magit-status-mode-hook (cons 'magit-clear-diff-args-if-not-dir-local
magit-status-mode-hook)))
(apply fn args))))