final move of files
[web.mtrack] / MTrack / SCM / Git / WorkingCopy.php
1 <?php
2
3 class MTrack_SCM_Git_WorkingCopy extends MTrackSCMWorkingCopy {
4   private $repo;
5   public $push = true;
6
7   function __construct(MTrackRepo $repo) {
8     $this->dir = mtrack_make_temp_dir();
9     $this->repo = $repo;
10     
11     MTrackSCM::run('git', 'string',
12         array('clone', $this->repo->repopath, $this->dir)
13     );
14   }
15
16   function __destruct() {
17     if ($this->push) {
18       echo stream_get_contents($this->git('push'));
19     }
20     mtrack_rmdir($this->dir);
21   }
22
23   function getFile($path)
24   {
25     return $this->repo->file($path);
26   }
27
28   function addFile($path)
29   {
30     $this->git('add', $path);
31   }
32
33   function delFile($path)
34   {
35     $this->git('rm', '-f', $path);
36   }
37
38   function commit(MTrackChangeset $CS)
39   {
40     if ($CS->when) {
41       $d = strtotime($CS->when);
42       putenv("GIT_AUTHOR_DATE=$d -0000");
43     } else {
44       putenv("GIT_AUTHOR_DATE=");
45     }
46     $reason = trim($CS->reason);
47     if (!strlen($reason)) {
48       $reason = 'Changed';
49     }
50     putenv("GIT_AUTHOR_NAME=$CS->who");
51     putenv("GIT_AUTHOR_EMAIL=$CS->who");
52     stream_get_contents($this->git('commit', '-a',
53       '-m', $reason
54       )
55     );
56   }
57
58   function git()
59   {
60     $args = func_get_args();
61     $a = array("--git-dir=$this->dir/.git", "--work-tree=$this->dir");
62     foreach ($args as $arg) {
63       $a[] = $arg;
64     }
65     print_r($a);
66     return MTrackSCM::run('git', 'read', $a);
67   }
68 }