handling of old branches
[gitlive] / GitRepo.vala
index b1bb25f..17556ae 100644 (file)
@@ -347,33 +347,60 @@ public class GitRepo : Object
     }
     
     public bool createBranchNamed(string branchname)
-    {
-               
-               try {
+    {  
+               
+
                     if (this.branches.has_key(branchname)) {
                        // this is where it get's tricky...
-                       
-                       string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
-                   var ret = this.git(cmd);
-                   var stash = ret.length> 1 ;
-                   
-                       
-                   cmd = { "stash" };                  
-                   if (stash) { this.git(cmd); }
-                   
-                   cmd = { "checkout", branchname  };
-                   this.git(cmd);
-                   
-                   cmd = { "merge", "master"  };
-                   this.git(cmd);
-                   
-                   cmd = { "stash", "pop"  };
-                   if (stash) { this.git(cmd); }
-                   
+                               try {                   
+                                               string[] cmd = { "ls-files" ,  "-m" };                   // list the modified files..
+                                           var ret = this.git(cmd);
+                                           var 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 {
+                                    cmd = { "merge", "master"  };
+                                           this.git(cmd);
+                                  } catch(Error e) {
+                                               try {
+                                                   cmd = { "mergetool" };
+                                                       this.git(cmd);
+                                                   cmd = { "commit" "-m" "Fix merge conflicts from master" };
+                                                       this.git(cmd);
+                                               } catch(Error ee) {
+                                                       GitMonitor.gitmonitor.pauseError(ee.message);
+                                                       return false;           
+                                               }
+                                       }
+                                 try {                                 
+                                           cmd = { "stash", "pop"  };
+                                           if (stash) { this.git(cmd); }
+                                       } catch(Error ee) {
+                                               GitMonitor.gitmonitor.pauseError(ee.message);
+                                               return false;           
+                                       }
+                                   
                    
                    } else {
-                           string[] cmd = { "checkout", "-b" , branchname  };
-                           this.git(cmd);
+                                   try {                                       
+                                          
+                                       string[] cmd = { "checkout", "-b" , 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),