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 /** editor actions **/
77 mp.actions['vcs'] = sub (d) {
81 foreach (d, n.check) {
82 if (stat(d) != NULL) {
93 mp.alert(L("This directory is not under a supported version control system"));
95 local l = sort(keys(v.opts));
100 label: sprintf(L("Available %s commands"), v.id),
109 mp.vcs_target = t[0];
111 local cmd = sprintf(l[mp.vcs_target], d.name);
113 /* if a 'pre' hook exists, run it and get the
114 cmd to be executed (NULL if none) */
115 if (v.opts[cmd].pre) {
116 cmd = v.opts[cmd].pre(d);
120 local log = mp.open(sprintf(L("<%s output>"), cmd));
122 log.txt.lines = [ '' ];
125 if (v.opts[cmd] == NULL) {
126 mp.actions.exec_command(log, cmd);
129 mp.detect_syntax(log);
139 /** default key bindings **/
141 mp.keycodes['ctrl-p'] = 'vcs';
143 /** action descriptions **/
145 mp.keycodes['vcs'] = LL("Version Control...");
149 sub mp.vcs_commit_on_close(doc, cmd)
150 /* on_close handler for commit message documents */
152 /* create a commit message */
153 local ci = mp.open('.COMMIT_MESSAGE');
157 /* and add an on_close handler */
162 if (stat(doc.name)) {
163 doc.txt.lines = [ '' ];
165 mp.actions.exec_command(doc, sprintf(doc.commit_cmd, doc.name));
167 mp.detect_syntax(doc);
173 doc.name = sprintf(L("<%s output>"), doc.commit_cmd);
175 /* reject closing (file has been modified) */
179 unlink('.COMMIT_MESSAGE');
181 /* delete this on_close handler */