From d6f430cb88bc4c395c1ce9f405a938699491b517 Mon Sep 17 00:00:00 2001
From: Michael Albinus <michael.albinus@gmx.de>
Date: Mon, 4 Feb 2019 16:03:43 +0100
Subject: [PATCH] Fix Bug#34196

* lisp/net/tramp.el (tramp-process-actions): Disable `global-auto-revert-mode'
temporarily.  (Bug#34196)
---
 lisp/net/tramp.el | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index d000bbe3d65..82d2e5a4d34 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -4060,17 +4060,23 @@ performed successfully.  Any other value means an error."
   (save-restriction
     (with-tramp-progress-reporter
 	proc 3 "Waiting for prompts from remote shell"
-      (let (exit)
-	(if timeout
-	    (with-timeout (timeout (setq exit 'timeout))
+      ;; `global-auto-revert-mode' could activate remote operations
+      ;; while we aren't ready.  We disable it temporarily.
+      (let ((garm (bound-and-true-p global-auto-revert-mode))
+	    exit)
+	(when garm (global-auto-revert-mode -1))
+	(unwind-protect
+	    (if timeout
+		(with-timeout (timeout (setq exit 'timeout))
+		  (while (not exit)
+		    (setq exit
+			  (catch 'tramp-action
+			    (tramp-process-one-action proc vec actions)))))
 	      (while (not exit)
 		(setq exit
 		      (catch 'tramp-action
 			(tramp-process-one-action proc vec actions)))))
-	  (while (not exit)
-	    (setq exit
-		  (catch 'tramp-action
-		    (tramp-process-one-action proc vec actions)))))
+	  (when garm (global-auto-revert-mode)))
 	(with-current-buffer (tramp-get-connection-buffer vec)
 	  (widen)
 	  (tramp-message vec 6 "\n%s" (buffer-string)))
-- 
2.39.5