From f456212b04275eebb6a7505d8602c1495ffaf497 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Tue, 6 Sep 2011 16:26:24 +0800 Subject: [PATCH] MTrack/SCM/Git/WorkingCopy.php --- MTrack/SCM/Git/WorkingCopy.php | 121 +++++++++++++++++---------------- 1 file changed, 62 insertions(+), 59 deletions(-) diff --git a/MTrack/SCM/Git/WorkingCopy.php b/MTrack/SCM/Git/WorkingCopy.php index e19c4dfe..20248abd 100644 --- a/MTrack/SCM/Git/WorkingCopy.php +++ b/MTrack/SCM/Git/WorkingCopy.php @@ -1,68 +1,71 @@ dir = mtrack_make_temp_dir(); - $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')); +class MTrack_SCM_Git_WorkingCopy extends MTrackSCMWorkingCopy +{ + private $repo; + public $push = true; + + function __construct(MTrack_Repo $repo) { + $this->dir = mtrack_make_temp_dir(); + $this->repo = $repo; + + MTrackSCM::run('git', 'string', + array('clone', $this->repo->repopath, $this->dir) + ); } - mtrack_rmdir($this->dir); - } - - function getFile($path) - { - return $this->repo->file($path); - } - - function addFile($path) - { - $this->git('add', $path); - } - - function delFile($path) - { - $this->git('rm', '-f', $path); - } - - function commit(MTrackChangeset $CS) - { - if ($CS->when) { - $d = strtotime($CS->when); - putenv("GIT_AUTHOR_DATE=$d -0000"); - } else { - putenv("GIT_AUTHOR_DATE="); + + function __destruct() { + if ($this->push) { + echo stream_get_contents($this->git('push')); + } + mtrack_rmdir($this->dir); } - $reason = trim($CS->reason); - if (!strlen($reason)) { - $reason = 'Changed'; + + function getFile($path) + { + return $this->repo->file($path); } - putenv("GIT_AUTHOR_NAME=$CS->who"); - putenv("GIT_AUTHOR_EMAIL=$CS->who"); - stream_get_contents($this->git('commit', '-a', - '-m', $reason - ) - ); - } - - function git() - { - $args = func_get_args(); - $a = array("--git-dir=$this->dir/.git", "--work-tree=$this->dir"); - foreach ($args as $arg) { - $a[] = $arg; + + function addFile($path) + { + $this->git('add', $path); + } + + function delFile($path) + { + $this->git('rm', '-f', $path); + } + + function commit(MTrackChangeset $CS) + { + if ($CS->when) { + $d = strtotime($CS->when); + putenv("GIT_AUTHOR_DATE=$d -0000"); + } else { + putenv("GIT_AUTHOR_DATE="); + } + $reason = trim($CS->reason); + if (!strlen($reason)) { + $reason = 'Changed'; + } + putenv("GIT_AUTHOR_NAME=$CS->who"); + putenv("GIT_AUTHOR_EMAIL=$CS->who"); + stream_get_contents($this->git('commit', '-a', + '-m', $reason + ) + ); + } + + function git() + { + $args = func_get_args(); + $a = array("--git-dir=$this->dir/.git", "--work-tree=$this->dir"); + foreach ($args as $arg) { + $a[] = $arg; + } + print_r($a); + return MTrackSCM::run('git', 'read', $a); } - print_r($a); - return MTrackSCM::run('git', 'read', $a); - } } -- 2.39.2