forked from magit/magit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagit-flow.el
123 lines (103 loc) · 3.67 KB
/
magit-flow.el
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
;;; magit-flow.el --- git-flow plug-in for Magit
;; Copyright (C) 2012 Phil Jackson
;;
;; Magit 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, or (at your option)
;; any later version.
;;
;; Magit 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 Magit. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This plug-in provides git-flow functionality as a separate
;; component of Magit. Only supports `feature` commands at the moment.
;;; Code:
(require 'magit)
(eval-when-compile
(require 'cl))
(defun magit-run-git-flow (&rest args)
(apply 'magit-run-git (cons "flow" args)))
(defun magit-run-git-lines-flow (&rest args)
(apply 'magit-git-lines (cons "flow" args)))
(defun magit-flow-init ()
(interactive)
(magit-run-git-flow "init" "-d")
(magit-display-process))
(defun magit-flow-feature-create ()
(interactive)
(let ((name (read-string "Create feature branch: ")))
(magit-run-git-flow "feature" "start" name)))
(defun magit-flow-feature-list ()
"List the feature branches managed by flow"
(let ((current-feature nil)
(all-features nil))
(dolist (name (magit-run-git-lines-flow "feature" "list"))
;; is this the branch we're on
(when (string-match "^\\* \\(.+\\)$" name 0)
(setq current-feature (match-string 1 name)))
;; clean and append this line
(let ((clean-name (replace-regexp-in-string "^\\*? +\\(.+\\)" "\\1" name)))
(setq all-features (nconc all-features (list clean-name)))))
(cons current-feature all-features)))
(defun magit-flow-feature-finish ()
(interactive)
(let* ((all (magit-flow-feature-list))
(current (car all))
(names (cdr all))
(name (magit-completing-read "Branch to finish: " names nil t current)))
(magit-run-git-flow "feature" "finish" name)
(magit-display-process)))
(defun magit-flow-feature-diff ()
(let ((dir default-directory)
(buf (get-buffer-create "*magit-diff*")))
(display-buffer buf)
(with-current-buffer buf
(magit-mode-init dir
'magit-diff-mode
'(lambda ()
(magit-create-buffer-sections
(magit-git-section 'diffbuf
"Divergence from develop:"
'magit-wash-diffs
"flow" "feature" "diff")))))))
(defvar magit-flow-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "o") 'magit-key-mode-popup-flow)
map))
;;;###autoload
(define-minor-mode magit-flow-mode "FLOW support for Magit"
:lighter " FLOW"
:require 'magit-flow
:keymap 'magit-flow-mode-map)
;;;###autoload
(defun turn-on-magit-flow ()
"Unconditionally turn on `magit-flow-mode'."
(magit-flow-mode 1))
;; add the group and its keys
(progn
;; (re-)create the group
(magit-key-mode-add-group 'flow)
(magit-key-mode-insert-action
'flow
"n"
"Create feature"
'magit-flow-feature-create)
(magit-key-mode-insert-action
'flow
"i"
"Init"
'magit-flow-init)
(magit-key-mode-insert-action
'flow
"f"
"Finish feature"
'magit-flow-feature-finish)
;; generate and bind the menu popup function
(magit-key-mode-generate 'flow))
(provide 'magit-flow)
;;; magit-flow.el ends here