]> git.eshelyaron.com Git - emacs.git/commitdiff
epatch: Save right backups in Git multipatches
authorTino Calancha <tino.calancha@gmail.com>
Tue, 21 Mar 2017 08:25:55 +0000 (17:25 +0900)
committerTino Calancha <tino.calancha@gmail.com>
Tue, 21 Mar 2017 08:25:55 +0000 (17:25 +0900)
Multipatches on N Git files save wrong backups for
N-1 files; only the last one has a correct backup (Bug#26084).
* lisp/vc/diff-mode.el (diff-file-junk-re): Add 'Prereq: '
* lisp/vc/ediff-ptch.el (ediff-map-patch-buffer): Use 'diff-file-junk-re'.
* test/lisp/vc/ediff-ptch-tests.el (ediff-ptch-test-bug25010):
Rename from ibuffer-test-bug25010.
(ediff-ptch-test-bug26084): New test.

lisp/vc/diff-mode.el
lisp/vc/ediff-ptch.el
test/lisp/vc/ediff-ptch-tests.el

index 31c33e6a720d3e7cb1bec572b1aae548fdd7a403..aa8d77882ec26e245d74a494ddc2854904bf1eef 100644 (file)
@@ -504,7 +504,7 @@ See http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01990.html")
 ;; "index ", "old mode", "new mode", "new file mode" and
 ;; "deleted file mode" are output by git-diff.
 (defconst diff-file-junk-re
-  (concat "Index: \\|=\\{20,\\}\\|" ; SVN
+  (concat "Index: \\|Prereq: \\|=\\{20,\\}\\|" ; SVN
           "diff \\|index \\|\\(?:deleted file\\|new\\(?: file\\)?\\|old\\) mode\\|=== modified file"))
 
 ;; If point is in a diff header, then return beginning
index 9d2ec51b596731da115161a32388ed5d0b532f53..36aebf4aed1d2025b89dc0aa18967a837d9a41a1 100644 (file)
@@ -25,6 +25,8 @@
 ;;; Code:
 
 
+(require 'diff-mode) ; For `diff-file-junk-re'.
+
 (provide 'ediff-ptch)
 
 (defgroup ediff-ptch nil
@@ -225,14 +227,11 @@ program."
                        (if (and beg2 end2)
                            (buffer-substring beg2 end2)
                          "/dev/null")))
-           ;; check for any `Index:' or `Prereq:' lines, but don't use them
-           (if (re-search-backward "^Index:" mark1-end 'noerror)
-               (move-marker mark2 (match-beginning 0)))
-           (if (re-search-backward "^Prereq:" mark1-end 'noerror)
-               (move-marker mark2 (match-beginning 0)))
-
+            ;; Remove file junk (Bug#26084).
+            (while (re-search-backward
+                    (concat "^" diff-file-junk-re) mark1-end t)
+                (move-marker mark2 (match-beginning 0)))
            (goto-char mark2-end)
-
            (if filenames
                (setq patch-map
                      (cons (ediff-make-new-meta-list-element
index 912c6b1e8182d157ba6468e612a38aabdef9d5cb..9aacb6bd20f3da723632f292940f893764533066 100644 (file)
@@ -22,7 +22,7 @@
 (require 'ert)
 (require 'ediff-ptch)
 
-(ert-deftest ibuffer-test-bug25010 ()
+(ert-deftest ediff-ptch-test-bug25010 ()
   "Test for http://debbugs.gnu.org/25010 ."
   (with-temp-buffer
     (insert "diff --git a/lisp/vc/ediff-ptch.el b/lisp/vc/ediff-ptch.el
@@ -38,5 +38,62 @@ index 6a07f80..6e8e947 100644
              (match-string 1))))
       (should-not (string-suffix-p "@@" filename)))))
 
+
+(ert-deftest ediff-ptch-test-bug26084 ()
+  "Test for http://debbugs.gnu.org/26084 ."
+  (let* ((tmpdir temporary-file-directory)
+         (foo (expand-file-name "foo" tmpdir))
+         (patch (expand-file-name "foo.diff" tmpdir))
+         (qux (expand-file-name "qux.txt" foo))
+         (bar (expand-file-name "bar.txt" foo))
+         (cmd "
+mkdir -p foo
+cd foo
+echo 'qux here' > qux.txt
+echo 'bar here' > bar.txt
+git init
+git add . && git commit -m 'Test repository.'
+echo 'foo here' > qux.txt
+echo 'foo here' > bar.txt
+git diff > ../foo.diff
+git reset --hard HEAD
+"))
+    (setq default-directory tmpdir)
+    (call-process-shell-command cmd)
+    (find-file patch)
+    (unwind-protect
+        (let* ((info
+                (progn (ediff-map-patch-buffer (current-buffer)) ediff-patch-map))
+               (patch1
+                (buffer-substring-no-properties
+                 (car (nth 3 (car info)))
+                 (car (nth 4 (car info)))))
+               (patch2
+                (buffer-substring-no-properties
+                 (car (nth 3 (cadr info)))
+                 (car (nth 4 (cadr info))))))
+          ;; Apply both patches.
+          (dolist (x (list (cons patch1 bar) (cons patch2 qux)))
+            (with-temp-buffer
+              (insert (car x))
+              (call-shell-region (point-min)
+                                 (point-max)
+                                 (format "%s %s %s %s"
+                                         ediff-patch-program
+                                         ediff-patch-options
+                                         ediff-backup-specs
+                                         (cdr x)))))
+          ;; Check backup files were saved correctly.
+          (dolist (x (list qux bar))
+            (should-not (string= (with-temp-buffer
+                                   (insert-file-contents x)
+                                   (buffer-string))
+                                 (with-temp-buffer
+                                   (insert-file-contents (concat x ediff-backup-extension))
+                                   (buffer-string))))))
+      (delete-directory foo 'recursive)
+      (delete-file patch))))
+
+
 (provide 'ediff-ptch-tests)
 ;;; ediff-ptch-tests.el ends here