Function: vc-refresh-state

vc-refresh-state is an interactive and byte-compiled function defined in vc-hooks.el.gz.

Signature

(vc-refresh-state)

Documentation

Refresh the VC state of the current buffer's file.

This command is more thorough than vc-state-refresh, in that it also supports switching a back-end or removing the file from VC. In the latter case, VC mode is deactivated for this buffer.

Probably introduced at or before Emacs version 25.1.

Key Bindings

Aliases

vc-find-file-hook (obsolete since 25.1)

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc-hooks.el.gz
(defun vc-refresh-state ()
  "Refresh the VC state of the current buffer's file.

This command is more thorough than `vc-state-refresh', in that it
also supports switching a back-end or removing the file from VC.
In the latter case, VC mode is deactivated for this buffer."
  (interactive)
  ;; Recompute whether file is version controlled,
  ;; if user has killed the buffer and revisited.
  (when vc-mode
    (setq vc-mode nil))
  (when buffer-file-name
    (vc-file-clearprops buffer-file-name)
    ;; FIXME: Why use a hook?  Why pass it buffer-file-name?
    (add-hook 'vc-mode-line-hook #'vc-mode-line nil t)
    (let (backend)
      (cond
        ((setq backend (with-demoted-errors (vc-backend buffer-file-name)))
         ;; Let the backend setup any buffer-local things he needs.
         (vc-call-backend backend 'find-file-hook)
	;; Compute the state and put it in the mode line.
	(vc-mode-line buffer-file-name backend)
	(unless vc-make-backup-files
	  ;; Use this variable, not make-backup-files,
	  ;; because this is for things that depend on the file name.
          (setq-local backup-inhibited t)))
       ((let* ((truename (and buffer-file-truename
			      (expand-file-name buffer-file-truename)))
	       (link-type (and truename
			       (not (equal buffer-file-name truename))
			       (vc-backend truename))))
	  (cond ((not link-type) nil)	;Nothing to do.
		((eq vc-follow-symlinks nil)
		 (message
		  "Warning: symbolic link to %s-controlled source file" link-type))
		((or (not (eq vc-follow-symlinks 'ask))
		     ;; Assume we cannot ask, default to yes.
		     noninteractive
		     ;; Copied from server-start.  Seems like there should
		     ;; be a better way to ask "can we get user input?"...
		     (and (daemonp)
			  (null (cdr (frame-list)))
			  (eq (selected-frame) terminal-frame))
		     ;; If we already visited this file by following
		     ;; the link, don't ask again if we try to visit
		     ;; it again.  GUD does that, and repeated questions
		     ;; are painful.
		     (get-file-buffer
		      (abbreviate-file-name
		       (file-chase-links buffer-file-name))))

		 (vc-follow-link)
		 (message "Followed link to %s" buffer-file-name)
		 (vc-refresh-state))
		(t
		 (if (yes-or-no-p (format
				   "Symbolic link to %s-controlled source file; follow link? " link-type))
		     (progn (vc-follow-link)
			    (message "Followed link to %s" buffer-file-name)
			    (vc-refresh-state))
		   (message
		    "Warning: editing through the link bypasses version control")
		   )))))))))