(defun vc-git--program-version ()
(let ((current
(if (file-remote-p default-directory)
(with-connection-local-variables
(and (local-variable-p 'vc-git--program-version)
vc-git--program-version))
vc-git--program-version)))
(or current
(let ((version-string
(vc-git--run-command-string nil "version")))
(setq version-string
(if (and version-string
;; Git for Windows appends ".windows.N" to the
;; numerical version reported by Git.
(string-match
"git version
\\([0-9.]+\\)\\(\\.windows\\.[0-9]+\\)?$"
version-string))
(match-string 1 version-string)
"0"))
(if (file-remote-p default-directory)
(let ((profile (gensym "connection-local-profile-")))
(connection-local-set-profile-variables
profile `((vc-git--program-version . ,version-string))) ;
(connection-local-set-profiles
(connection-local-criteria-for-default-directory) profile))
(setq vc-git--program-version version-string))
version-string))))