diff options
| author | Sean Whitton | 2025-08-12 20:35:49 +0100 |
|---|---|---|
| committer | Sean Whitton | 2025-08-12 20:35:49 +0100 |
| commit | bb1c737531c8d2e78a77b29ddd2db5b89c9c6810 (patch) | |
| tree | 23e7efbdcc5c83f2a36ec221a738adf7fac6cf06 | |
| parent | e48592ef3bc0734bcc4655cc3863f35a30e14437 (diff) | |
| download | emacs-bb1c737531c8d2e78a77b29ddd2db5b89c9c6810.tar.gz emacs-bb1c737531c8d2e78a77b29ddd2db5b89c9c6810.zip | |
vc-test--other-working-trees: Export env vars so Git finds an author
* test/lisp/vc/vc-tests/vc-tests.el
(vc-test--with-author-identity): New macro, factored out of
vc-test--version-diff.
(vc-test--version-diff, vc-test--other-working-trees): Use it.
| -rw-r--r-- | test/lisp/vc/vc-tests/vc-tests.el | 322 |
1 files changed, 164 insertions, 158 deletions
diff --git a/test/lisp/vc/vc-tests/vc-tests.el b/test/lisp/vc/vc-tests/vc-tests.el index ba131502b9b..81789814350 100644 --- a/test/lisp/vc/vc-tests/vc-tests.el +++ b/test/lisp/vc/vc-tests/vc-tests.el | |||
| @@ -584,6 +584,22 @@ This checks also `vc-backend' and `vc-responsible-backend'." | |||
| 584 | (ignore-errors | 584 | (ignore-errors |
| 585 | (run-hooks 'vc-test--cleanup-hook)))))) | 585 | (run-hooks 'vc-test--cleanup-hook)))))) |
| 586 | 586 | ||
| 587 | (defmacro vc-test--with-author-identity (backend &rest body) | ||
| 588 | (declare (indent 1) (debug t)) | ||
| 589 | `(let ((process-environment process-environment)) | ||
| 590 | ;; git tries various approaches to guess a user name and email, | ||
| 591 | ;; which can fail depending on how the system is configured. | ||
| 592 | ;; Eg if the user account has no GECOS, git commit can fail with | ||
| 593 | ;; status 128 "fatal: empty ident name". | ||
| 594 | (when (memq ,backend '(Bzr Git)) | ||
| 595 | (setq process-environment (cons "EMAIL=john@doe.ee" | ||
| 596 | process-environment))) | ||
| 597 | (when (eq ,backend 'Git) | ||
| 598 | (setq process-environment (append '("GIT_AUTHOR_NAME=A" | ||
| 599 | "GIT_COMMITTER_NAME=C") | ||
| 600 | process-environment))) | ||
| 601 | ,@body)) | ||
| 602 | |||
| 587 | (declare-function log-edit-done "vc/log-edit") | 603 | (declare-function log-edit-done "vc/log-edit") |
| 588 | 604 | ||
| 589 | (defun vc-test--version-diff (backend) | 605 | (defun vc-test--version-diff (backend) |
| @@ -595,72 +611,62 @@ This checks also `vc-backend' and `vc-responsible-backend'." | |||
| 595 | (file-truename | 611 | (file-truename |
| 596 | (expand-file-name | 612 | (expand-file-name |
| 597 | (make-temp-name "vc-test") temporary-file-directory)))) | 613 | (make-temp-name "vc-test") temporary-file-directory)))) |
| 598 | (process-environment process-environment) | ||
| 599 | vc-test--cleanup-hook) | 614 | vc-test--cleanup-hook) |
| 600 | (vc--fix-home-for-bzr tempdir) | 615 | (vc--fix-home-for-bzr tempdir) |
| 601 | ;; git tries various approaches to guess a user name and email, | 616 | (vc-test--with-author-identity backend |
| 602 | ;; which can fail depending on how the system is configured. | 617 | |
| 603 | ;; Eg if the user account has no GECOS, git commit can fail with | 618 | (unwind-protect |
| 604 | ;; status 128 "fatal: empty ident name". | 619 | (progn |
| 605 | (when (memq backend '(Bzr Git)) | 620 | ;; Cleanup. |
| 606 | (setq process-environment (cons "EMAIL=john@doe.ee" | 621 | (add-hook |
| 607 | process-environment))) | 622 | 'vc-test--cleanup-hook |
| 608 | (if (eq backend 'Git) | 623 | (let ((dir default-directory)) |
| 609 | (setq process-environment (append '("GIT_AUTHOR_NAME=A" | 624 | (lambda () (delete-directory dir 'recursive)))) |
| 610 | "GIT_COMMITTER_NAME=C") | 625 | |
| 611 | process-environment))) | 626 | ;; Create empty repository. Check repository checkout model. |
| 612 | (unwind-protect | 627 | (make-directory default-directory) |
| 613 | (progn | 628 | (vc-test--create-repo-function backend) |
| 614 | ;; Cleanup. | 629 | |
| 615 | (add-hook | 630 | (let* ((tmp-name (expand-file-name "foo" default-directory)) |
| 616 | 'vc-test--cleanup-hook | 631 | (files (list (file-name-nondirectory tmp-name)))) |
| 617 | (let ((dir default-directory)) | 632 | ;; Write and register a new file. |
| 618 | (lambda () (delete-directory dir 'recursive)))) | 633 | (write-region "originaltext" nil tmp-name nil 'nomessage) |
| 619 | 634 | (vc-register (list backend files)) | |
| 620 | ;; Create empty repository. Check repository checkout model. | 635 | |
| 621 | (make-directory default-directory) | 636 | (let ((buff (find-file tmp-name))) |
| 622 | (vc-test--create-repo-function backend) | 637 | (with-current-buffer buff |
| 623 | 638 | (progn | |
| 624 | (let* ((tmp-name (expand-file-name "foo" default-directory)) | 639 | ;; Optionally checkout file. |
| 625 | (files (list (file-name-nondirectory tmp-name)))) | 640 | (when (memq backend '(RCS CVS SCCS)) |
| 626 | ;; Write and register a new file. | 641 | (vc-checkout tmp-name)) |
| 627 | (write-region "originaltext" nil tmp-name nil 'nomessage) | 642 | |
| 628 | (vc-register (list backend files)) | 643 | ;; Checkin file. |
| 629 | 644 | (vc-checkin files backend) | |
| 630 | (let ((buff (find-file tmp-name))) | 645 | (insert "Testing vc-version-diff") |
| 631 | (with-current-buffer buff | 646 | (let (vc-async-checkin) |
| 647 | (log-edit-done))))) | ||
| 648 | |||
| 649 | ;; Modify file content. | ||
| 650 | (when (memq backend '(RCS CVS SCCS)) | ||
| 651 | (vc-checkout tmp-name)) | ||
| 652 | (write-region "updatedtext" nil tmp-name nil 'nomessage) | ||
| 653 | |||
| 654 | ;; Check version diff. | ||
| 655 | (vc-version-diff files nil nil) | ||
| 656 | (if (eq backend 'Bzr) | ||
| 657 | (sleep-for 1)) | ||
| 658 | (should (bufferp (get-buffer "*vc-diff*"))) | ||
| 659 | |||
| 660 | (with-current-buffer "*vc-diff*" | ||
| 632 | (progn | 661 | (progn |
| 633 | ;; Optionally checkout file. | 662 | (let ((rawtext (buffer-substring-no-properties (point-min) |
| 634 | (when (memq backend '(RCS CVS SCCS)) | 663 | (point-max)))) |
| 635 | (vc-checkout tmp-name)) | 664 | (should (string-search "-originaltext" rawtext)) |
| 636 | 665 | (should (string-search "+updatedtext" rawtext))))))) | |
| 637 | ;; Checkin file. | ||
| 638 | (vc-checkin files backend) | ||
| 639 | (insert "Testing vc-version-diff") | ||
| 640 | (let (vc-async-checkin) | ||
| 641 | (log-edit-done))))) | ||
| 642 | |||
| 643 | ;; Modify file content. | ||
| 644 | (when (memq backend '(RCS CVS SCCS)) | ||
| 645 | (vc-checkout tmp-name)) | ||
| 646 | (write-region "updatedtext" nil tmp-name nil 'nomessage) | ||
| 647 | |||
| 648 | ;; Check version diff. | ||
| 649 | (vc-version-diff files nil nil) | ||
| 650 | (if (eq backend 'Bzr) | ||
| 651 | (sleep-for 1)) | ||
| 652 | (should (bufferp (get-buffer "*vc-diff*"))) | ||
| 653 | |||
| 654 | (with-current-buffer "*vc-diff*" | ||
| 655 | (progn | ||
| 656 | (let ((rawtext (buffer-substring-no-properties (point-min) | ||
| 657 | (point-max)))) | ||
| 658 | (should (string-search "-originaltext" rawtext)) | ||
| 659 | (should (string-search "+updatedtext" rawtext))))))) | ||
| 660 | 666 | ||
| 661 | ;; Save exit. | 667 | ;; Save exit. |
| 662 | (ignore-errors | 668 | (ignore-errors |
| 663 | (run-hooks 'vc-test--cleanup-hook)))))) | 669 | (run-hooks 'vc-test--cleanup-hook))))))) |
| 664 | 670 | ||
| 665 | (declare-function vc-git--program-version "vc-git") | 671 | (declare-function vc-git--program-version "vc-git") |
| 666 | 672 | ||
| @@ -672,104 +678,104 @@ This checks also `vc-backend' and `vc-responsible-backend'." | |||
| 672 | (file-name-as-directory | 678 | (file-name-as-directory |
| 673 | (expand-file-name | 679 | (expand-file-name |
| 674 | (make-temp-name "vc-test") temporary-file-directory))) | 680 | (make-temp-name "vc-test") temporary-file-directory))) |
| 675 | (process-environment process-environment) | ||
| 676 | vc-test--cleanup-hook) | 681 | vc-test--cleanup-hook) |
| 677 | (unwind-protect | 682 | (vc-test--with-author-identity backend |
| 678 | (progn | 683 | (unwind-protect |
| 679 | ;; Cleanup. | 684 | (progn |
| 680 | (add-hook | 685 | ;; Cleanup. |
| 681 | 'vc-test--cleanup-hook | 686 | (add-hook |
| 682 | (let ((dir default-directory)) | 687 | 'vc-test--cleanup-hook |
| 683 | (lambda () | 688 | (let ((dir default-directory)) |
| 684 | (delete-directory dir 'recursive) | 689 | (lambda () |
| 685 | (dolist (name '("first" "second" "first")) | 690 | (delete-directory dir 'recursive) |
| 686 | (project-forget-project | 691 | (dolist (name '("first" "second" "first")) |
| 687 | (expand-file-name name default-directory)))))) | 692 | (project-forget-project |
| 688 | 693 | (expand-file-name name default-directory)))))) | |
| 689 | (let* ((first (file-truename | 694 | |
| 690 | (file-name-as-directory | 695 | (let* ((first (file-truename |
| 691 | (expand-file-name "first" default-directory)))) | 696 | (file-name-as-directory |
| 692 | (second (file-truename | 697 | (expand-file-name "first" default-directory)))) |
| 693 | (file-name-as-directory | 698 | (second (file-truename |
| 694 | (expand-file-name "second" default-directory)))) | 699 | (file-name-as-directory |
| 695 | (third (file-truename | 700 | (expand-file-name "second" default-directory)))) |
| 696 | (file-name-as-directory | 701 | (third (file-truename |
| 697 | (expand-file-name "third" default-directory)))) | 702 | (file-name-as-directory |
| 698 | (tmp-name (expand-file-name "foo" first)) | 703 | (expand-file-name "third" default-directory)))) |
| 699 | (project-list-file | 704 | (tmp-name (expand-file-name "foo" first)) |
| 700 | (expand-file-name "projects.eld" default-directory))) | 705 | (project-list-file |
| 701 | 706 | (expand-file-name "projects.eld" default-directory))) | |
| 702 | ;; Set up the first working tree. | 707 | |
| 703 | (make-directory first t) | 708 | ;; Set up the first working tree. |
| 704 | (let ((default-directory first)) | 709 | (make-directory first t) |
| 705 | (vc-test--create-repo-function backend) | ||
| 706 | (write-region "foo" nil tmp-name nil 'nomessage) | ||
| 707 | (vc-register `(,backend (,(file-name-nondirectory tmp-name))))) | ||
| 708 | (with-current-buffer (find-file-noselect tmp-name) | ||
| 709 | (vc-checkin (list (file-name-nondirectory tmp-name)) backend) | ||
| 710 | (insert "Testing other working trees") | ||
| 711 | (let (vc-async-checkin) | ||
| 712 | (log-edit-done)) | ||
| 713 | |||
| 714 | ;; Set up the second working tree. | ||
| 715 | ;; Stub out `vc-dir' so that it doesn't start a | ||
| 716 | ;; background update process which won't like it when we | ||
| 717 | ;; start moving directories around. | ||
| 718 | ;; For the backends which do additional prompting (as | ||
| 719 | ;; specified in the API for this backend function) we | ||
| 720 | ;; need to stub that out. | ||
| 721 | (cl-letf (((symbol-function 'vc-dir) #'ignore)) | ||
| 722 | (cl-ecase backend | ||
| 723 | (Git (cl-letf (((symbol-function 'completing-read) | ||
| 724 | (lambda (&rest _ignore) ""))) | ||
| 725 | (vc-add-working-tree backend second))) | ||
| 726 | (Hg (vc-add-working-tree backend second))))) | ||
| 727 | |||
| 728 | ;; Test `known-other-working-trees'. | ||
| 729 | (with-current-buffer (find-file-noselect tmp-name) | ||
| 730 | (should | ||
| 731 | (equal (list second) | ||
| 732 | (vc-call-backend backend 'known-other-working-trees))) | ||
| 733 | (let ((default-directory second)) | ||
| 734 | (should | ||
| 735 | (equal (list first) | ||
| 736 | (vc-call-backend backend 'known-other-working-trees)))) | ||
| 737 | |||
| 738 | ;; Test `move-working-tree'. | ||
| 739 | (vc-move-working-tree backend second third) | ||
| 740 | (should | ||
| 741 | (equal (list third) | ||
| 742 | (vc-call-backend backend 'known-other-working-trees))) | ||
| 743 | (should-not (file-directory-p second)) | ||
| 744 | (should (file-directory-p third)) | ||
| 745 | ;; Moving the first working tree is only supported | ||
| 746 | ;; for some backends. | ||
| 747 | (cond ((and (eq backend 'Git) | ||
| 748 | (version<= "2.29" (vc-git--program-version))) | ||
| 749 | (let ((default-directory third)) | ||
| 750 | (vc-move-working-tree backend first second)) | ||
| 751 | (let ((default-directory third)) | ||
| 752 | (should | ||
| 753 | (equal (list second) | ||
| 754 | (vc-call-backend backend | ||
| 755 | 'known-other-working-trees)))) | ||
| 756 | (should-not (file-directory-p first)) | ||
| 757 | (should (file-directory-p second)) | ||
| 758 | (vc-move-working-tree backend second first)) | ||
| 759 | ((eq backend 'Hg) | ||
| 760 | (let ((default-directory third)) | ||
| 761 | (should-error (vc-move-working-tree backend | ||
| 762 | first second))))) | ||
| 763 | (vc-move-working-tree backend third second) | ||
| 764 | |||
| 765 | ;; Test `delete-working-tree'. | ||
| 766 | (let ((default-directory first)) | 710 | (let ((default-directory first)) |
| 767 | (vc-delete-working-tree backend second) | 711 | (vc-test--create-repo-function backend) |
| 768 | (should-not (file-directory-p second)))))) | 712 | (write-region "foo" nil tmp-name nil 'nomessage) |
| 769 | 713 | (vc-register `(,backend (,(file-name-nondirectory tmp-name))))) | |
| 770 | ;; Save exit. | 714 | (with-current-buffer (find-file-noselect tmp-name) |
| 771 | (ignore-errors | 715 | (vc-checkin (list (file-name-nondirectory tmp-name)) backend) |
| 772 | (run-hooks 'vc-test--cleanup-hook)))))) | 716 | (insert "Testing other working trees") |
| 717 | (let (vc-async-checkin) | ||
| 718 | (log-edit-done)) | ||
| 719 | |||
| 720 | ;; Set up the second working tree. | ||
| 721 | ;; Stub out `vc-dir' so that it doesn't start a | ||
| 722 | ;; background update process which won't like it when we | ||
| 723 | ;; start moving directories around. | ||
| 724 | ;; For the backends which do additional prompting (as | ||
| 725 | ;; specified in the API for this backend function) we | ||
| 726 | ;; need to stub that out. | ||
| 727 | (cl-letf (((symbol-function 'vc-dir) #'ignore)) | ||
| 728 | (cl-ecase backend | ||
| 729 | (Git (cl-letf (((symbol-function 'completing-read) | ||
| 730 | (lambda (&rest _ignore) ""))) | ||
| 731 | (vc-add-working-tree backend second))) | ||
| 732 | (Hg (vc-add-working-tree backend second))))) | ||
| 733 | |||
| 734 | ;; Test `known-other-working-trees'. | ||
| 735 | (with-current-buffer (find-file-noselect tmp-name) | ||
| 736 | (should | ||
| 737 | (equal (list second) | ||
| 738 | (vc-call-backend backend 'known-other-working-trees))) | ||
| 739 | (let ((default-directory second)) | ||
| 740 | (should | ||
| 741 | (equal (list first) | ||
| 742 | (vc-call-backend backend 'known-other-working-trees)))) | ||
| 743 | |||
| 744 | ;; Test `move-working-tree'. | ||
| 745 | (vc-move-working-tree backend second third) | ||
| 746 | (should | ||
| 747 | (equal (list third) | ||
| 748 | (vc-call-backend backend 'known-other-working-trees))) | ||
| 749 | (should-not (file-directory-p second)) | ||
| 750 | (should (file-directory-p third)) | ||
| 751 | ;; Moving the first working tree is only supported | ||
| 752 | ;; for some backends. | ||
| 753 | (cond ((and (eq backend 'Git) | ||
| 754 | (version<= "2.29" (vc-git--program-version))) | ||
| 755 | (let ((default-directory third)) | ||
| 756 | (vc-move-working-tree backend first second)) | ||
| 757 | (let ((default-directory third)) | ||
| 758 | (should | ||
| 759 | (equal (list second) | ||
| 760 | (vc-call-backend backend | ||
| 761 | 'known-other-working-trees)))) | ||
| 762 | (should-not (file-directory-p first)) | ||
| 763 | (should (file-directory-p second)) | ||
| 764 | (vc-move-working-tree backend second first)) | ||
| 765 | ((eq backend 'Hg) | ||
| 766 | (let ((default-directory third)) | ||
| 767 | (should-error (vc-move-working-tree backend | ||
| 768 | first second))))) | ||
| 769 | (vc-move-working-tree backend third second) | ||
| 770 | |||
| 771 | ;; Test `delete-working-tree'. | ||
| 772 | (let ((default-directory first)) | ||
| 773 | (vc-delete-working-tree backend second) | ||
| 774 | (should-not (file-directory-p second)))))) | ||
| 775 | |||
| 776 | ;; Save exit. | ||
| 777 | (ignore-errors | ||
| 778 | (run-hooks 'vc-test--cleanup-hook))))))) | ||
| 773 | 779 | ||
| 774 | ;; Create the test cases. | 780 | ;; Create the test cases. |
| 775 | 781 | ||