10 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 Array<GitMontitorQueue> cmds;
37 * @param {Object} cfg - Configuration
38 * (basically repopath is currently only critical one.)
42 public GitRepo(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 if (!GLib.FileUtils.test(this.repopath +"/" + f, GLib.FileTest.EXISTS)) {
70 printf("Checked %s - exists\n", this.repopath +"/" + f);
72 this.git( { "add", f });
74 ret += e.message + "\n";
82 * remove files to track.
84 * @argument {Array} files the files to add.
86 public string remove : function ( Array<GitMontitorQueue> files )
88 // this may fail if files do not exist..
89 // should really find out if these are untracked files each..
90 // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
91 // not sure if that is how git works.. but just be certian.
94 for (var i = 0; i < files.length;i++) {
95 var f = files.item(i);
97 this.git( { "rm", "-f" , f });
99 ret += e.message + "\n";
111 * @argument {Object} cfg commit configuration
113 * @property {String} name (optional)
114 * @property {String} email (optional)
115 * @property {String} changed (date) (optional)
116 * @property {String} reason (optional)
117 * @property {Array} files - the files that have changed.
121 public string commit ( string message, Array<GitMontitorQueue> files )
128 if (typeof(cfg.name) != 'undefined') {
130 'author' : cfg.name + ' <' + cfg.email + '>'
133 "GIT_COMMITTER_NAME" + cfg.name,
134 "GIT_COMMITTER_EMAIL" + cfg.email
138 if (typeof(cfg.changed) != 'undefined') {
139 env.push("GIT_AUTHOR_DATE= " + cfg.changed )
143 var args = { "commit", "-m", message.length ? message : "Changed" }
144 for (var i = i< files.length ; i++ ) {
145 args += files.items(i).path; // full path?
148 return this.git(args, env);
153 * Fetch and merge remote repo changes into current branch..
155 * At present we just need this to update the current working branch..
156 * -- maybe later it will have a few options and do more stuff..
161 // should probably hand error conditions better...
162 return this.git({ "pull" });
168 * Send local changes to remote repo(s)
170 * At present we just need this to push the current branch.
171 * -- maybe later it will have a few options and do more stuff..
177 return this.git({ "push" });
182 * The meaty part.. run spawn.. with git..
187 git: function(string[] args_in, string[] env = {})
189 // convert arguments.
194 "--git-dir", this.gitdir,
199 if (this.gitdir != this.repopath) {
200 args += "--work-tree"
201 args += this.repopath;
203 for (var i = i; i < args_in.length;i++) {
207 //this.lastCmd = args.join(" ");
210 print( string.joinv (", ", args_list););
213 env += ("HOME=" + GLib.get_home_dir() );
214 // do not need to set gitpath..
215 //if (File.exists(this.repo + '/.git/config')) {
216 //env.push("GITPATH=" + this.repo );
220 var cfg = new SpawnConfig(this.repopath, args , env);
223 // may throw error...
224 var sp = new Spawn(cfg);
226 //print("GOT: " + output)
227 // parse output for some commands ?