Function: vc-git--git-status-to-vc-state
vc-git--git-status-to-vc-state is a byte-compiled function defined in
vc-git.el.gz.
Signature
(vc-git--git-status-to-vc-state CODE-LIST)
Documentation
Convert CODE-LIST to a VC status.
Each element of CODE-LIST comes from the first two characters of
a line returned by git status --porcelain and should be passed
in the order given by git status.
Source Code
;; Defined in /usr/src/emacs/lisp/vc/vc-git.el.gz
(defun vc-git--git-status-to-vc-state (code-list)
"Convert CODE-LIST to a VC status.
Each element of CODE-LIST comes from the first two characters of
a line returned by `git status --porcelain' and should be passed
in the order given by `git status'."
;; It is necessary to allow CODE-LIST to be a list because sometimes git
;; status returns multiple lines, e.g. for a file that is removed from
;; the index but is present in the HEAD and working tree.
(pcase code-list
('nil 'up-to-date)
(`(,code)
(pcase code
("!!" 'ignored)
("??" 'unregistered)
;; I have only seen this with a file that is only present in the
;; index. Let us call this `removed'.
("AD" 'removed)
(_ (cond
((string-match-p "^[ RD]+$" code) 'removed)
((string-match-p "^[ M]+$" code) 'edited)
((string-match-p "^[ A]+$" code) 'added)
((string-match-p "^[ U]+$" code) 'conflict)
(t 'edited)))))
;; I know of two cases when git state returns more than one element,
;; in both cases returning '("D " "??")':
;; 1. When a file is removed from the index but present in the
;; HEAD and working tree.
;; 2. When a file A is renamed to B in the index and then back to A
;; in the working tree.
;; In both of these instances, `unregistered' is a reasonable response.
('("D " "??") 'unregistered)
;; In other cases, let us return `edited'.
(_ 'edited)))