In my repo's
.git/config I have
status.showUntrackedFiles set to
no (for performance, because it's a very large repo).
However, sometimes (e.g. before I push to remote) I'd like to manually check, from magit, if there are untracked files.
Can I tell magit to ignore the behavior from my repo's git config, and show me the untracked files?
Alternatives I've tried
- Just use
git status -ufrom the command line to get the untracked files (this is fine, but it'd be nice to see this from magit)
- Hide untracked files using emacs (instead of
magit-status-sections-hook, and just call
magit-insert-untracked-fileswhen I need it (This seems simple enough, but I don't want to hide untracked files by default in all repos, just this one large repo)
Solution I Settled On
It was too long for a comment, so I'll just put it here.
I modified @whitetrillium's code to preserve my existing
magit-status-sections-hook in addition to adding the untracked files. That function is:
(defun my-magit-status () "Forcibly include untracked files at the end of magit-status." (interactive) (advice-add 'magit-get :around (defun magit-get--around (orig-fun &rest orig-args) ;; (debug) (pcase-let* ((`(,keys) orig-args)) (if (string= keys "status.showUntrackedFiles") "all" (apply orig-fun orig-args))))) (let ((magit-status-sections-hook (append magit-status-sections-hook '(magit-insert-untracked-files)))) (call-interactively 'magit-status)) (advice-remove 'magit-get 'magit-get--around))
Then bind this to whatever you want. (e.g.
(global-set-key (kbd "C-x G" 'my-magit-status), as recommended by @whitetrillium)
Then I figured I'd just add the untracked files to an existing
magit-status, and I used the same advice on
(defun magit-force-insert-untracked-files () "Forcibly insert untracked files (at point) in magit-status." (interactive) (defun magit-get--around (orig-fun &rest orig-args) (pcase-let* ((`(,keys) orig-args)) (if (string= keys "status.showUntrackedFiles") "all" (apply orig-fun orig-args)))) (advice-add 'magit-get :around 'magit-get--around) (read-only-mode -1) (magit-insert-untracked-files) (read-only-mode t) (advice-remove 'magit-get 'magit-get--around))
Sort of annoyingly, this performs the insert wherever your cursor is, but it's a nice way to just tack on the untracked files to your