Fix vc-hg-diff arguments to diff vs empty tree

* lisp/vc/vc-hg.el (vc-hg-diff): Fix behavior according to
backend function specification (bug#81527).
* test/lisp/vc/vc-hg-tests.el (vc-hg-diff-revision-arguments):
New test.
This commit is contained in:
Aaron L. Zeng 2026-07-31 15:01:19 -04:00 committed by Sean Whitton
parent d828a19fdc
commit afda8c2779
2 changed files with 18 additions and 1 deletions

View file

@ -567,7 +567,7 @@ This requires hg 4.4 or later, for the \"-L\" option of \"hg log\"."
(when (and (not newvers) (member oldvers (list working ".")))
(setq oldvers nil))
(when (and newvers (not oldvers))
(setq oldvers working))
(setq oldvers "null"))
(apply #'vc-hg-command
(or buffer "*vc-diff*")
(if async 'async 1)

View file

@ -88,4 +88,21 @@ R foo"
("foo2" added #s(vc-hg-extra-fileinfo renamed-from "foo"))
("bar2" added #s(vc-hg-extra-fileinfo renamed-from "bar")))))
(ert-deftest vc-hg-diff-revision-arguments ()
"Test `vc-hg-diff' revision arguments."
(cl-letf (((symbol-function 'vc-hg-command) #'list)
(vc-hg-diff-switches t))
;; REV1 REV2 both nil: diff file against working revision
(should (equal (vc-hg-diff '("foo") nil nil)
'("*vc-diff*" 1 ("foo") "diff")))
;; REV1 nil and REV2 non-nil: diff REV2 against empty tree
(should (equal (vc-hg-diff '("foo") nil "22222")
'("*vc-diff*" 1 ("foo") "diff" "-r" "null" "-r" "22222")))
;; REV1 non-nil and REV2 nil: diff working copy against older revision
(should (equal (vc-hg-diff '("foo") "11111" nil)
'("*vc-diff*" 1 ("foo") "diff" "-r" "11111")))
;; REV1 REV2 both non-nil: diff two revisions
(should (equal (vc-hg-diff '("foo") "11111" "22222")
'("*vc-diff*" 1 ("foo") "diff" "-r" "11111" "-r" "22222")))))
;;; vc-hg-tests.el ends here