Function: org-attach-git-commit

org-attach-git-commit is a byte-compiled function defined in org-attach-git.el.gz.

Signature

(org-attach-git-commit &optional _)

Documentation

Commit changes to git if org-attach-id-dir is properly initialized.

This checks for the existence of a ".git" directory in that directory.

Takes an unused optional argument for the sake of being compatible with hook org-attach-after-change-hook.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-attach-git.el.gz
(defun org-attach-git-commit (&optional _)
  "Commit changes to git if `org-attach-id-dir' is properly initialized.
This checks for the existence of a \".git\" directory in that directory.

Takes an unused optional argument for the sake of being compatible
with hook `org-attach-after-change-hook'."
  (let* ((dir (cond ((eq org-attach-git-dir 'default)
                     (expand-file-name org-attach-id-dir))
                    ((eq org-attach-git-dir 'individual-repository)
                     (org-attach-dir))))
	 (git-dir (vc-git-root dir))
	 (use-annex (org-attach-git-use-annex))
	 (changes 0))
    (when (and git-dir (executable-find "git"))
      (with-temp-buffer
	(cd dir)
        (dolist (new-or-modified
                 (split-string
                  (shell-command-to-string
                   "git ls-files -zmo --exclude-standard") "\0" t))
          (if (and use-annex
                   (>= (file-attribute-size (file-attributes new-or-modified))
                       org-attach-git-annex-cutoff))
              (call-process "git" nil nil nil "annex" "add" new-or-modified)
            (call-process "git" nil nil nil "add" new-or-modified))
	  (cl-incf changes))
	(dolist (deleted
		 (split-string
		  (shell-command-to-string "git ls-files -z --deleted") "\0" t))
	  (call-process "git" nil nil nil "rm" deleted)
	  (cl-incf changes))
	(when (> changes 0)
	  (shell-command "git commit -m 'Synchronized attachments'"))))))