Subject: bug#39280: 27.0.60; wdired-get-filename ignores first argument

From: Tino Calancha <[email-masked]>
Date: Sat, 25 Jan 2020 21:05:05 +0100

emacs -Q /tmp
M-! touch foo RET
g
j foo RET
C-x C-q
M-: (wdired-get-filename 'local t) RET
=> "/tmp/foo"
;; Expected: "foo"

--8<-----------------------------cut here---------------start------------->8---
commit 5f7e8975e741298718a4e05aa674873207cb56a6
Author: Tino Calancha <[email-masked]>
Date:   Sat Jan 25 21:03:53 2020 +0100

    Fix bug in wdired-get-filename
    
    * lisp/wdired.el (wdired-get-filename):
    Acknowledge the first argument.
    * test/lisp/wdired-tests.el (wdired-test-bug39280): Add test.

diff --git a/lisp/wdired.el b/lisp/wdired.el
index d470e0a21b..23dc4b9ef5 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -344,7 +344,7 @@ wdired-get-filename
 	;; Don't unquote the old name, it wasn't quoted in the first place
         (and file (setq file (wdired-normalize-filename file (not old)))))
       (if (or no-dir old)
-	  file
+	  (if no-dir (file-relative-name file) file)
 	(and file (> (length file) 0)
              (concat (dired-current-directory) file))))))
 
diff --git a/test/lisp/wdired-tests.el b/test/lisp/wdired-tests.el
index baa547758e..3d5f504205 100644
--- a/test/lisp/wdired-tests.el
+++ b/test/lisp/wdired-tests.el
@@ -176,6 +176,22 @@ wdired-test-bug34915
       (server-force-delete)
       (delete-directory test-dir t))))
 
+(ert-deftest wdired-test-bug39280 ()
+  "Test for https://debbugs.gnu.org/39280."
+  (let* ((test-dir (make-temp-file "test-dir" 'dir))
+         (fname "foo")
+         (full-fname (expand-file-name fname test-dir)))
+    (make-empty-file full-fname)
+    (let ((buf (find-file-noselect test-dir)))
+      (unwind-protect
+	  (with-current-buffer buf
+	    (dired-toggle-read-only)
+            (dolist (old '(t nil))
+              (should (equal fname (wdired-get-filename 'nodir old)))
+              (should (equal full-fname (wdired-get-filename nil old))))
+	    (wdired-finish-edit))
+	(if buf (kill-buffer buf))
+	(delete-directory test-dir t)))))
 
 (provide 'wdired-tests)
 ;;; wdired-tests.el ends here
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 27.0.60 (build 24, x86_64-pc-linux-gnu, GTK+ Version 3.24.5)
 of 2020-01-25 built on calancha-pc.dy.bbexcite.jp
Repository revision: baca81e64141aed076fe088e7160f6e0d4a51c68
Repository branch: emacs-27
Windowing system distributor 'The X.Org Foundation', version 11.0.12004000
System Description: Debian GNU/Linux 10 (buster)

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
(Shell command succeeded with no output)
Press C-c C-c when finished or C-c ESC to abort changes
"/tmp/foo"
Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND GPM DBUS GSETTINGS GLIB NOTIFY INOTIFY
ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD PDUMPER
LCMS2 GMP