As the tagline says, if you're trying to use Emacs's built-n project-management package, project.el
, to add a git version-controlled project that git deems untrustworthy and then do a project-find-{files,dir} on it, it will currently crash, because the output of the git ls-files
outputs a bunch of errors to stderr and nothing to stdout, and it doesn't expect to have an empty list of files and directories. To resolve this, I've created a nice snipped of code that will detect, when you add a project, whether git deems it unsafe (git ls-files returns code 128 to mean that) and ask you whether you want to add it to your list of safe directories:
(advice-add 'project-remember-project
:before (lambda (pr &optional something)
(when (and (eq 'Git (cadr pr))
(let ((default-directory (caddr pr)))
(= (shell-command "git ls-files") 128)))
(when (y-or-n-p "Dubious ownership of repository detected. Treat as safe? ")
(shell-command
(concat "git config --global --add safe.directory "
(eshell-escape-arg (directory-file-name (file-local-name (caddr pr))))))))))