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) {
40 * @param {Object} cfg - Configuration
41 * (basically repopath is currently only critical one.)
45 public GitRepo(string path) {
47 this.git_working_dir = path;
48 this.gitdir = path + "/.git";
49 if (!FileUtils.test(this.gitdir , FileTest.IS_DIR)) {
50 this.gitdir = path; // naked...
52 this.cmds = new Array<GitMonitorQueue> ();
53 //Repo.superclass.constructor.call(this,cfg);
60 * @argument {Array} files the files to add.
62 public string add ( Array<GitMonitorQueue> files ) throws Error, SpawnError
64 // should really find out if these are untracked files each..
65 // we run multiple versions to make sure that if one failes, it does not ignore the whole lot..
66 // not sure if that is how git works.. but just be certian.
68 for (var i = 0; i < files.length;i++) {
69 var f = files.index(i).vname;
71 string[] cmd = { "add", f };
74 ret += e.message + "\n";
83 * remove files to track.
85 * @argument {Array} files the files to add.
87 public string remove ( Array<GitMonitorQueue> files ) throws Error, SpawnError
89 // this may fail if files do not exist..
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.
95 for (var i = 0; i < files.length;i++) {
96 var f = files.index(i).vname;
98 string[] cmd = { "rm", "-f" , f };
101 ret += e.message + "\n";
113 * @argument {Object} cfg commit configuration
115 * @property {String} name (optional)
116 * @property {String} email (optional)
117 * @property {String} changed (date) (optional)
118 * @property {String} reason (optional)
119 * @property {Array} files - the files that have changed.
123 public string commit ( string message, Array<GitMonitorQueue> files ) throws Error, SpawnError
130 if (typeof(cfg.name) != 'undefined') {
132 'author' : cfg.name + ' <' + cfg.email + '>'
135 "GIT_COMMITTER_NAME" + cfg.name,
136 "GIT_COMMITTER_EMAIL" + cfg.email
140 if (typeof(cfg.changed) != 'undefined') {
141 env.push("GIT_AUTHOR_DATE= " + cfg.changed )
145 string[] args = { "commit", "-m" };
146 args += (message.length > 0 ? message : "Changed" );
147 for (var i = 0; i< files.length ; i++ ) {
148 args += files.index(i).vname; // full path?
151 return this.git(args);
156 * Fetch and merge remote repo changes into current branch..
158 * At present we just need this to update the current working branch..
159 * -- maybe later it will have a few options and do more stuff..
162 public string pull () throws Error, SpawnError
164 // should probably hand error conditions better...
165 string[] cmd = { "pull" };
166 return this.git( cmd );
173 * Send local changes to remote repo(s)
175 * At present we just need this to push the current branch.
176 * -- maybe later it will have a few options and do more stuff..
179 public string push () throws Error, SpawnError
182 return this.git({ "push" });
187 * The meaty part.. run spawn.. with git..
192 public string git(string[] args_in ) throws Error, SpawnError
194 // convert arguments.
197 string[] args = { "git" };
198 //args += "--git-dir";
199 //args += this.gitdir;
200 args += "--no-pager";
203 //if (this.gitdir != this.repopath) {
204 // args += "--work-tree";
205 // args += this.repopath;
207 for (var i = 0; i < args_in.length;i++) {
211 //this.lastCmd = args.join(" ");
213 stdout.printf( "CWD=%s\n", this.git_working_dir );
214 print( string.joinv (" ", args));
218 string home = "HOME=" + Environment.get_home_dir() ;
220 // do not need to set gitpath..
221 //if (File.exists(this.repo + '/.git/config')) {
222 //env.push("GITPATH=" + this.repo );
227 var cfg = new SpawnConfig(this.git_working_dir , args , env);
230 // may throw error...
231 var sp = new Spawn(cfg);
233 stdout.printf( "GOT: %s\n" , sp.output);
234 // parse output for some commands ?