10 public class GitRepo : Object
13 public Array<GitMonitorQueue> cmds;
17 public string git_working_dir;
18 public bool debug = false;
21 * index of.. matching gitpath..
23 public static int indexOf( Array<GitRepo> repos, string gitpath) {
24 // make a fake object to compare against..
25 var test_repo = new GitRepo(gitpath);
27 for(var i =0; i < repos.length; i++) {
28 if (repos.index(i).gitdir == test_repo.gitdir) {
36 public static Array<GitRepo> list_cache = null;
38 public static Array<GitRepo> list()
41 if (Repo._list !== false) {
45 var dir = GLib.get_home_dir() + '/gitlive';
46 var ar = File.list(dir );
47 print(JSON.stringify(ar));
48 ar.forEach(function(f) {
49 if (File.exists(dir + '/' + f +'/.git')) {
50 Repo._list.push(new imports.Scm.Git.Repo.Repo( {
51 repopath : dir +'/' + f,
66 * @param {Object} cfg - Configuration
67 * (basically repopath is currently only critical one.)
71 public GitRepo(string path) {
73 this.git_working_dir = path;
74 this.gitdir = path + "/.git";
75 if (!FileUtils.test(this.gitdir , FileTest.IS_DIR)) {
76 this.gitdir = path; // naked...
78 this.cmds = new Array<GitMonitorQueue> ();
79 //Repo.superclass.constructor.call(this,cfg);
86 * @argument {Array} files the files to add.
88 public string add ( Array<GitMonitorQueue> files ) throws Error, SpawnError
90 // should really find out if these are untracked files each..
91 // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
92 // 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.index(i).vname;
97 string[] cmd = { "add", f };
100 ret += e.message + "\n";
109 * remove files to track.
111 * @argument {Array} files the files to add.
113 public string remove ( Array<GitMonitorQueue> files ) throws Error, SpawnError
115 // this may fail if files do not exist..
116 // should really find out if these are untracked files each..
117 // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
118 // not sure if that is how git works.. but just be certian.
121 for (var i = 0; i < files.length;i++) {
122 var f = files.index(i).vname;
124 string[] cmd = { "rm", "-f" , f };
127 ret += e.message + "\n";
139 * @argument {Object} cfg commit configuration
141 * @property {String} name (optional)
142 * @property {String} email (optional)
143 * @property {String} changed (date) (optional)
144 * @property {String} reason (optional)
145 * @property {Array} files - the files that have changed.
149 public string commit ( string message, Array<GitMonitorQueue> files ) throws Error, SpawnError
156 if (typeof(cfg.name) != 'undefined') {
158 'author' : cfg.name + ' <' + cfg.email + '>'
161 "GIT_COMMITTER_NAME" + cfg.name,
162 "GIT_COMMITTER_EMAIL" + cfg.email
166 if (typeof(cfg.changed) != 'undefined') {
167 env.push("GIT_AUTHOR_DATE= " + cfg.changed )
171 string[] args = { "commit", "-m" };
172 args += (message.length > 0 ? message : "Changed" );
173 for (var i = 0; i< files.length ; i++ ) {
174 args += files.index(i).vname; // full path?
177 return this.git(args);
182 * Fetch and merge remote repo changes into current branch..
184 * At present we just need this to update the current working branch..
185 * -- maybe later it will have a few options and do more stuff..
188 public string pull () throws Error, SpawnError
190 // should probably hand error conditions better...
191 string[] cmd = { "pull" };
192 return this.git( cmd );
199 * Send local changes to remote repo(s)
201 * At present we just need this to push the current branch.
202 * -- maybe later it will have a few options and do more stuff..
205 public string push () throws Error, SpawnError
208 return this.git({ "push" });
213 * The meaty part.. run spawn.. with git..
218 public string git(string[] args_in ) throws Error, SpawnError
220 // convert arguments.
223 string[] args = { "git" };
224 //args += "--git-dir";
225 //args += this.gitdir;
226 args += "--no-pager";
229 //if (this.gitdir != this.repopath) {
230 // args += "--work-tree";
231 // args += this.repopath;
233 for (var i = 0; i < args_in.length;i++) {
237 //this.lastCmd = args.join(" ");
239 stdout.printf( "CWD=%s\n", this.git_working_dir );
240 print( string.joinv (" ", args));
244 string home = "HOME=" + Environment.get_home_dir() ;
246 // do not need to set gitpath..
247 //if (File.exists(this.repo + '/.git/config')) {
248 //env.push("GITPATH=" + this.repo );
253 var cfg = new SpawnConfig(this.git_working_dir , args , env);
256 // may throw error...
257 var sp = new Spawn(cfg);
259 stdout.printf( "GOT: %s\n" , sp.output);
260 // parse output for some commands ?