;;; version-control-settings.el --- Version control settings  -*- lexical-binding: t -*-

;;; Commentary:
;; IMPORTANT for magit: do not delete and change in magit-version.el
;; the version, see also git repo lisp/Makefile

;; TODO: add? https://github.com/alphapapa/magit-todos

;; Requirements:
;; magit https://melpa.org/#/magit
;;   https://magit.vc/manual/magit/Installing-from-the-Git-Repository.html#Installing-from-the-Git-Repository
;;   http://wikemacs.org/wiki/Magit
;;   dash with-editor git-commit transient
;; git-messenger https://melpa.org/#/git-messenger
;;   popup
;; orgit
;; diff-hl https://elpa.gnu.org/packages/diff-hl.html
;; (not anymore) ido-completing-read+ (now using ivy)
;; ivy

;;; Code:
;; see also Diff-Hl (diff-hl-mode) to see VC diff highlighting in fringes.

;; required by magit
(use-package git-commit
  :defer t)

(use-package magit
  :bind (("C-c M-g" . magit-file-dispatch))
  :config
  ;; (setq magit-completing-read-function 'magit-builtin-completing-read)   ;; if ivy-mode is on then it uses it otherwise set to 'ivy-completing-read
  ;; (setq magit-completing-read-function 'magit-ido-completing-read)       ;; Use ido to checkout branches. requires ido-completing-read+

  (defun my-magit-fringe-click (evt)
    "Toggle section visibility in a magit mode buffer."
    (interactive "e")
    (mouse-set-point evt)
    (magit-section-toggle (magit-current-section)))
  (define-key magit-mode-map [left-fringe mouse-1] 'my-magit-fringe-click))

(use-package magit-section
  :defer t)

;; On Windows, we must use Git GUI to enter username and password
;; See: https://github.com/magit/magit/wiki/FAQ#windows-cannot-push-via-https
(when (eq window-system 'w32)
  (setenv "GIT_ASKPASS" "git-gui--askpass"))

(use-package git-messenger
  :after (magit)
  :bind (("C-x v p" . git-messenger:popup-message))
  ;;:config
  ;;(setq git-messenger:use-magit-popup t)
  )

(use-package orgit
  :after (magit org))

;; show diffs in fringes
(use-package diff-hl
  :hook (((prog-mode vc-dir-mode org-mode) . turn-on-diff-hl-mode)
         (magit-pre-refresh . diff-hl-magit-pre-refresh)
         (magit-post-refresh . diff-hl-magit-post-refresh))
  ;;:config
  ;;(global-diff-hl-mode)
  )

;; There's no fringe when Emacs is running in the console, but the
;; navigation and revert commands still work. Consider turning
;; diff-hl-margin-mode on, to show the indicators in the margin
;; instead.
(use-package diff-hl-margin
  :after diff-hl
  :unless (display-graphic-p)
  :hook ((diff-hl-mode . diff-hl-margin-mode))
  ;;:config
  )

(provide 'version-control-settings)
;;; version-control-settings.el ends here
