Function: magit-submodule-remove
magit-submodule-remove is an autoloaded, interactive and byte-compiled
function defined in magit-submodule.el.
Signature
(magit-submodule-remove MODULES ARGS TRASH-GITDIRS)
Documentation
Unregister MODULES and remove their working directories.
For safety reasons, do not remove the gitdirs and if a module has uncommitted changes, then do not remove it at all. If a module's gitdir is located inside the working directory, then move it into the gitdir of the superproject first.
With the "--force" argument offer to remove dirty working directories and with a prefix argument offer to delete gitdirs. Both actions are very dangerous and have to be confirmed. There are additional safety precautions in place, so you might be able to recover from making a mistake here, but don't count on it.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-submodule.el
;;;###autoload
(defun magit-submodule-remove (modules args trash-gitdirs)
"Unregister MODULES and remove their working directories.
For safety reasons, do not remove the gitdirs and if a module has
uncommitted changes, then do not remove it at all. If a module's
gitdir is located inside the working directory, then move it into
the gitdir of the superproject first.
With the \"--force\" argument offer to remove dirty working
directories and with a prefix argument offer to delete gitdirs.
Both actions are very dangerous and have to be confirmed. There
are additional safety precautions in place, so you might be able
to recover from making a mistake here, but don't count on it."
(interactive
(list (if-let ((modules (magit-region-values 'magit-module-section t)))
(magit-confirm 'remove-modules nil "Remove %d modules" nil modules)
(list (magit-read-module-path "Remove module")))
(magit-submodule-arguments "--force")
current-prefix-arg))
(when magit-submodule-remove-trash-gitdirs
(setq trash-gitdirs t))
(magit-with-toplevel
(when-let
((modified
(seq-filter (lambda (module)
(let ((default-directory (file-name-as-directory
(expand-file-name module))))
(and (cddr (directory-files default-directory))
(magit-anything-modified-p))))
modules)))
(if (member "--force" args)
(if (magit-confirm 'remove-dirty-modules
"Remove dirty module %s"
"Remove %d dirty modules"
t modified)
(dolist (module modified)
(let ((default-directory (file-name-as-directory
(expand-file-name module))))
(magit-git "stash" "push"
"-m" "backup before removal of this module")))
(setq modules (cl-set-difference modules modified :test #'equal)))
(if (cdr modified)
(message "Omitting %s modules with uncommitted changes: %s"
(length modified)
(string-join modified ", "))
(message "Omitting module %s, it has uncommitted changes"
(car modified)))
(setq modules (cl-set-difference modules modified :test #'equal))))
(when modules
(let ((alist
(and trash-gitdirs
(mapcar (##split-string % "\0")
(magit-git-lines "submodule" "foreach" "-q"
"printf \"$sm_path\\0$name\n\"")))))
(magit-git "submodule" "absorbgitdirs" "--" modules)
(magit-git "submodule" "deinit" args "--" modules)
(magit-git "rm" args "--" modules)
(when (and trash-gitdirs
(magit-confirm 'trash-module-gitdirs
"Trash gitdir of module %s"
"Trash gitdirs of %d modules"
t modules))
(dolist (module modules)
(if-let ((name (cadr (assoc module alist))))
;; Disregard if `magit-delete-by-moving-to-trash'
;; is nil. Not doing so would be too dangerous.
(delete-directory (convert-standard-filename
(expand-file-name
(concat "modules/" name)
(magit-gitdir)))
t t)
(error "BUG: Weird module name and/or path for %s" module)))))
(magit-refresh))))