aboutsummaryrefslogtreecommitdiffstats
path: root/emacs/gitto.el
blob: 646ae859d1648f062a30c0303b12cb54bbe50fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
;;; gitto.el --- Gitto in emacs

;; Copyright (C) 2012  Tom Willemse

;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: convenience
;; Package-Version: 0.2.1

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Small interface between gitto and Emacs.

;; Right now it only offers the `gitto-register' command which lets
;; you register repositories from within Emacs.  When called
;; interactively this command will try to register the git directory
;; of the file of the current buffer.

;;; Code:

(defgroup gitto nil
  "Gitto settings."
  :group 'applications)

(defcustom gitto-program "gitto"
  "The gitto executable."
  :group 'gitto
  :type 'string)

;;;###autoload
(defun gitto-registered-p (dir)
  "Check if DIR is a registered repository."
  (not (string-match-p "not registered"
                       (shell-command-to-string
                        (concat gitto-program " check " dir)))))

;;;###autoload
(defun gitto-register (dir)
  "Register DIR with gitto."
  (interactive (list (locate-dominating-file (buffer-file-name) ".git")))
  (unless dir
    (error "Not a git repository"))

  (shell-command (concat gitto-program " add " dir)))

;;;###autoload
(defun gitto-unregister (dir)
  "Unregister DIR with gitto."
  (interactive (list (locate-dominating-file (buffer-file-name) ".git")))
  (unless (and dir (gitto-registered-p dir))
    (error "Not a registered git repository"))

  (shell-command (concat gitto-program " remove " dir)))

(provide 'gitto)
;;; gitto.el ends here