10 public class GitRepo : Object
16 * index of.. matching gitpath..
18 public static int indexOfAdd( Array<GitRepo> repos, string gitpath) {
19 for(var i =0; i < repos.length; i++) {
20 if (reos.index(i).gitpath == add) {
30 public Array<GitMontitorQueue> cmds;
37 * @param {Object} cfg - Configuration
38 * (basically repopath is currently only critical one.)
42 public GitRepo(string path) {
45 this.gitdir = path + "/.git";
46 if (!GLib.file_test(this.gitdir , GLib.FileTest.IS_DIR)) {
47 this.gitdir = path; // naked...
49 this.cmds = new Array<GitMontitorQueue> ();
50 //Repo.superclass.constructor.call(this,cfg);
57 * @argument {Array} files the files to add.
59 public string add ( Array<GitMontitorQueue> files )
61 // should really find out if these are untracked files each..
62 // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
63 // not sure if that is how git works.. but just be certian.
64 for (var i = 0; i < files.length;i++) {
65 var f = files.item(i);
67 this.git( { "add", f });
69 ret += e.message + "\n";
77 * remove files to track.
79 * @argument {Array} files the files to add.
81 public string remove : function ( Array<GitMontitorQueue> files )
83 // this may fail if files do not exist..
84 // should really find out if these are untracked files each..
85 // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
86 // not sure if that is how git works.. but just be certian.
89 for (var i = 0; i < files.length;i++) {
90 var f = files.item(i);
92 this.git( { "rm", "-f" , f });
94 ret += e.message + "\n";
106 * @argument {Object} cfg commit configuration
108 * @property {String} name (optional)
109 * @property {String} email (optional)
110 * @property {String} changed (date) (optional)
111 * @property {String} reason (optional)
112 * @property {Array} files - the files that have changed.
116 public string commit ( string message, Array<GitMontitorQueue> files )
123 if (typeof(cfg.name) != 'undefined') {
125 'author' : cfg.name + ' <' + cfg.email + '>'
128 "GIT_COMMITTER_NAME" + cfg.name,
129 "GIT_COMMITTER_EMAIL" + cfg.email
133 if (typeof(cfg.changed) != 'undefined') {
134 env.push("GIT_AUTHOR_DATE= " + cfg.changed )
138 var args = { "commit", "-m", message.length ? message : "Changed" }
139 for (var i = i< files.length ; i++ ) {
140 args += files.items(i).path; // full path?
143 return this.git(args, env);
148 * Fetch and merge remote repo changes into current branch..
150 * At present we just need this to update the current working branch..
151 * -- maybe later it will have a few options and do more stuff..
156 // should probably hand error conditions better...
157 return this.git({ "pull" });
163 * Send local changes to remote repo(s)
165 * At present we just need this to push the current branch.
166 * -- maybe later it will have a few options and do more stuff..
172 return this.git({ "push" });
177 * The meaty part.. run spawn.. with git..
182 git: function(string[] args_in, string[] env = {})
184 // convert arguments.
189 "--git-dir", this.gitdir,
194 if (this.gitdir != this.repopath) {
195 args += "--work-tree"
196 args += this.repopath;
198 for (var i = i; i < args_in.length;i++) {
202 //this.lastCmd = args.join(" ");
205 print( string.joinv (", ", args_list););
208 env += ("HOME=" + GLib.get_home_dir() );
209 // do not need to set gitpath..
210 //if (File.exists(this.repo + '/.git/config')) {
211 //env.push("GITPATH=" + this.repo );
215 var cfg = new SpawnConfig(this.repopath, args , env);
218 // may throw error...
219 var sp = new Spawn(cfg);
221 //print("GOT: " + output)
222 // parse output for some commands ?