Subject: bug#53927: 27.2; shell-mode dir tracking falls out of sync after popd in remote buffers

From: Michael Albinus <[email-masked]>
Date: Tue, 15 Feb 2022 14:39:37 +0100

Dan McCarthy <[email-masked]> writes:

Hi Dan,

> Create a remote shell-mode buffer with C-u M-x shell, using bash as
> the
> remote shell. pushd into another directory, then popd
> back. default-directory and shell-dirstack still have the other
> directory even though the popd took effect in the remote process.
>
> The problem seems to be that shell-prefixed-directory-name returns a
> string like
> "/ssh:dan@solstice:/ssh:dan@solstice:/home/dan/Documents/",
> doubling the remote prefix.
>
> Local shell-mode buffers do not have the problem.

Thanks for the bug report, I could reproduce it locally. The appended
patch fixes this for me, could you please check?

Eli, it is a very simple patch. Any chance to commit it to the emacs-28
branch? Otherwise, I would commit it to master, but we need a marker to
merge it back to the emacs-28 branch after the Emacs 28.1 release.

Best regards, Michael.

diff --git a/lisp/shell.el b/lisp/shell.el
index c0a82bca18..6198214abe 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -942,7 +942,7 @@ shell-prefixed-directory-name
       dir
     (if (file-name-absolute-p dir)
 	;; The name is absolute, so prepend the prefix.
-	(concat comint-file-name-prefix dir)
+	(concat comint-file-name-prefix (file-local-name dir))
       ;; For relative name we assume default-directory already has the prefix.
       (expand-file-name dir))))