MTrack/SCM/Git/WorkingCopy.php
[web.mtrack] / MTrack / SCM / Git / WorkingCopy.php
index 9b4391c..b2d671b 100644 (file)
@@ -1,31 +1,45 @@
 <?php
 
+/***
+ *
+ * working directories?
+ *
+ * This is very dodgy..
+ * = either we have a temporary working directory created for each session/user etc..
+ *
+ * = what happens when multiple people try to access a working directory..
+ *
+ * = what happens if the same person is doing multiple things on the same workign directory..
+ *
+ * 
+ *
+ *
+ */
+require_once 'MTrack/SCM/WorkingCopy.php';
 
-
-class MTrack_SCM_Git_WorkingCopy extends MTrackSCMWorkingCopy
+class MTrack_SCM_Git_WorkingCopy extends MTrack_SCM_WorkingCopy
 {
     private $repo;
-    public $push = true;
+    public $push = false; /// 
   
     function __construct(MTrack_Repo $repo) {
-        $cfg = HTML_FlexyFramework::get()->MTrack;
-        if (empty($cfg['workingdir'])) {
-            throw new Exception("MTrack[workingdir] is not set");
-        }
-        $this->dir = $cfg['workingdir'];
+        
+        $this->dir = $this->generateTempDir();;
+        
         $this->repo = $repo;
         
         MTrackSCM::run('git', 'string',
             array('clone', $this->repo->repopath, $this->dir)
         );
     }
-  
-    function __destruct() {
-        if ($this->push) {
-          echo stream_get_contents($this->git('push'));
-        }
-        mtrack_rmdir($this->dir);
+    
+    function push()
+    {
+        return stream_get_contents($this->git('push'));
     }
+    
+    
   
     function getFile($path)
     {
@@ -41,24 +55,35 @@ class MTrack_SCM_Git_WorkingCopy extends MTrackSCMWorkingCopy
     {
          $this->git('rm', '-f', $path);
     }
+    /**
+     * @param {StdClass} $CS
+     *   ->when (optional)
+     *   ->reason (optional)???
+     *   ->name (required)
+     *   ->email (required)
+     */
   
-    function commit(MTrackChangeset $CS)
+    function commit( $CS)
     {
+         
         if ($CS->when) {
-          $d = strtotime($CS->when);
-          putenv("GIT_AUTHOR_DATE=$d -0000");
+            $d = strtotime($CS->when);
+            putenv("GIT_AUTHOR_DATE=$d -0000");
         } else {
-          putenv("GIT_AUTHOR_DATE=");
+            putenv("GIT_AUTHOR_DATE=");
         }
+        
         $reason = trim($CS->reason);
         if (!strlen($reason)) {
-          $reason = 'Changed';
+            $reason = 'Changed';
         }
-        putenv("GIT_AUTHOR_NAME=$CS->who");
-        putenv("GIT_AUTHOR_EMAIL=$CS->who");
-        stream_get_contents($this->git('commit', '-a',
-          '-m', $reason
-          )
+        print_R($CS);exit;
+        echo implode(" ", array('commit', '-a', '-m', $reason ,
+                       '--author="' . $CS->name . ' <'. $CS->email . '>"' ));exit;
+         exit;
+        return stream_get_contents(
+            $this->git('commit', '-a', '-m', $reason ,
+                       '--author="' . $CS->name . ' <'. $CS->email . '>"' )
         );
     }
   
@@ -69,7 +94,7 @@ class MTrack_SCM_Git_WorkingCopy extends MTrackSCMWorkingCopy
         foreach ($args as $arg) {
           $a[] = $arg;
         }
-        print_r($a);
+         print_r($a);
         return MTrackSCM::run('git', 'read', $a);
     }
 }