X-Git-Url: http://git.pk910.de/?p=GITManagedWebpage.git;a=blobdiff_plain;f=GITManagedWebpage.class.php;h=2c429f96ed1a047e76a7f5c0f42739f078984cd9;hp=305530b1ba1195254bd2cd8c266a25ec3ce5ccfe;hb=c3d91f1e989eea95c4cef035490c72c8e2455fef;hpb=b71fd6d276e1b3f58903307ec6d3a0f7cd15538c diff --git a/GITManagedWebpage.class.php b/GITManagedWebpage.class.php index 305530b..2c429f9 100644 --- a/GITManagedWebpage.class.php +++ b/GITManagedWebpage.class.php @@ -33,6 +33,7 @@ class GITManagedWebpage { private $loopedcall = false; private $config = null; private $config_changed = true; + private $activeSession = null; public function __construct($giturl, $workdir = null, $localdir = null) { if(session_status() != PHP_SESSION_ACTIVE) { @@ -89,7 +90,7 @@ class GITManagedWebpage { } else $argstr .= " ".escapeshellarg($arg); } - $gitcmd = 'git '.escapeshellarg('--git-dir='.$this->workdir.'repository/.git').$argstr; + $gitcmd = 'git '.escapeshellarg('--git-dir='.$this->workdir.'repository/.git').' '.escapeshellarg('--work-tree='.$this->workdir.'repository').$argstr; $output = shell_exec($gitcmd); return $output; } @@ -217,7 +218,7 @@ class GITManagedWebpage { if($branch == $default_branch) $dir = $this->localdir; else - $dir = $this->workdir.'branch_'.$branch.'/'; + $dir = $this->workdir.'branch_'.str_replace(array('/'), array('_'), $branch).'/'; if(file_exists($dir)) return $dir; else if($create) { @@ -238,13 +239,19 @@ class GITManagedWebpage { preg_match("#([a-z0-9]{40})#", $gitret, $match); $newest_version = $match[1]; + $deleted_files = array(); if(($current_version = $this->getConfig('version_'.$branch))) { if($current_version == $newest_version) return; else { - //applying patch - $difftxt = $this->gitcmd("diff", $current_version, $newest_version); - echo $difftxt; + $override_all = true; + $delfiles = $this->gitcmd("diff", "--diff-filter=D", "--name-only", $current_version, $newest_version); + $delfiles = explode("\n", str_replace(array("\r"), array(""), $delfiles)); + foreach($delfiles as $file) { + if(!$file) + continue; + $deleted_files[] = $file; + } } } else $override_all = true; @@ -254,9 +261,14 @@ class GITManagedWebpage { shell_exec('rsync -avz --exclude ".git" '.escapeshellarg($this->workdir."repository/").' '.escapeshellarg($path)); else shell_exec('tar -c --exclude ".git" -C '.escapeshellarg($this->workdir."repository").' . | tar -x -C '.escapeshellarg($path)); + + // remove deleted files + foreach($deleted_files as $file) { + unlink($path.$file); + } } $this->setConfig('version_'.$branch, $newest_version); - //$this->saveConfig(); + $this->saveConfig(); } /* public function update() @@ -278,8 +290,10 @@ class GITManagedWebpage { if($this->loopedcall) return; - if(!$this->branchExists($branch)) - return false; + if(!$this->branchExists($branch)) { + if(!$this->branchExists('origin/'.$branch)) + return false; + } $this->setActiveBranch($branch, $remember); if(!$this->localBranchPath($branch)) { @@ -306,8 +320,7 @@ class GITManagedWebpage { $this->updateBranch($active_branch, $dir); } include_once($dir.$file); - } else { - include_once($this->localdir.$file); + die(); } }