branch: externals/vc-jj
commit 60726917bc589dd5a3371c1059ade9fc20711e31
Author: Kristoffer Balintona <[email protected]>
Commit: Kristoffer Balintona <[email protected]>

    fix: Erase *vc-diff* buffer before using it
    
    *vc-diff* may not be erased upon new invocations of `vc-jj-diff`.
    Ensure its contents are erased as needed by calling
    `vc-jj--command-dispatched` when the current buffer is not the
    *vc-diff* buffer.
    
    Fixes #152
---
 NEWS.org |  2 ++
 vc-jj.el | 17 ++++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index f4bc93cc44..9bf3da9e81 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -12,6 +12,8 @@
 
 *** Fixed
 
+- Fixed a bug where the contents of ​*vc-diff​* were not erased prior to 
invocations of ~vc-jj-diff~.
+
 ** [[https://codeberg.org/emacs-jj-vc/vc-jj.el/compare/v0.4...v0.5][0.5]] - 
2025-12-21
 
 *** Added
diff --git a/vc-jj.el b/vc-jj.el
index 00e442af19..9c7c60c190 100644
--- a/vc-jj.el
+++ b/vc-jj.el
@@ -1068,9 +1068,20 @@ unsupported."
                         (list "-f" rev1 "-t" rev2))
                       (vc-switches 'jj 'diff)
                       (list "--") files)))
-    (with-current-buffer buffer
-      (prog1
-          (apply #'vc-jj--command-dispatched buffer 0 nil "diff" args)
+    ;; Match `vc-git-diff' by returning the value of
+    ;; `vc-jj--command-dispatched'.
+    ;;
+    ;; Also ensure that (vc-jj--command-dispatched BUFFER ...) is
+    ;; called when BUFFER is not the current buffer.  Otherwise,
+    ;; BUFFER may accumulate content from previous invocations of
+    ;; `vc-jj-diff', because `vc-do-command' (called internally by
+    ;; `vc-jj--command-dispatched') only erases BUFFER when BUFFER is
+    ;; not the current buffer.  See
+    ;; https://codeberg.org/emacs-jj-vc/vc-jj.el/issues/152 for more
+    ;; information.
+    (prog1
+        (apply #'vc-jj--command-dispatched buffer 0 nil "diff" args)
+      (with-current-buffer buffer
         (ansi-color-filter-region (point-min) (point-max))))))
 
 ;;;; revision-completion-table

Reply via email to