Function: vc-git-state

vc-git-state is a byte-compiled function defined in vc-git.el.gz.

Signature

(vc-git-state FILE)

Documentation

Git-specific version of vc-state.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc-git.el.gz
(defun vc-git-state (file)
  "Git-specific version of `vc-state'."
  ;; It can't set `needs-update' or `needs-merge'. The rough
  ;; equivalent would be that upstream branch for current branch is in
  ;; fast-forward state i.e. current branch is direct ancestor of
  ;; corresponding upstream branch, and the file was modified
  ;; upstream.  We'd need to check against the upstream tracking
  ;; branch for that (an extra process call or two).
  (let* ((args
          `("status" "--porcelain" "-z" "--untracked-files"
            ,@(and (version<= "1.7.6.3" (vc-git--program-version))
                   '("--ignored"))
            "--"))
         (status (apply #'vc-git--run-command-string file args))
         (root (vc-git-root default-directory))
         (file-rel (file-relative-name file root)))
    (if (null status)
        ;; If status is nil, there was an error calling git, likely because
        ;; the file is not in a git repo.
        'unregistered
      ;; If this code is adapted to parse 'git status' for a directory,
      ;; note that a renamed file takes up two null values and needs to be
      ;; treated slightly more carefully.
      (vc-git--git-status-to-vc-state
       ;; Work around Git bug demonstrated in Emacs bug#81625: this 'git
       ;; status' call can return results for files other than FILE.
       ;; Match on FILE-REL because --porcelain means results are always
       ;; relative to the repository root.
       (cl-loop for line in (split-string status "\0" t)
                when (equal (substring line 3) file-rel)
                collect (substring line 0 2))))))