X-Git-Url: http://git.pk910.de/?p=GITManagedWebpage.git;a=blobdiff_plain;f=GITManagedWebpage.class.php;h=c8c7714e719eec80823363657b4263165c185ce7;hp=2c429f96ed1a047e76a7f5c0f42739f078984cd9;hb=04b1df59f6e9c029d88dd203d7dac395122cc9cb;hpb=c3d91f1e989eea95c4cef035490c72c8e2455fef diff --git a/GITManagedWebpage.class.php b/GITManagedWebpage.class.php index 2c429f9..c8c7714 100644 --- a/GITManagedWebpage.class.php +++ b/GITManagedWebpage.class.php @@ -103,6 +103,16 @@ class GITManagedWebpage { $this->config_changed = true; } + private function checkConfigIntegrity() { + foreach($this->config as $key => $value) { + if(substr($key, 0, strlen('branch_')) == 'branch_') { + if(!file_exists($this->workdir.$key)) { + unset($this->config['key']); + } + } + } + } + /* private function getConfig($name) * get an option from the configuration */ @@ -113,6 +123,7 @@ class GITManagedWebpage { if(file_exists($this->workdir."config.txt")) { $config_txt = @file_get_contents($this->workdir."config.txt"); $this->config = unserialize($config_txt); + $this->checkConfigIntegrity(); } else { $this->config = array(); return null; @@ -228,20 +239,19 @@ class GITManagedWebpage { return false; } - private function updateBranch($branch, $path) { + private function updateBranch($branch, $path, $force = false) { if(substr($path, -1) != '/') $path .= '/'; $current_branch = str_replace(array("\r", "\n"), array("", ""), $this->gitcmd("rev-parse", "--abbrev-ref", "HEAD")); - if($current_branch != $branch) - $this->gitcmd("checkout", $branch); - $this->gitcmd("pull"); + $this->gitcmd("fetch"); + $this->gitcmd("reset", "--hard", "origin/".$branch); $gitret = $this->gitcmd("rev-list", "--max-count=1", $branch); 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) + if($current_version == $newest_version && !$force) return; else { $override_all = true; @@ -291,6 +301,7 @@ class GITManagedWebpage { return; if(!$this->branchExists($branch)) { + $this->gitcmd("fetch"); if(!$this->branchExists('origin/'.$branch)) return false; } @@ -298,11 +309,11 @@ class GITManagedWebpage { if(!$this->localBranchPath($branch)) { $dir = $this->localBranchPath($branch, true); - $this->updateBranch($branch, $dir); + $this->updateBranch($branch, $dir, true); } } - public function execute($file = null) { + public function getExecFile($file = null) { if($this->loopedcall) return; define("GITMANAGED_EXECUTED", true); @@ -315,12 +326,14 @@ class GITManagedWebpage { $default_branch = $this->getConfig("defaultbranch"); $active_branch = $this->getActiveBranch(); if($active_branch != $default_branch) { - if(!($dir = $this->localBranchPath($branch))) { + if(!($dir = $this->localBranchPath($active_branch))) { $dir = $this->localBranchPath($active_branch, true); - $this->updateBranch($active_branch, $dir); + $this->updateBranch($active_branch, $dir, true); } - include_once($dir.$file); - die(); + chdir($dir); + return $dir.$file; + } else { + return $file; } }