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,
70 /** editor actions **/
72 mp.actions['vcs'] = sub (d) {
76 foreach (d, n.check) {
77 if (stat(d) != NULL) {
88 mp.alert(L("This directory is not under a supported version control system"));
90 local l = sort(keys(v.opts));
95 label: sprintf(L("Available %s commands"), v.id),
104 mp.vcs_target = t[0];
106 local cmd = sprintf(l[mp.vcs_target], d.name);
108 /* if a 'pre' hook exists, run it and get the
109 cmd to be executed (NULL if none) */
110 if (v.opts[cmd].pre) {
111 cmd = v.opts[cmd].pre(d);
115 local log = mp.open(sprintf(L("<%s output>"), cmd));
117 log.txt.lines = [ '' ];
120 if (v.opts[cmd] == NULL) {
121 mp.actions.exec_command(log, cmd);
124 mp.detect_syntax(log);
134 /** default key bindings **/
136 mp.keycodes['ctrl-p'] = 'vcs';
138 /** action descriptions **/
140 mp.keycodes['vcs'] = LL("Version Control...");
144 sub mp.vcs_commit_on_close(doc, cmd)
145 /* on_close handler for commit message documents */
147 local msg_file = '.COMMIT_MESSAGE';
149 /* create a commit message */
150 local ci = mp.open(msg_file);
154 /* and add an on_close handler */
159 if (stat(doc.name)) {
160 doc.txt.lines = [ '' ];
162 mp.actions.exec_command(doc, sprintf(doc.commit_cmd, doc.name));
164 mp.detect_syntax(doc);
170 doc.name = sprintf(L("<%s output>"), doc.commit_cmd);
172 /* reject closing (file has been modified) */
178 /* delete this on_close handler */