From 003121ba0ccc94649cfc28803ec0b924cb09d5f3 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sun, 16 Feb 2025 17:51:00 +0100 Subject: [PATCH] Add simple function to list changed git repositories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is akin (in purpose) to `magit-list-repositories`, but also descends into submodules. It's not as nice as `magit-list-repositories`, though … more of a draft version right now. This replaces a shell script with similar purpose. --- site-lisp/db-utils.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index 335ca68..50107af 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -656,6 +656,32 @@ quite sure whether something like this exists already?" (setq saved-window-configuration (current-window-configuration)) (delete-other-windows)))) +(defun db/list-changed-git-repositories () + "List git repositories under ~ that have changed content or need pushing." + (interactive) + (with-current-buffer (get-buffer-create " *changed-git-repos*") + (erase-buffer) + (dolist (dir (directory-files-recursively (expand-file-name "~") + "\\`\\.git\\'" + :include-directories + #'(lambda (subdir) + (not (string-match "\\(\\.git\\|\\.minetest\\|\\.local/share/Trash\\)" + subdir))))) + (let* ((default-directory (file-name-directory dir)) + (git-status (shell-command-to-string "git status -s -b")) + (has-uncommited-changes (string-match-p "^[^#]" git-status)) + (needs-pushing (string-match-p "\\[ahead " git-status))) + (when (or has-uncommited-changes needs-pushing) + (insert (format "Repository at %s: " default-directory)) + (when has-uncommited-changes + (insert "has uncommited changes")) + (when (and has-uncommited-changes needs-pushing) + (insert " and ")) + (when needs-pushing + (insert "needs pushing")) + (insert "\n")))) + (switch-to-buffer (current-buffer)))) + ;;; Base45 Decoding