- public void createBranchNamed(string branchname)
- {
- if (this.branches.has_key(branchname)) {
- string[] cmd = { "checkout", branchname };
- this.git(cmd);
- } else {
- string[] cmd = { "checkout", "-b" , branchname };
- this.git(cmd);
- }
+ public bool createBranchNamed(string branchname)
+ {
+
+ var stash = false;
+ if (this.branches.has_key(branchname)) {
+ // this is where it get's tricky...
+ try {
+ string[] cmd = { "ls-files" , "-m" }; // list the modified files..
+ var ret = this.git(cmd);
+ stash = ret.length> 1 ;
+
+
+ cmd = { "stash" };
+ if (stash) { this.git(cmd); }
+
+ cmd = { "checkout", branchname };
+ this.git(cmd);
+ } catch(Error e) {
+ GitMonitor.gitmonitor.pauseError(e.message);
+ return false;
+ }
+ try {
+ if (branchname != "master") {
+ string[] cmd = { "merge", "master" };
+ this.git(cmd);
+ this.push();
+ //cmd = { "commit", "-a" , "-m", "merge master changes" };
+ //git chethis.git( cmd );
+ }
+
+ } catch(Error e) {
+ string[] cmd = { "checkout", "master" };
+ this.git(cmd);
+ GitMonitor.gitmonitor.pauseError(
+ "Use\n\na) git checkout %s\nb) git mergetool\nc) git commit\nd) git push\n d) stash pop \ne) start gitlive again\n".printf(
+ branchname)
+ + e.message
+ );
+ return false;
+
+ }
+ try {
+ string[] cmd = { "stash", "pop" };
+ if (stash) { this.git(cmd); }
+ } catch(Error ee) {
+ GitMonitor.gitmonitor.pauseError(ee.message);
+ return false;
+ }
+ this.push();
+
+ } else {
+ try {
+
+ string[] cmd = { "checkout", "-b" , branchname };
+ this.git(cmd);
+ this.push();
+ cmd = { "branch", "--set-upstream-to=origin/"+branchname , branchname };
+ this.git(cmd);
+
+ } catch(Error ee) {
+ GitMonitor.gitmonitor.pauseError(ee.message);
+ return false;
+ }
+
+ }
+ var notification = new Notify.Notification(
+ "Changed to branch %s".printf(branchname),
+ "",
+ "dialog-information"
+
+ );
+
+ notification.set_timeout(5);
+ notification.show();
+
+