aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorKévin Le Gouguec2024-02-12 08:29:19 +0100
committerKévin Le Gouguec2024-03-17 22:37:28 +0100
commit8d4a8b7dfd0905defac172cc58c2252dc1b39ad7 (patch)
tree57bb9cc6cdfae228b9768a6f04351533204229b8 /test
parentc29b6df2273347946d5b8c88b5dee39d8d6fd202 (diff)
downloademacs-8d4a8b7dfd0905defac172cc58c2252dc1b39ad7.tar.gz
emacs-8d4a8b7dfd0905defac172cc58c2252dc1b39ad7.zip
; Re-apply accidentally reverted commit
This re-applies: 2024-03-17 "Fix vc-dir when "remote" Git branch is local" (21828f288ef) reverted as part of the unrelated: 2024-03-17 "Update modus-themes to their 4.4.0 version" (67b0c1c09ea) The original commit message follows: Fix vc-dir when "remote" Git branch is local While in there, add that "tracking" branch to the vc-dir buffer. For bug#68183. * lisp/vc/vc-git.el (vc-git-dir-extra-headers): Reduce boilerplate with new function 'vc-git--out-ok'; stop calling vc-git-repository-url when REMOTE is "." to avoid throwing an error; display tracking branch; prefer "none (<details...>)" to "not (<details...>)" since that reads more grammatically correct. (vc-git--out-ok): Add documentation. (vc-git--out-str): New function to easily get the output from a Git command. * test/lisp/vc/vc-git-tests.el (vc-git-test--with-repo) (vc-git-test--run): New helpers, defined to steer clear of vc-git-- internal functions. (vc-git-test-dir-track-local-branch): Check that vc-dir does not crash.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/vc/vc-git-tests.el40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/lisp/vc/vc-git-tests.el b/test/lisp/vc/vc-git-tests.el
index c52cd9c5875..fd3e8ccd602 100644
--- a/test/lisp/vc/vc-git-tests.el
+++ b/test/lisp/vc/vc-git-tests.el
@@ -24,6 +24,8 @@
24 24
25;;; Code: 25;;; Code:
26 26
27(require 'ert-x)
28(require 'vc)
27(require 'vc-git) 29(require 'vc-git)
28 30
29(ert-deftest vc-git-test-program-version-general () 31(ert-deftest vc-git-test-program-version-general ()
@@ -81,4 +83,42 @@
81 (should-not (vc-git-annotate-time)) 83 (should-not (vc-git-annotate-time))
82 (should-not (vc-git-annotate-time)))) 84 (should-not (vc-git-annotate-time))))
83 85
86(defmacro vc-git-test--with-repo (name &rest body)
87 "Initialize a repository in a temporary directory and evaluate BODY.
88
89The current directory will be set to the top of that repository; NAME
90will be bound to that directory's file name. Once BODY exits, the
91directory will be deleted."
92 (declare (indent 1))
93 `(ert-with-temp-directory ,name
94 (let ((default-directory ,name))
95 (vc-create-repo 'Git)
96 ,@body)))
97
98(defun vc-git-test--run (&rest args)
99 "Run git ARGS…, check for non-zero status, and return output."
100 (with-temp-buffer
101 (apply 'vc-git-command t 0 nil args)
102 (buffer-string)))
103
104(ert-deftest vc-git-test-dir-track-local-branch ()
105 "Test that `vc-dir' works when tracking local branches. Bug#68183."
106 (skip-unless (executable-find vc-git-program))
107 (vc-git-test--with-repo repo
108 ;; Create an initial commit to get a branch started.
109 (write-region "hello" nil "README")
110 (vc-git-test--run "add" "README")
111 (vc-git-test--run "commit" "-mFirst")
112 ;; Get current branch name lazily, to remain agnostic of
113 ;; init.defaultbranch.
114 (let ((upstream-branch
115 (string-trim (vc-git-test--run "branch" "--show-current"))))
116 (vc-git-test--run "checkout" "--track" "-b" "hack" upstream-branch)
117 (vc-dir default-directory)
118 (pcase-dolist (`(,header ,value)
119 `(("Branch" "hack")
120 ("Tracking" ,upstream-branch)))
121 (goto-char (point-min))
122 (re-search-forward (format "^%s *: %s$" header value))))))
123
84;;; vc-git-tests.el ends here 124;;; vc-git-tests.el ends here