Guard against user saving ediff-meta-diff-buffer

* lisp/vc/ediff-mult.el (ediff-collect-custom-diffs): If the
diff buffer is visiting a file, create a new buffer.  (Bug#3348)

* test/lisp/vc/ediff-mult-tests.el: New test file.
This commit is contained in:
Mauro Aranda 2025-03-09 08:10:17 -03:00
parent ba20f73d8e
commit d01b7c85fe
2 changed files with 62 additions and 1 deletions

View file

@ -1719,7 +1719,14 @@ multifile patches. For `ediff-directory-revisions', we insist that
all marked sessions must be active."
(interactive)
(let ((coding-system-for-read ediff-coding-system-for-read))
(or (ediff-buffer-live-p ediff-meta-diff-buffer)
(unless (and (ediff-buffer-live-p ediff-meta-diff-buffer)
;; We assume `ediff-meta-diff-buffer' doesn't
;; visit any file. But if the user saves the
;; `ediff-meta-diff-buffer' to a file, that
;; assumption isn't right anymore. (Bug#3348)
;; So, if `ediff-meta-diff-buffer' is visiting some
;; file, create a new buffer rather than reusing it.
(not (buffer-file-name ediff-meta-diff-buffer)))
(setq ediff-meta-diff-buffer
(get-buffer-create
(ediff-unique-buffer-name "*Ediff Multifile Diffs" "*"))))

View file

@ -0,0 +1,54 @@
;;; ediff-mult-tests.el --- Tests for ediff-mult.el -*- lexical-binding:t -*-
;; Copyright (C) 2025 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; GNU Emacs is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Code:
(require 'ert)
(require 'ediff-mult)
(ert-deftest ediff-test-bug3348 ()
"After saving `ediff-meta-diff-buffer' to a file, we should not reuse it."
(let ((test-dir
(expand-file-name "bug-3348-testdir" temporary-file-directory)))
(make-directory test-dir t)
(cd test-dir)
(make-directory "dir-a" t)
(make-directory "dir-b" t)
(with-temp-file "dir-a/file"
(insert "aaa\n"))
(with-temp-file "dir-b/file"
(insert "bbb\n"))
(ediff-directories "dir-a" "dir-b" nil)
(switch-to-buffer "*Ediff Session Group Panel*")
(ediff-next-meta-item 1)
(ediff-mark-for-operation-at-pos nil)
(ediff-collect-custom-diffs)
(with-current-buffer "*Ediff Multifile Diffs*"
(write-file "foo.patch"))
(with-temp-file "dir-b/file"
(insert "BBB\n"))
(ediff-collect-custom-diffs)
(should-not (equal ediff-meta-diff-buffer (get-buffer "foo.patch")))))