4 A Programmer's Text Editor
6 Version Control System support
8 Copyright (C) 1991-2012 Angel Ortega <angel@triptico.com>
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 http://www.triptico.com
33 check: [ '.git', '../.git', '../../.git' ],
38 "git diff '%s'" => NULL,
39 "git log '%s'" => NULL,
40 "git add '%s'" => NULL,
41 "git blame '%s'" => NULL,
42 "git checkout '%s'" => NULL,
44 "git stash apply" => NULL,
49 mp.vcs_commit_on_close(doc, "git commit -a -F '%s'");
61 "svn diff '%s'" => NULL,
62 "svn log '%s'" => NULL,
63 "svn add '%s'" => NULL,
64 "svn annotate '%s'" => NULL,
68 mp.vcs_commit_on_close(doc, "svn commit -F '%s'");
75 check: [ '.hg', '../.hg', '../../.hg' ],
80 "hg diff '%s'" => NULL,
81 "hg log '%s'" => NULL,
82 "hg add '%s'" => NULL,
85 "hg annotate '%s'" => NULL,
88 mp.vcs_commit_on_close(doc, "hg commit -A -l '%s'");
95 /** editor actions **/
97 mp.actions['vcs'] = sub (d) {
100 foreach (k, keys(mp.vcs)) {
103 foreach (d, n.check) {
104 if (stat(d) != NULL) {
115 mp.alert(L("This directory is not under a supported version control system"));
117 local l = sort(keys(v.opts));
122 label: sprintf(L("Available %s commands"), v.id),
131 mp.vcs_target = t[0];
133 local cmd = sprintf(l[mp.vcs_target], d.name);
135 /* if a 'pre' hook exists, run it and get the
136 cmd to be executed (NULL if none) */
137 if (v.opts[cmd].pre) {
138 cmd = v.opts[cmd].pre(d);
142 local log = mp.open(sprintf(L("<%s output>"), cmd));
144 log.txt.lines = [ '' ];
147 if (v.opts[cmd] == NULL) {
148 mp.actions.exec_command(log, cmd);
151 mp.detect_syntax(log);
161 /** default key bindings **/
163 mp.keycodes['ctrl-p'] = 'vcs';
165 /** action descriptions **/
167 mp.keycodes['vcs'] = LL("Version Control...");
171 sub mp.vcs_commit_on_close(doc, cmd)
172 /* on_close handler for commit message documents */
174 /* create a commit message */
175 local ci = mp.open('.COMMIT_MESSAGE');
179 /* and add an on_close handler */
184 if (stat(doc.name)) {
185 doc.txt.lines = [ '' ];
187 mp.actions.exec_command(doc, sprintf(doc.commit_cmd, doc.name));
189 mp.detect_syntax(doc);
195 doc.name = sprintf(L("<%s output>"), doc.commit_cmd);
197 /* reject closing (file has been modified) */
201 unlink('.COMMIT_MESSAGE');
203 /* delete this on_close handler */