Commit 3f2788d4 authored by Dmitry Gutov's avatar Dmitry Gutov

project--vc-list-files: Recurse into submodules

* lisp/progmodes/project.el (project-try-vc): Do not treat a Git
submodule as a project root, go up to the parent repo.
(project--git-submodules): New function.
(project--vc-list-files): Use it.  Recurse into submodules.
parent f0da3aa8
Pipeline #4416 failed with stage
in 60 minutes and 10 seconds
......@@ -262,8 +262,15 @@ backend implementation of `project-external-roots'.")
(defun project-try-vc (dir)
(let* ((backend (ignore-errors (vc-responsible-backend dir)))
(root (and backend (ignore-errors
(vc-call-backend backend 'root dir)))))
(pcase backend
;; Don't stop at submodule boundary.
(or (vc-file-getprop dir 'project-git-root)
(vc-file-setprop dir 'project-git-root
(vc-find-root dir ".git/"))))
('nil nil)
(_ (ignore-errors (vc-call-backend backend 'root dir))))))
(and root (cons 'vc root))))
(cl-defmethod project-roots ((project (head vc)))
......@@ -303,7 +310,8 @@ backend implementation of `project-external-roots'.")
(pcase backend
(let ((default-directory (expand-file-name (file-name-as-directory dir)))
(args '("-z")))
(args '("-z"))
;; Include unregistered.
(setq args (append args '("-c" "-o" "--exclude-standard")))
(when extra-ignores
......@@ -315,11 +323,26 @@ backend implementation of `project-external-roots'.")
(format ":!/:%s" (substring i 2))
(format ":!:%s" i)))
(lambda (file) (concat default-directory file))
(apply #'vc-git--run-command-string nil "ls-files" args)
"\0" t))))
(setq files
(lambda (file) (concat default-directory file))
(apply #'vc-git--run-command-string nil "ls-files" args)
"\0" t)))
;; Unfortunately, 'ls-files --recurse-submodules' conflicts with '-o'.
(let* ((submodules (project--git-submodules))
(lambda (module)
(when (file-directory-p module)
(concat default-directory module)
(setq files
(apply #'nconc files sub-files)))
(let ((default-directory (expand-file-name (file-name-as-directory dir)))
......@@ -337,6 +360,18 @@ backend implementation of `project-external-roots'.")
(lambda (s) (concat default-directory s))
(split-string (buffer-string) "\0" t)))))))
(defun project--git-submodules ()
;; 'git submodule foreach' is much slower.
(condition-case nil
(insert-file-contents ".gitmodules")
(let (res)
(goto-char (point-min))
(while (re-search-forward "path *= *\\(.+\\)" nil t)
(push (match-string 1) res))
(nreverse res)))
(file-missing nil)))
(cl-defmethod project-ignores ((project (head vc)) dir)
(let* ((root (cdr project))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment