emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ssh-deploy db73e5b 083/133: Started in new function for


From: Stefan Monnier
Subject: [elpa] externals/ssh-deploy db73e5b 083/133: Started in new function for detecting remote changes that should be testable by unit tests
Date: Sat, 27 Mar 2021 14:48:48 -0400 (EDT)

branch: externals/ssh-deploy
commit db73e5bd7293cd8c998f010f44e33b2eeaa494de
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Started in new function for detecting remote changes that should be 
testable by unit tests
---
 ssh-deploy-test.el | 52 +++++++++++++++++++++++++---------------------------
 ssh-deploy.el      | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 27 deletions(-)

diff --git a/ssh-deploy-test.el b/ssh-deploy-test.el
index d3ba791..44c7a8b 100644
--- a/ssh-deploy-test.el
+++ b/ssh-deploy-test.el
@@ -65,7 +65,6 @@
            (ssh-deploy-root-local directory-a)
            (ssh-deploy-root-remote directory-b)
            (ssh-deploy-on-explicit-save 0)
-           (ssh-deploy-verbose 0)
            (ssh-deploy-debug 0)
            (ssh-deploy-async async)
            (ssh-deploy-async-with-threads async-with-threads))
@@ -74,7 +73,6 @@
       (when (and ssh-deploy-root-local
                  ssh-deploy-root-remote
                  ssh-deploy-on-explicit-save
-                 ssh-deploy-verbose
                  ssh-deploy-debug
                  ssh-deploy-async
                  ssh-deploy-async-with-threads)
@@ -123,7 +121,6 @@
            (ssh-deploy-root-local directory-a)
            (ssh-deploy-root-remote directory-b)
            (ssh-deploy-on-explicit-save 0)
-           (ssh-deploy-verbose 0)
            (ssh-deploy-debug 0)
            (ssh-deploy-async async)
            (ssh-deploy-async-with-threads async-with-threads))
@@ -132,7 +129,6 @@
       (when (and ssh-deploy-root-local
                  ssh-deploy-root-remote
                  ssh-deploy-on-explicit-save
-                 ssh-deploy-verbose
                  ssh-deploy-debug
                  ssh-deploy-async
                  ssh-deploy-async-with-threads)
@@ -201,7 +197,6 @@
            (ssh-deploy-root-local directory-a)
            (ssh-deploy-root-remote directory-b)
            (ssh-deploy-on-explicit-save 1)
-           (ssh-deploy-verbose 0)
            (ssh-deploy-debug 0)
            (ssh-deploy-async async)
            (ssh-deploy-async-with-threads async-with-threads))
@@ -210,7 +205,6 @@
       (when (and ssh-deploy-root-local
                  ssh-deploy-root-remote
                  ssh-deploy-on-explicit-save
-                 ssh-deploy-verbose
                  ssh-deploy-debug
                  ssh-deploy-async
                  ssh-deploy-async-with-threads)
@@ -272,27 +266,31 @@
 
 (defun ssh-deploy-test ()
   "Run test for plug-in."
-  (if (fboundp 'async-start)
-      (message "\nNOTE: Running tests for async.el as well since it's 
loaded\n")
-    (message "\nNOTE: Skipping tests for async.el since it's not loaded\n"))
-  (ssh-deploy-test--get-revision-path)
-  (ssh-deploy-test--file-is-in-path)
-  (ssh-deploy-test--is-not-empty-string)
-
-  (ssh-deploy-test--upload 0 0)
-  (when (fboundp 'async-start)
-    (ssh-deploy-test--upload 1 0))
-  (ssh-deploy-test--upload 1 1)
-
-  (ssh-deploy-test--download 0 0)
-  (when (fboundp 'async-start)
-    (ssh-deploy-test--download 1 0))
-  (ssh-deploy-test--download 1 1)
-
-  (ssh-deploy-test--rename-and-delete 0 0)
-  (when (fboundp 'async-start)
-    (ssh-deploy-test--rename-and-delete 1 0))
-  (ssh-deploy-test--rename-and-delete 1 1))
+  (let ((ssh-deploy-verbose 1)
+        (ssh-deploy-debug 1))
+    (when (and ssh-deploy-verbose
+               ssh-deploy-debug)
+      (if (fboundp 'async-start)
+          (message "\nNOTE: Running tests for async.el as well since it's 
loaded\n")
+        (message "\nNOTE: Skipping tests for async.el since it's not 
loaded\n"))
+      (ssh-deploy-test--get-revision-path)
+      (ssh-deploy-test--file-is-in-path)
+      (ssh-deploy-test--is-not-empty-string)
+
+      (ssh-deploy-test--upload 0 0)
+      (when (fboundp 'async-start)
+        (ssh-deploy-test--upload 1 0))
+      (ssh-deploy-test--upload 1 1)
+
+      (ssh-deploy-test--download 0 0)
+      (when (fboundp 'async-start)
+        (ssh-deploy-test--download 1 0))
+      (ssh-deploy-test--download 1 1)
+
+      (ssh-deploy-test--rename-and-delete 0 0)
+      (when (fboundp 'async-start)
+        (ssh-deploy-test--rename-and-delete 1 0))
+      (ssh-deploy-test--rename-and-delete 1 1))))
 
 (ssh-deploy-test)
 
diff --git a/ssh-deploy.el b/ssh-deploy.el
index fa2d436..691d891 100644
--- a/ssh-deploy.el
+++ b/ssh-deploy.el
@@ -731,6 +731,47 @@
         (when (or (> (length (nth 4 diff)) 0) (> (length (nth 5 diff)) 0) (> 
(length (nth 7 diff)) 0))
           (ssh-deploy--diff-directories-present diff directory-a directory-b 
on-explicit-save debug async async-with-threads revision-folder remote-changes 
exclude-list))))))
 
+;; TODO Should optimize and unit-test this function
+(defun ssh-deploy--remote-changes-data (path-local &optional root-local 
root-remote revision-folder exclude-list)
+  "Check if a local revision for PATH-LOCAL on ROOT-LOCAL and if remote file 
has changed on ROOT-REMOTE, check for copies in REVISION-FOLDER and skip if 
path is in EXCLUDE-LIST.  Should only return status-code and message."
+  (let ((root-local (or root-local ssh-deploy-root-local))
+        (root-remote (or root-remote ssh-deploy-root-remote))
+        (exclude-list (or exclude-list ssh-deploy-exclude-list)))
+
+    ;; Is the file inside the local-root and should it not be excluded?
+    (if (and (ssh-deploy--file-is-in-path-p path-local root-local)
+             (ssh-deploy--file-is-included-p path-local exclude-list))
+        (let* ((revision-folder (or revision-folder 
ssh-deploy-revision-folder))
+               (revision-path (ssh-deploy--get-revision-path path-local 
revision-folder))
+               (path-remote (expand-file-name (ssh-deploy--get-relative-path 
root-local path-local) root-remote)))
+
+          ;; Is the file a regular file?
+          (if (not (file-directory-p path-local))
+
+              ;; Does a local revision of the file exist?
+              (if (file-exists-p revision-path)
+
+                  ;; Local revision exist
+
+                  (if (file-exists-p path-remote)
+                      (if (ediff-same-file-contents revision-path path-remote)
+                          (list 0 (format "Remote file '%s' has not changed." 
path-remote) path-local)
+                        (list 1 (format "Remote file '%s' has changed please 
download or diff." path-remote) path-local))
+                    (list 0 (format "Remote file '%s' doesn't exist." 
path-remote) path-local))
+
+                ;; Does remote file exist?
+                (if (file-exists-p path-remote)
+                    (if (ediff-same-file-contents path-local path-remote)
+                        (list 0 (format "Remote file '%s' has not changed. 
SHOULD create base revision." path-remote) path-local)
+                      (list 1 (format "Remote file '%s' has changed please 
download or diff." path-remote) path-local))
+                  (list 0 (format "Remote file '%s' doesn't exist." 
path-remote) path-local)))
+
+            ;; File is a directory
+            (list 0 (format "File %s is a directory, ignoring remote changes 
check." path-local) path-local)))
+
+      ;; File is not inside root or is excluded from it
+      (list 0 (format "File %s is not in root or is excluded from it." 
path-local)))))
+
 ;;;###autoload
 (defun ssh-deploy-remote-changes (path-local &optional root-local root-remote 
async revision-folder exclude-list async-with-threads)
   "Check if a local revision for PATH-LOCAL on ROOT-LOCAL and if remote file 
has changed on ROOT-REMOTE, do it optionally asynchronously if ASYNC is true, 
check for copies in REVISION-FOLDER and skip if path is in EXCLUDE-LIST.  Use 
multi-threading if ASYNC-WITH-THREADS is above zero."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]