php warnings
[Pman.MTrack] / Merger.php
index 391e358..3a7c864 100644 (file)
@@ -35,7 +35,7 @@ class Pman_MTrack_Merger extends Pman {
     }
     
     
-    function get($pi)
+    function get($pi, $opts= array())
     {
         
         $this->pi = 'default/roojs1'; // fixme..
@@ -185,7 +185,7 @@ class Pman_MTrack_Merger extends Pman {
         
         
         $fh = $this->repo->impl()->git('diff', "-w", "{$this->release}..{$rev}", '--', $files);
-        
+        echo "<PRE> Commit: " . $rev ."</PRE>";
         echo '<PRE>' . htmlspecialchars(stream_get_contents($fh)) . '</PRE>';
         fclose($fh);
         exit;
@@ -196,6 +196,13 @@ class Pman_MTrack_Merger extends Pman {
     
     function merge($rev)
     {
+        
+        $mi = $this->repo->history("/", 1, "rev", $rev);
+       // echo '<PRE>';print_R($mi);exit;
+        
+
+        
+        
         $wd = $this->repo->getWorkingCopy();
         $wd->git('checkout', '-b', $this->release, 'remotes/origin/'. $this->release);
         
@@ -205,18 +212,49 @@ class Pman_MTrack_Merger extends Pman {
         
         $files = '';
         if (!empty($_POST['files'])) {
-            $files = json_decode($_POST['files']);
+            
+           
+            // if we select all the files, we should do a merge, rather than a commit..
+            $files = $_POST['files'] == '_all_' ? '_all_' : json_decode($_POST['files']);
         }
         
-        $fh = $this->repo->impl()->git('diff', "-w", "{$this->release}..{$rev}", '--', $files);
-        $of = fopen($patchfile, 'w');
-        stream_copy_to_stream($fh, $of);
-        fclose($of); fclose($fh);
-        var_dump($patch);
-        $patch = System::which('patch');
-        $cmd = "$patch -p1 < " . $patchfile
-        patch -p1 < /var/lib/php5/MTrackTMPgZFeAN.txt
-
+        
+        if (is_array($files)) { 
+            
+            $fh = $this->repo->impl()->git('diff',   "{$this->release}..{$rev}", '--', $files);
+            $of = fopen($patchfile, 'w');
+            stream_copy_to_stream($fh, $of);
+            fclose($of); fclose($fh);
+            //var_dump($patch);
+            $patch = System::which('patch');
+            chdir($wd->dir);
+            $cmd = "$patch -p1 < " . $patchfile;
+            `$cmd`;  //eg . patch -p1 < /var/lib/php5/MTrackTMPgZFeAN.txt
+        } else { 
+            $wd->git('merge', '--squash' , $rev);
+        }
+          
+        //echo $cmd;
+        
+        $commit = (object) array(
+            'when' =>  $mi[0]->ctime,
+            'reason' => $_REQUEST['message'],
+            'name'  => $this->authUser->name,
+            'email' => $this->authUser->email,
+        );
+        
+        $res = $wd->commit($commit);
+        if (!is_array($files)) {
+            // we do an actually merge commit seperatly from the merge diff, so that
+            // our logs show a nice history in each of those commits.
+            // not sure if this is a good idea or not..
+            $wd->git('merge', '-m', "Merge Commit with working branch (no code changed)" , $rev);
+        }
+        
+        
+        $res .= $wd->push();
+        $this->jok($res);
+        
        // $wd->checkout($this->release);
         // generate the patch
         // apply the patch