branch: externals/ssh-deploy commit 4c1a539e6f95e4847c13685d2b752e40d2b8aad8 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Added customizable exclusion patterns --- ssh-deploy.el | 61 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/ssh-deploy.el b/ssh-deploy.el index 52babd0..2f05d3b 100644 --- a/ssh-deploy.el +++ b/ssh-deploy.el @@ -3,8 +3,8 @@ ;; Author: Christian Johansson <github.com/cjohansson> ;; Maintainer: Christian Johansson <github.com/cjohansson> ;; Created: 5 Jul 2016 -;; Modified: 9 Jan 2017 -;; Version: 1.49 +;; Modified: 15 Mar 2017 +;; Version: 1.50 ;; Keywords: tools, convenience ;; URL: https://github.com/cjohansson/emacs-ssh-deploy @@ -118,6 +118,11 @@ :type 'boolean :group 'ssh-deploy) +(defcustom ssh-deploy-exclude-list '("/.git/" ".dir-locals.el") + "List of strings that if found in paths will exclude paths from sync, '(\"/.git\"/' \".dir-locals.el\") by default." + :type 'list + :group 'ssh-deploy) + (defun ssh-deploy--get-revision-path (path) "Generate revision-path for PATH." (if (not (file-exists-p ssh-deploy-revision-folder)) @@ -128,6 +133,16 @@ "Return true if FILE is in the path PATH." (not (null (string-match path file)))) +(defun ssh-deploy--file-is-included (path) + "Return true if PATH is not in the exclusion list." + (let ((not-found t)) + (dolist (element ssh-deploy-exclude-list) + (if (and (not (null element)) + (not (null (string-match element path)))) + (progn + (setq not-found nil)))) + not-found)) + (defun ssh-deploy--get-relative-path (root path) "Return a string for the relative path based on ROOT and PATH." (replace-regexp-in-string root "" path)) @@ -186,10 +201,10 @@ (list 0 (format "Upload '%s' completed." ,remote-path))) (list 1 (format "External file '%s' has changed, please download or diff." ,remote-path)))) (list 1 "Function ediff-same-file-contents is missing."))) - (lambda(return) - (if (= (nth 0 return) 0) - (message (nth 1 return)) - (display-warning "ssh-deploy" (nth 1 return) :warning)))))) + (lambda(return) + (if (= (nth 0 return) 0) + (message (nth 1 return)) + (display-warning "ssh-deploy" (nth 1 return) :warning)))))) (progn (message "Uploading directory '%s' to '%s' via tramp asynchronously.." local remote-path) (if (string= remote-path (alist-get 'string remote)) @@ -316,7 +331,8 @@ ;;;### autoload (defun ssh-deploy (local-root remote-root upload-or-download path debug async force) "Upload/Download file or directory relative to the roots LOCAL-ROOT with REMOTE-ROOT via ssh or ftp according to UPLOAD-OR-DOWNLOAD and the path PATH, DEBUG enables some feedback messages and ASYNC determines if transfers should be asynchrous or not, FORCE upload despite external change." - (if (ssh-deploy--file-is-in-path path local-root) + (if (and (ssh-deploy--file-is-in-path path local-root) + (ssh-deploy--file-is-included path)) (progn (let ((file-or-directory (file-regular-p path))) (let ((remote-path (concat remote-root (ssh-deploy--get-relative-path local-root path)))) @@ -325,7 +341,7 @@ (ssh-deploy--upload path connection local-root async force) (ssh-deploy--download connection path local-root async)))))) (if debug - (message "Path '%s' is not in the root '%s'" path local-root)))) + (message "Path '%s' is not in the root '%s' or is excluded from it." path local-root)))) ;;;### autoload (defun ssh-deploy-upload-handler () @@ -366,7 +382,8 @@ (let ((local-root (file-truename ssh-deploy-root-local)) (remote-root ssh-deploy-root-remote) (path (file-truename buffer-file-name))) - (if (ssh-deploy--file-is-in-path path local-root) + (if (and (ssh-deploy--file-is-in-path path local-root) + (ssh-deploy--file-is-included path)) (progn (let ((revision-path (ssh-deploy--get-revision-path path)) (remote-path (concat remote-root (ssh-deploy--get-relative-path local-root path)))) @@ -390,8 +407,8 @@ (list 0 (format "Remote file '%s' doesn't exist." ,remote-path)))) (lambda(return) (if (= (nth 0 return) 0) - (message (nth 1 return)) - (display-warning "ssh-deploy" (nth 1 return) :warning))))) + (message (nth 1 return)) + (display-warning "ssh-deploy" (nth 1 return) :warning))))) (progn (if (file-exists-p remote-path) (progn @@ -420,10 +437,10 @@ (list 1 (format "External file has '%s' changed, please download or diff." ,remote-path)))) (list 1 "Function ediff-file-same-contents is missing"))) (list 0 (format "Remote file '%s' doesn't exist." ,remote-path)))) - (lambda(return) - (if (= (nth 0 return) 0) - (message (nth 1 return)) - (display-warning "ssh-deploy" (nth 1 return) :warning))))) + (lambda(return) + (if (= (nth 0 return) 0) + (message (nth 1 return)) + (display-warning "ssh-deploy" (nth 1 return) :warning))))) (progn (if (file-exists-p remote-path) (progn @@ -436,7 +453,7 @@ (message "Remote file '%s' has not changed, created base revision." remote-path)) (display-warning "ssh-deploy" (format "External file '%s' has changed, please download or diff." remote-path) :warning))) (display-warning "ssh-deploy" "Function ediff-same-file-contents is missing." :warning))) - (message "Remote file '%s' doesn't exist." remote-path))))))))))))))) + (message "Remote file '%s' doesn't exist." remote-path))))))))))))))) ;;;### autoload (defun ssh-deploy-download-handler () @@ -457,7 +474,8 @@ ;;;### autoload (defun ssh-deploy-diff-handler () "Compare current path with remote host if it is configured for deployment." - (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) (ssh-deploy--is-not-empty-string ssh-deploy-root-remote)) + (if (and (ssh-deploy--is-not-empty-string ssh-deploy-root-local) + (ssh-deploy--is-not-empty-string ssh-deploy-root-remote)) (if (and (ssh-deploy--is-not-empty-string buffer-file-name) (file-exists-p buffer-file-name)) (let ((local-path (file-truename buffer-file-name)) @@ -489,7 +507,8 @@ (defun ssh-deploy-diff (local-root remote-root-string path &optional debug) "Find differences relative to the roots LOCAL-ROOT with REMOTE-ROOT-STRING and the path PATH, DEBUG enables feedback message." (let ((file-or-directory (file-regular-p path))) - (if (ssh-deploy--file-is-in-path path local-root) + (if (and (ssh-deploy--file-is-in-path path local-root) + (ssh-deploy--file-is-included path)) (progn (let ((remote-path (concat remote-root-string (ssh-deploy--get-relative-path local-root path)))) (let ((remote (ssh-deploy--parse-remote remote-path))) @@ -511,12 +530,13 @@ (ztree-diff path command)) (message "ztree-diff is not installed.")))))))) (if debug - (message "Path '%s' is not in the root '%s'" path local-root))))) + (message "Path '%s' is not in the root '%s' or is excluded from it." path local-root))))) ;;;### autoload (defun ssh-deploy-browse-remote (local-root remote-root-string path) "Browse relative to LOCAL-ROOT on REMOTE-ROOT-STRING the path PATH in `dired-mode`." - (if (ssh-deploy--file-is-in-path path local-root) + (if (and (ssh-deploy--file-is-in-path path local-root) + (ssh-deploy--file-is-included path)) (let ((remote-path (concat remote-root-string (ssh-deploy--get-relative-path local-root path)))) (let ((remote-root (ssh-deploy--parse-remote remote-path))) (let ((command (concat "/" (alist-get 'protocol remote-root) ":" (alist-get 'username remote-root) "@" (alist-get 'server remote-root) ":" (alist-get 'path remote-root)))) @@ -551,3 +571,4 @@ (provide 'ssh-deploy) ;;; ssh-deploy.el ends here +