aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Kangas2025-03-03 18:37:43 +0100
committerStefan Kangas2025-03-03 18:57:17 +0100
commit10abb87f0519b3d53d6b7078703d3a0120e3aaa8 (patch)
tree183ea373683714b48b7ee19e173a04b9218a1b6a /test
parenteeda2a8ab1f06da5b51dc98e57ae8b4a4faa1f72 (diff)
downloademacs-10abb87f0519b3d53d6b7078703d3a0120e3aaa8.tar.gz
emacs-10abb87f0519b3d53d6b7078703d3a0120e3aaa8.zip
Fix fontification outside hunks in Git patches
* lisp/vc/diff-mode.el (diff-font-lock-keywords): Don't fontify lines in Git patches starting with + or - as added/removed, if they are either before the first hunk, or in the email signature. (Bug#75884) (diff-buffer-type): Move definition up. (diff--indicator-added-re, diff--indicator-removed-re): New variables. (diff--git-preamble-end, diff--git-footer-start) (diff--indicator-matcher-helper, diff--indicator-added-matcher) (diff--indicator-removed-matcher): New functions. * test/lisp/vc/diff-mode-tests.el (diff-mode-test-git-patch) (diff-mode-test-git-patch/before-first-hunk) (diff-mode-test-git-patch/signature): New tests. * test/lisp/vc/diff-mode-resources/git.patch: New file.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/vc/diff-mode-resources/git.patch51
-rw-r--r--test/lisp/vc/diff-mode-tests.el40
2 files changed, 91 insertions, 0 deletions
diff --git a/test/lisp/vc/diff-mode-resources/git.patch b/test/lisp/vc/diff-mode-resources/git.patch
new file mode 100644
index 00000000000..05ec90d105c
--- /dev/null
+++ b/test/lisp/vc/diff-mode-resources/git.patch
@@ -0,0 +1,51 @@
1From 1234567890abcdef1234567890abcdef12345678 Mon Sep 17 00:00:00 2001
2From: Alyssa P. Hacker <alyssa.p.hacker@example.com>
3Date: Sun, 3 Mar 2025 10:30:00 -0400
4Subject: [PATCH] Subtle bug fixes and slight improvements
5
6- This is not a removed line
7+ This is not an added line
8
9---
10 src/main.py | 10 +++++-----
11 1 file changed, 5 insertions(+), 5 deletions(-)
12
13diff --git a/src/main.py b/src/main.py
14index 9f6c5fe43e47eab441232e54456c5c2b06297b65..7b3f91a8b4ed923c8f43183276e3ab36fe04f6c9 100644
15--- a/src/main.py
16+++ b/src/main.py
17@@ -2,25 +2,24 @@
18
19 def main():
20 # Initialize the magic number generator
21- magic_number = 42
22- print("Magic number: ", magic_number)
23
24- # TODO: Fix the infinite loop
25- while True:
26- print("This loop will never end")
27+ magic_number = 73 # After reconsidering, 73 seems more appropriate
28+ print("Updated magic number: ", magic_number)
29
30+ # The infinite loop was probably not the best approach
31+ # while True:
32+ # print("This loop will never end.")
33
34 # This part of the code handles other important tasks
35 print("Processing other tasks...")
36
37 # Error handling has been updated for clarity
38- if not fixed_it_yet:
39- print("ERROR: Still broken!")
40+ if not fixed_it_yet: # This should be fine now
41+ print("ERROR: No longer an issue.")
42
43 # Exiting the function on a positive note
44- print("Goodbye, cruel world!")
45+ print("Goodbye, world!")
46
47 if __name__ == "__main__":
48 main()
49
50--
512.40.0
diff --git a/test/lisp/vc/diff-mode-tests.el b/test/lisp/vc/diff-mode-tests.el
index cd3f613f532..bbd66824e48 100644
--- a/test/lisp/vc/diff-mode-tests.el
+++ b/test/lisp/vc/diff-mode-tests.el
@@ -557,5 +557,45 @@ baz"))))
557+1 557+1
558"))))) 558")))))
559 559
560(ert-deftest diff-mode-test-git-patch ()
561 (let ((file (ert-resource-file "git.patch")))
562 (with-temp-buffer
563 (insert-file-contents file)
564 (diff-mode)
565 (font-lock-ensure)
566 (goto-char (point-min))
567 (re-search-forward "magic_number = 42")
568 (should (eq (get-text-property (match-beginning 0) 'face)
569 'diff-removed))
570 (re-search-forward "magic_number = 73")
571 (should (eq (get-text-property (match-beginning 0) 'face)
572 'diff-added)))))
573
574(ert-deftest diff-mode-test-git-patch/before-first-hunk ()
575 (let ((file (ert-resource-file "git.patch")))
576 (with-temp-buffer
577 (insert-file-contents file)
578 (diff-mode)
579 (font-lock-ensure)
580 (goto-char (point-min))
581 (re-search-forward "This is not a removed line")
582 (should (eq (get-text-property (match-beginning 0) 'face)
583 'diff-context))
584 (re-search-forward "This is not an added line")
585 (font-lock-ensure)
586 (should (eq (get-text-property (match-beginning 0) 'face)
587 'diff-context)))))
588
589(ert-deftest diff-mode-test-git-patch/signature ()
590 (let ((file (ert-resource-file "git.patch")))
591 (with-temp-buffer
592 (insert-file-contents file)
593 (diff-mode)
594 (font-lock-ensure)
595 (goto-char (point-max))
596 (re-search-backward "^-- $")
597 (should (eq (get-text-property (match-beginning 0) 'face)
598 'diff-context)))))
599
560(provide 'diff-mode-tests) 600(provide 'diff-mode-tests)
561;;; diff-mode-tests.el ends here 601;;; diff-mode-tests.el ends here