10 public class GitRepo : Object
13 public Array<GitMonitorQueue> cmds;
17 public bool debug = false;
20 * index of.. matching gitpath..
22 public static int indexOfAdd( Array<GitRepo> repos, string gitpath) {
23 for(var i =0; i < repos.length; i++) {
24 if (repos.index(i).gitdir == gitpath) {
38 * @param {Object} cfg - Configuration
39 * (basically repopath is currently only critical one.)
43 public GitRepo(string path) {
46 this.gitdir = path + "/.git";
47 if (!FileUtils.test(this.gitdir , FileTest.IS_DIR)) {
48 this.gitdir = path; // naked...
50 this.cmds = new Array<GitMonitorQueue> ();
51 //Repo.superclass.constructor.call(this,cfg);
58 * @argument {Array} files the files to add.
60 public string add ( Array<GitMonitorQueue> files )
62 // should really find out if these are untracked files each..
63 // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
64 // not sure if that is how git works.. but just be certian.
65 for (var i = 0; i < files.length;i++) {
66 var f = files.index(i).vname;
68 this.git( { "add" } + f);
70 ret += e.message + "\n";
78 * remove files to track.
80 * @argument {Array} files the files to add.
82 public string remove ( Array<GitMonitorQueue> files )
84 // this may fail if files do not exist..
85 // should really find out if these are untracked files each..
86 // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
87 // not sure if that is how git works.. but just be certian.
90 for (var i = 0; i < files.length;i++) {
91 var f = files.index(i).vname;
93 this.git( { "rm", "-f" } + f );
95 ret += e.message + "\n";
107 * @argument {Object} cfg commit configuration
109 * @property {String} name (optional)
110 * @property {String} email (optional)
111 * @property {String} changed (date) (optional)
112 * @property {String} reason (optional)
113 * @property {Array} files - the files that have changed.
117 public string commit ( string message, Array<GitMonitorQueue> files )
124 if (typeof(cfg.name) != 'undefined') {
126 'author' : cfg.name + ' <' + cfg.email + '>'
129 "GIT_COMMITTER_NAME" + cfg.name,
130 "GIT_COMMITTER_EMAIL" + cfg.email
134 if (typeof(cfg.changed) != 'undefined') {
135 env.push("GIT_AUTHOR_DATE= " + cfg.changed )
139 var args = { "commit", "-m", };
140 arg += (message.length > 0 ? message : "Changed" );
141 for (var i = 0; i< files.length ; i++ ) {
142 args += files.index(i).vname; // full path?
145 return this.git(args, env);
150 * Fetch and merge remote repo changes into current branch..
152 * At present we just need this to update the current working branch..
153 * -- maybe later it will have a few options and do more stuff..
156 public string pull ()
158 // should probably hand error conditions better...
159 return this.git({ "pull" });
165 * Send local changes to remote repo(s)
167 * At present we just need this to push the current branch.
168 * -- maybe later it will have a few options and do more stuff..
171 public string push ()
174 return this.git({ "push" });
179 * The meaty part.. run spawn.. with git..
184 public string git(string[] args_in, string[] env = {}) throws Error, SpawnError
186 // convert arguments.
191 "--git-dir", this.gitdir,
196 if (this.gitdir != this.repopath) {
197 args += "--work-tree";
198 args += this.repopath;
200 for (var i = 0; i < args_in.length;i++) {
204 //this.lastCmd = args.join(" ");
207 print( string.joinv (", ", args));
210 env += ("HOME=" + Enviroment.get_home_dir() );
211 // do not need to set gitpath..
212 //if (File.exists(this.repo + '/.git/config')) {
213 //env.push("GITPATH=" + this.repo );
217 var cfg = new SpawnConfig(this.repopath, args , env);
220 // may throw error...
221 var sp = new Spawn(cfg);
223 //print("GOT: " + output)
224 // parse output for some commands ?