From 8ca7a700bbcafe02a1df0a59401c97da6e7478b6 Mon Sep 17 00:00:00 2001 From: yoctocell Date: Wed, 6 Jan 2021 11:21:51 +0100 Subject: Check if selected files are patches Throw an error if the selected files aren't valid patch files. * git-email.el (git-email--check-file): (git-email--get-filenames): --- git-email.el | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'git-email.el') diff --git a/git-email.el b/git-email.el index 5fe7cfc..21a49a5 100644 --- a/git-email.el +++ b/git-email.el @@ -133,6 +133,14 @@ If the header is not found, return an empty string." (- (re-search-forward "\n\n") 1) (point-max)))) +(defun git-email--check-file (file) + "Check if FILE is a patch." + (if (and (file-readable-p file) + (or (string-match-p "\\.patch$" file) + (string-match-p "\\.diff$" file))) + file + (error "Not a valid patch!"))) + (defun git-email--dired-files () "Return list of filenames for marked files in `dired'. If no marks are found, return the filename at point." @@ -165,14 +173,16 @@ If no marks are found, return the filename at point." (defun git-email--get-filenames () "Return list of filenames for marked files in `vc-dir'. If no marks are found, return the filename at point." - (cond ((eq major-mode 'dired-mode) - (git-email--dired-files)) - ((eq major-mode 'vc-dir-mode) - (git-email--vc-dir-files)) - ((eq major-mode 'ibuffer-mode) - (git-email--ibuffer-files)) - (t - (git-email--minibuffer-file)))) + (let ((files (cond ((eq major-mode 'dired-mode) + (git-email--dired-files)) + ((eq major-mode 'vc-dir-mode) + (git-email--vc-dir-files)) + ((eq major-mode 'ibuffer-mode) + (git-email--ibuffer-files)) + (t + (git-email--minibuffer-file))))) + (when (mapcar 'git-email--check-file files) + files))) ;;;###autoload (defun git-email-apply-patch (project) -- cgit v1.2.3