/** * Check Log * * This function finds that last tag for the current release and shows you * any changes between them * * @param The git module directory * @return String of `git log` output */ function checklog($moddir) { $repo = Git::open($moddir); $ltags = $repo->list_tags(); if ($ltags === false) { return 'No Tags found!'; } list($rawname, $ver, $supported) = freepbx::check_xml_file($moddir); //Get current module version preg_match('/(\\d*\\.\\d*)\\./i', $ver, $matches); $rver = $matches[1]; //cycle through the tags and create a new array with relavant tags $tagArray = array(); foreach ($ltags as $tag) { if (preg_match('/release\\/(.*)/i', $tag, $matches)) { if (strpos($matches[1], $rver) !== false) { $tagArray[] = $matches[1]; } } } if (!empty($tagArray)) { usort($tagArray, "freepbx::version_compare_freepbx"); $htag = array_pop($tagArray); $tagref = $repo->show_ref_tag($htag); return $repo->log($tagref, 'HEAD'); } return; }
public static function inspect() { $repo = Git::open(ABSPATH); if (is_object($repo) && $repo->test_git()) { $status_data = $repo->run('status --porcelain'); $changed_files = array(); if (preg_match_all('/(^.+?)\\s(.*)$/m', $status_data, $changes, PREG_SET_ORDER)) { foreach ($changes as $changed_item) { $change = trim($changed_item[1]); $file = trim($changed_item[2]); $changed_files[$change][] = $file; } } $routine_options = ACI_Routine_Handler::get_options(__CLASS__); if (!is_array($routine_options)) { $routine_options = array(); } if (!is_array($routine_options['changed_files'])) { $routine_options['changed_files'] = array(); } if (empty($routine_options['ignore_files'])) { $routine_options['ignore_files'] = self::$_default_ignore_files; } else { if (!is_array($routine_options['ignore_files'])) { $routine_options['ignore_files'] = (array) $routine_options['ignore_files']; } } foreach (array_keys($changed_files) as $change) { foreach ($routine_options['ignore_files'] as $file_path) { if (!empty($file_path)) { $files_to_ignore = preg_grep('/^' . str_replace('\\*', '*', preg_quote($file_path, '/') . '/'), $changed_files[$change]); if (is_array($files_to_ignore) && count($files_to_ignore) > 0) { foreach (array_keys($files_to_ignore) as $ignore_file_key) { unset($changed_files[$change][$ignore_file_key]); } } } } if (count($changed_files[$change]) > 0) { switch ($change) { case 'A': AC_Inspector::log('Git repository has ' . count($changed_files[$change]) . ' NEW file(s).', __CLASS__); break; case 'M': AC_Inspector::log('Git repository has ' . count($changed_files[$change]) . ' MODIFIED file(s).', __CLASS__); break; case 'D': AC_Inspector::log('Git repository has ' . count($changed_files[$change]) . ' DELETED file(s).', __CLASS__); break; case '??': AC_Inspector::log('Git repository has ' . count($changed_files[$change]) . ' UNTRACKED file(s).', __CLASS__); break; } } } $routine_options['changed_files'] = $changed_files; ACI_Routine_Handler::set_options(__CLASS__, $routine_options); } }
function getBranch() { try { Git::set_bin(Settings::$git); $repo = Git::open(dirname(__FILE__) . '/../../'); return $repo->active_branch(); } catch (Exception $e) { echo $e->getMessage(); } }
function update($dynamic_model_update = true) { if ($this->git_path == null) { throw $this->exception('public variable git_path must be defined in page class'); } $class = get_class($this); preg_match('/page_(.*)_page_(.*)/', $class, $match); $this->component_namespace = $match[1]; $mp = $this->add('Model_MarketPlace')->loadBy('namespace', $this->component_namespace); $this->component_name = $mp['name']; $component_path = getcwd() . DS . 'epan-components' . DS . $this->component_namespace; if ($_GET['git_exec_path']) { Git::set_bin($_GET['git_exec_path']); } try { if (file_exists($component_path . DS . '.git')) { $repo = Git::open($component_path); } else { $repo = Git::create($component_path); } } catch (Exception $e) { // No Git Found ... So just return return; } $remote_branches = $repo->list_remote_branches(); if (count($remote_branches) == 0) { $repo->add_remote_address($this->git_path); } $branch = 'master'; if ($_GET['git_branch']) { $branch = $_GET['git_branch']; } $repo->run('fetch --all'); $repo->run('reset --hard origin/' . $branch); if ($dynamic_model_update) { $dir = $component_path . DS . 'lib' . DS . 'Model'; if (file_exists($dir)) { $lst = scandir($dir); array_shift($lst); array_shift($lst); foreach ($lst as $item) { $model = $this->add($this->component_namespace . '/Model_' . str_replace(".php", '', $item)); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); } } } // Re process Config file $this->add('Model_MarketPlace')->loadBy('namespace', $this->component_namespace)->reProcessConfig(); // Get new code from git // Get all models in lib/Model // add dynamic line on object // tryLoanAny }
/** * A custom method within the Plugin to generate the content * * @return string : HTML */ function generateGitBranchBlock() { $output = ''; $do_user_git = new UserGitrepo(); $git_repo = $do_user_git->CheckGitProjectExist($_SESSION["do_project"]->idproject); if (is_array($git_repo)) { include_once 'plugin/Git/class/Git.class.php'; $repo_path = "plugin/Git/repos/"; //$output .= '<br />'; $e_del_gitrepo = new Event("UserGitrepo->eventSelfDelProjectGitRepo"); $e_del_gitrepo->addParam("goto", "Project/" . $_SESSION["do_project"]->idproject); $e_del_gitrepo->addParam("idgit_project", $git_repo["idgit_project"]); $output .= '<div id="templt" class="co_worker_item co_worker_desc">'; $output .= '<div style="position: relative;">'; //$output .= '<b>Repository Name : '.$git_repo['git_repo'].'<br /></b>'; $idproject_task = (int) $_GET['idprojecttask']; $repo_name = $git_repo['git_repo']; $folder = "{$repo_path}" . "{$repo_name}"; if (is_dir($folder)) { $repo = Git::open($folder); $branch_name = $repo->branchlist($idproject_task); $branch_name = split(' ', $branch_name); //echo'<pre>';print_r($branch_name);echo'</pre>'; $size = sizeof($branch_name); for ($i = 1; $i < $size; $i++) { $branch_title = split('/', $branch_name[$i]); //echo'<pre>';print_r($branch_title);echo'</pre>'; $b_size = sizeof($branch_title); $b_name = split(' ', $branch_title[$b_size - 1]); $br_name .= $b_name[0] . '<br />'; } if (!empty($br_name)) { $output .= _('Currently The Following Git branches are associated with this Task <br />'); //$output .= '<br />Branches assoicated with current task are :<br />'; $output .= '<b>' . $br_name . '</b>'; } else { $output .= _('No Git branches found which are associated with this Task <br />'); } } else { $output .= _('Invalid Respository, Missing git repository in the plugin/Git/repos/' . $repo_name . ', Please check and try again <br />'); } $output .= '</div></div>'; } else { $output .= 'No Git Repository is associated with this Project Task'; } return $output; }
private function initRepo() { if (!class_exists("Git")) { require 'Git.php/Git.php'; } $this->pullOnChange = c::get('gcapc-pull', false); $this->pushOnChange = c::get('gcapc-push', false); $this->commitOnChange = c::get('gcapc-commit', false); $this->gitBin = c::get('gcapc-gitBin', ''); $this->windowsMode = c::get('gcapc-windowsMode', false); if ($this->windowsMode) { Git::windows_mode(); } if ($this->gitBin) { Git::set_bin($this->gitBin); } $this->repo = Git::open($this->repoPath); if (!$this->repo->test_git()) { trigger_error('git could not be found or is not working properly. ' . Git::get_bin()); } }
private function gitPanel($site) { $gitContentContainer = ''; // var_dump($site); if ($site->git) { $text = '<i class="fa fa-git"></i>'; $title = 'Git Controlled WP_Content'; $gitContentContainer = new html('div', array('class' => 'collapse ', 'id' => 'git_' . $site->name)); $innerContainer = new html('div', array('class' => 'options-tab')); $repo = Git::open('../../' . $site->name . '/htdocs/wp-content'); // -or- Git::create('/path/to/repo') // $status = $repo->status(); // Git Active Branch $activeBranch = new html('code', array('text' => 'current branch: ' . $repo->active_branch(), 'class' => 'options-label git-branch')); // Git Repo Controls $repoControls = new html('div', array('class' => '')); $pullBtn = new html('a', array('class' => 'btn git-pull btn-primary btn-sm', 'text' => 'Pull', 'disabled' => 'disabled', 'data-git-path' => '../../../' . $site->name . '/htdocs/wp-content')); // $refreshBtn = new html('a', array( // 'class' => 'btn btn-info btn-sm', // 'text' => 'Refresh' // )); $repoControls->append($pullBtn); // Git Commit Log $commitLog = explode(PHP_EOL, $repo->run('log -6 --oneline')); array_pop($commitLog); $commitsHtml = new html('ul', array('class' => 'list-unstyled compact')); foreach ($commitLog as $key => $logEntry) { $entry = new html('li', array('text' => $logEntry, 'class' => 'compact')); $commitsHtml->append($entry); } // $repo->add('.'); // $repo->commit('Some commit message'); // $repo->push('origin', 'master'); // Add Elements to Git HTML Container $innerContainer->append($activeBranch)->append($repoControls)->append($commitsHtml); $gitContentContainer->append($innerContainer); } return $gitContentContainer; }
<head> <title>index</title> </head> <body> <form action="<?php $PHP_SELF; ?> " method="POST"> <div class="status"> <?php // check if repo exists if (is_dir($repo_path)) { // open local repo $repo = Git::open($repo_path); } else { // clone remote repo $repo = new GitRepo($repo_path, true, false); $repo->clone_remote($source); } if (!empty($_POST['file_title'])) { $f_title = trim($_POST['file_title']); $f_desc = trim($_POST['file_description']); $f_tags = trim($_POST['file_tags']); $f_code = trim($_POST['file_code']); // TITLE // if title not end in .js make it end in .js if (!preg_match('/.js$/', $f_title)) { $f_title = $f_title . ".js"; }
/** * Refresh a local repo with changes from remote * * Updates from remote, it will attempt to stash your working changes first * * @param string $directory Location of repo * @param string $remote The name of the remote origin * @param string $final_branch The final branch to checkout after updating (null means whatever it was on before) * @return bool */ public static function refreshRepo($directory, $remote = 'origin', $final_branch = null) { freepbx::outn("Attempting to open " . $directory . "..."); //Attempt to open the module as a git repo, bail if it's not a repo try { $repo = Git::open($directory); freepbx::out("Done"); } catch (Exception $e) { freepbx::out("Skipping"); return false; } $stash = $repo->add_stash(); if (!empty($stash)) { freepbx::out("\tStashing Uncommited changes..Done"); } freepbx::outn("\tRemoving unreachable object from the remote..."); $repo->prune($remote); freepbx::out("Done"); freepbx::outn("\tCleaning Untracked Files..."); $repo->clean(true, true); freepbx::out("Done"); freepbx::outn("\tFetching Changes..."); $repo->fetch(); freepbx::out("Done"); freepbx::outn("\tDetermine Active Branch..."); $activeb = $repo->active_branch(); freepbx::out($activeb); $lbranches = $repo->list_branches(); $rbranches = $repo->list_remote_branches(); foreach ($rbranches as $k => &$rbranch) { if (preg_match('/' . $remote . '\\/(.*)/i', $rbranch)) { $rbranch = str_replace($remote . '/', '', $rbranch); $rbranch_array[] = $rbranch; } } array_unique($rbranch_array); freepbx::out("\tUpdating Branches..."); $ubranches = array(); foreach ($lbranches as $branch) { freepbx::outn("\t\tUpdating " . $branch . "..."); if (!in_array($branch, $rbranch_array)) { //Delete branches that are not available on the remote, otherwise we end up throwing an exception freepbx::out("Removing as it no longer exists on the remote"); $repo->delete_branch($branch, true); continue; } $repo->checkout($branch); $repo->pull($remote, $branch); freepbx::out("Done"); $ubranches[] = $branch; } foreach ($rbranches as $branch) { if (!in_array($branch, $ubranches)) { freepbx::outn("\t\tChecking Out " . $branch . "..."); try { $repo->checkout($branch); freepbx::out("Done"); } catch (Exception $e) { freepbx::out("Branch Doesnt Exist...Skipping"); } } } $lbranches = $repo->list_branches(); $branch = !empty($final_branch) && in_array($final_branch, $lbranches) ? $final_branch : $activeb; freepbx::out("\tPutting you back on " . $branch . " ..."); $repo->checkout($branch); freepbx::out("Done"); if (!empty($stash) && empty($final_branch)) { freepbx::outn("\tRestoring Uncommited changes..."); try { $repo->apply_stash(); $repo->drop_stash(); freepbx::out("Done"); } catch (Exception $e) { freepbx::out("Failed to restore stash!, Please check your directory"); } } $repo->add_merge_driver(); }
<?php require_once 'git.php/Git.php'; $repo = Git::open('../'); // -or- Git::create('/path/to/repo') $repo->pull('origin', 'master');
function update($dynamic_model_update = true, $git_exec_path = null, $git_branch = 'master') { if ($this->git_path == null) { throw $this->exception('public variable git_path must be defined in page class'); } $installation_path = getcwd(); if ($git_exec_path) { Git::set_bin($git_exec_path); } if (file_exists($installation_path . DS . '.git')) { $repo = Git::open($installation_path); } else { $repo = Git::create($installation_path); } $remote_branches = $repo->list_remote_branches(); if (count($remote_branches) == 0) { $repo->add_remote_address($this->git_path); } $repo->run('fetch --all'); $repo->run('reset --hard origin/' . $git_branch); if ($dynamic_model_update) { $model = $this->add('Model_Branch'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_Staff'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_EpanCategory'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_Epan'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_EpanTemplates'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_EpanPage'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_EpanPageSnapshots'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_MarketPlace'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_InstalledComponents'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_Tools'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_Plugins'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_Alerts'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_Aliases'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_Messages'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); $model = $this->add('Model_Users'); $model->add('dynamic_model/Controller_AutoCreator'); $model->tryLoadAny(); } // fire queries to convert superuser to 100 etc $this->query('UPDATE users SET type=IF(type="SuperUser",100,IF(type="BackEndUser",80,IF(type=100,100,50)))'); // change users type to int $this->query('ALTER TABLE `users` CHANGE `type` `type` INT NULL DEFAULT NULL'); // re Process base Element Config $base_element_market_place = $this->add('Model_MarketPlace')->loadBy('namespace', 'baseElements'); $base_element_market_place->reProcessConfig(); }
freepbx::switchBranch($dir, $options['switch']); } exit(0); } if (isset($options['refresh'])) { foreach (glob($directory . "/*", GLOB_ONLYDIR) as $dir) { freepbx::refreshRepo($dir); } exit(0); } if (isset($options['addmergedriver'])) { foreach (glob($directory . "/*", GLOB_ONLYDIR) as $dir) { freepbx::outn("Attempting to open " . $dir . "..."); //Attempt to open the module as a git repo, bail if it's not a repo try { $repo = Git::open($dir); freepbx::out("Done"); } catch (Exception $e) { freepbx::out("Skipping"); continue; } $gitatts = $repo->add_merge_driver(); if (!empty($gitatts)) { file_put_contents($dir . '/.gitattributes', $gitatts); } } exit(0); } if (isset($options['setup'])) { if (is_link($directory)) { freepbx::out("Confused. {$directory} is a symbolic link. Please resolve then run this again");
foreach (glob($langRepoPath . '/pot/*.pot') as $pot) { $fileinfo = pathinfo($pot); $module = $fileinfo['filename']; if ($fileinfo['filename'] != 'amp') { $moduleDirectory = $directory . "/" . $module; $langDirectory = $moduleDirectory . "/i18n"; } else { //framework is different $moduleDirectory = $directory . "/framework"; $langDirectory = $moduleDirectory . "/amp_conf/htdocs/admin/i18n"; } if (file_exists($moduleDirectory)) { freepbx::outn('Opening ' . $module . '...'); freepbx::refreshRepo($moduleDirectory); try { $repo = Git::open($moduleDirectory); freepbx::out("Done"); $ab = $repo->active_branch(); $repo->checkout("master"); } catch (Exception $e) { freepbx::out("Skipping"); continue; } if (!file_exists($langDirectory)) { freepbx::out('WARNING: Creating Missing i18n folder in ' . $module, 1); mkdir($langDirectory, 0777, true); } foreach (glob($langRepoPath . '/po/*', GLOB_ONLYDIR) as $langpath) { $lang = basename($langpath); if (file_exists($langpath . "/" . $module . ".po")) { $author = $langrepo->get_last_author("po/" . $lang . "/" . $module . ".po");
<?php if (isset($_GET['commithash'])) { $commithash = $_GET['commithash']; $repo_name = $_GET['repo_name']; $repo_folder = 'plugin/Git/repos/' . $repo_name . ''; if (is_dir($repo_folder)) { include_once 'class/Git.class.php'; $repo = Git::open($repo_folder); $commitlog = $repo->commitdetails($commithash); echo $commitlog; } else { echo 'Invalid Repository Please try again. '; } } else { echo 'Invalid Option Please try again. '; }
/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/ // Copyright 2008 - 2010 all rights reserved, SQLFusion LLC, info@sqlfusion.com /** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/ include_once 'config.php'; include_once 'plugin/Git/class/UserGitrepo.class.php'; include_once 'plugin/Git/class/Git.class.php'; $do_usergit = new UserGitrepo(); $do_usergit->getAll(); $rows = $do_usergit->getNumRows(); $repo_path = "plugin/Git/repos/"; $commitlog = array(); while ($do_usergit->fetch()) { $repo_name = $do_usergit->getData('git_repo'); $folder = "{$repo_path}" . "{$repo_name}"; if (is_dir($folder)) { $repo = Git::open($folder); echo '<pre>'; print_r($repo->log()); echo '</pre>'; $commitlog = $repo->log(); $commit_log = split('\\^', $commitlog); foreach ($commit_log as $commits) { if (!empty($commits)) { $commit_hash = split(";", $commits); $user = split("--", $commit_hash[1]); $user_email = $user[0]; $user_email = trim($user_email); $date = split(":", $user[1]); $date_log = $date[0]; $note = $date[1]; $task_ids = '';
private function _get_diff_info($repo_path, $commit_hash) { //open repo $repo = Git::open($repo_path); //get git_diff from given commit $diff_return = $repo->diff(false, ' ' . $commit_hash); //diff return treatment $xpl_str = explode('@@', $diff_return); $diff_array = array(); //isolate data and get begin and duration line from every chunk for ($index = 1; $index < count($xpl_str); $index += 2) { $diff_element = array(); $diff_element['diff_info'] = array(); //add diff content in array (line by line) $diff_element['diff_content'] = explode(PHP_EOL, $xpl_str[$index + 1]); //isolate diff_info previous and current $tmp = explode(' ', $xpl_str[$index]); //remove unnecessary index inside array array_pop($tmp); array_shift($tmp); $previous_tmp = array(); $current_tmp = array(); $tmp[0] = str_replace('-', '', $tmp[0]); $tmp[1] = str_replace('+', '', $tmp[1]); $previous_tmp['one_line'] = false; $current_tmp['one_line'] = false; if (!strpos($tmp[0], ',') !== false) { $previous_tmp['one_line'] = true; $previous_tmp['begin_line'] = (int) $tmp[0]; $previous_tmp['duration_line'] = 0; } if (!strpos($tmp[1], ',') !== false) { $current_tmp['one_line'] = true; $current_tmp['begin_line'] = (int) $tmp[1]; $current_tmp['duration_line'] = 0; } if (!$previous_tmp['one_line']) { $explode_tmp = explode(',', $tmp[0]); $previous_tmp['begin_line'] = (int) $explode_tmp[0]; $previous_tmp['duration_line'] = (int) $explode_tmp[1]; } unset($explode_tmp); if (!$current_tmp['one_line']) { $explode_tmp = explode(',', $tmp[1]); $current_tmp['begin_line'] = (int) $explode_tmp[0]; $current_tmp['duration_line'] = (int) $explode_tmp[1]; } //add obtains info inside array $diff_element['diff_info']['previous'] = $previous_tmp; $diff_element['diff_info']['current'] = $current_tmp; $diff_array[] = $diff_element; } //build array of previous and current state of file for ($i = 0; $i < count($diff_array); $i++) { $previous_note = array(); $current_note = array(); foreach ($diff_array[$i]['diff_content'] as $line) { if (empty($line)) { $previous_note[] = ""; $current_note[] = ""; } elseif ($line[0] == ' ') { $line[0] = ''; $previous_note[] = $line; $current_note[] = $line; } elseif ($line[0] == '-') { $previous_note[] = $line; } elseif ($line[0] == '+') { $current_note[] = $line; } else { $previous_note[] = $line; $current_note[] = $line; } } $diff_array[$i]['diff_content'] = array('previous' => $previous_note, 'current' => $current_note); } return $diff_array; }
<?php session_start(); require_once '../settings.php'; require_once 'Git.php'; try { Git::set_bin(Settings::$git); $repo = Git::open(dirname(__FILE__) . '/../../'); $branches = $repo->list_branches(); } catch (Exception $e) { $error = "Error connecting to the local git repo <b>highcharts.com</b>. Make sure git is running.<br/><br>" . $e->getMessage(); } if (@$_POST['branch']) { try { // Post to session $_SESSION['branch'] = @$_POST['branch']; $_SESSION['after'] = @$_POST['after']; $_SESSION['before'] = @$_POST['before']; // Prepare command $cmd = 'log > ' . sys_get_temp_dir() . '/log.txt --format="%h|%ci|%s|%p" '; // Date if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $_SESSION['after'])) { $cmd .= '--after={' . $_SESSION['after'] . '} --before={' . @$_SESSION['before'] . '}'; // Tag or commit } else { $cmd .= '' . $_SESSION['after'] . '..' . (isset($_SESSION['before']) ? $_SESSION['before'] : 'HEAD'); } // Repo $activeBranch = $repo->active_branch(); $repo->checkout($_SESSION['branch']); $repo->run($cmd);
} else { $return = array(0, "Git::create() executed successfully"); } return $return; }, 'Git::create([ $source ])' => function () { $return = null; $repo = Git::create(DIR . "/createfrom", DIR . "/test.git"); if (!Git::is_repo($repo)) { $return = array(2, "Git::create([ \$source ]) failed to produce expected output."); } else { $return = array(0, "Git::create([ \$source ]) executed successfully"); } return $return; }, 'Git::open()' => function () { $return = null; $repo = Git::open(DIR . "/test.git"); if (!Git::is_repo($repo)) { $return = array(2, "Git::open() failed to produce expected output."); } else { $return = array(0, "Git::open() executed successfully"); } return $return; }); class Git_TestSuiteControl { protected $warnings = 0; protected $errors = 0; public static function rm($dir) { if (!file_exists($dir)) { return true;
function get_update($sname, $file_lock, $base_url, $path, $mail_lock, $remote_git = '', $remote_branch = '') { session_name($sname); session_start(); set_time_limit(300); ignore_user_abort(true); $stime = time(); $work = false; //检测、设置工作标志,存在session里(同一个session_name在一个页面未结束前会保持读写锁状态) if (empty($_SESSION['working'])) { $work = true; } if (file_exists($file_lock)) { $last_work_time = filemtime($file_lock); if ($last_work_time > 0 && time() - $last_work_time < 120) { //上次更新至今有120秒 echo "检测到正在进行工作中,本页面停止载入,请稍后再次访问。"; return false; //exit; } $work = true; unlink($file_lock); } elseif (empty($_SESSION['work_time']) || $stime - $_SESSION['work_time'] > LOCK_TIME) { //保证 LOCK_TIME 秒内只访问一次 $work = true; } if ($work && !file_exists($file_lock)) { $_SESSION['working'] = true; $_SESSION['work_time'] = $stime; file_put_contents($file_lock, $stime); } else { echo "距离上次获取请求时间间隔多短,请稍后再次访问。"; return false; //exit; } echo date("Y-m-d H:i:s") . " 读取列表中...<br>"; $list = get_list($base_url); //获取列表 if (count($list) < 2) { echo "读取Wiki列表失败,等待下次检测。<br>"; $_SESSION['work_time'] = $stime - LOCK_TIME; //取消检查时间,让检测可在稍后再次发起 unlink($file_lock); return false; } session_write_close(); //解除session,防止使其他访问页面一直等待session mk_dir($path); if (IS_WIN) { Git::windows_mode(); } if (!file_exists($path . '.git')) { echo date("Y-m-d H:i:s") . " 没有git库,尝试创建...<br>"; if ($remote_git) { //是否设置了远程仓库 echo "尝试从远程仓库克隆数据...<br>"; $ret = Git::clone_remote($path, $remote_git, $remote_branch); //从远程仓库clone(可指定分支) if (!Git::is_repo($ret) || !file_exists($path . '.git') || !$ret) { echo "从远程仓库克隆失败,本地创建...<br>"; $ret = Git::create($path); //如果clone失败,则本地创建 } } else { $ret = Git::create($path); } //直接本地创建 echo date("Y-m-d H:i:s") . " 创建结果:" . (Git::is_repo($ret) ? '成功' : '失败') . "<br>"; } $files = ls_file($path); foreach ($files as $file) { if (!is_dir($path . $file)) { unlink($path . $file); } } $tmp_arr = parse_url($base_url); $url_base = $tmp_arr['scheme'] . '://' . $tmp_arr['host']; write($path . 'list.txt', json($list)); //写出列表 echo date("Y-m-d H:i:s") . " 读取wiki列表完毕,开始读取内容页...<br>"; $count = 0; $content = get_content($base_url); write($path . 'index.html', $content); $count++; foreach ($list as $arr) { if (isset($arr['ul'])) { foreach ($arr['ul'] as $a) { if (substr($a['url'], 0, 1) == '.' || substr($a['url'], 0, 1) == '/') { //地址以.或/开头,则为wiki文档 $content = get_content((substr($a['url'], 0, 1) == '/' ? $url_base : (substr($a['url'], 0, 1) == '.' ? $url_base . $tmp_arr['path'] : '')) . $a['url']); if ($content) { write($path . $a['title'] . '.html', $content); $count++; } } } } } echo date("Y-m-d H:i:s") . " 获取操作完成,读取页面数量:" . $count . "<br>"; $repo = Git::open($path); $ret = $repo->status(true); $no_commit = preg_match('/nothing to commit, working directory clean/', $ret); if ($no_commit) { echo " 未检测到更新,共计用时:" . (time() - $stime) . "秒<br>"; } else { echo "待更新内容:<hr>" . $ret . "<hr>"; $ret0 = $repo->add(); $repo->run('config --global user.email "' . GIT_EMAIL . '"'); //git config --global user.email "*****@*****.**" $repo->run('config --global user.name "' . GIT_NAME . '"'); //git config --global user.name "Your Name" $repo->run('config --global core.quotepath false'); //配置git显示中文不转码 $ret = $repo->commit('check time: ' . date("Y-m-d H:i:s")); echo time() . " 已进行git提交,共计用时:" . (time() - $stime) . "秒<br><br>"; if ($remote_git) { $branch = $repo->active_branch(); echo "检测到远程仓库参数,提交到远程仓库...<br>"; $repo->run("remote add {$stime} " . $remote_git); //添加远程仓库 $repo->run("push -f {$stime} {$branch}:" . (empty($remote_branch) ? 'master' : "{$remote_branch}")); //强制覆盖远程仓库(可指定分支) $repo->run("remote remove {$stime}"); //删除远程仓库 } echo "提交git日志内容如下:<hr>" . nl2br(htmlspecialchars($ret)); $ret2 = $repo->run('log --stat -p -1'); echo "<hr>其他日志:<br>" . nl2br(htmlspecialchars($ret0)) . nl2br(htmlspecialchars($ret2)); unlink($mail_lock); } unlink($file_lock); return !$no_commit; }
<?php include 'config.php'; include 'Git.php'; $path = getcwd(); echo "pushing to git...\n"; $repo = Git::open($path . '/' . STATIC_PATH); $repo->add('.'); $repo->commit(time()); $repo->push('origin', 'master'); echo "successfully pushed!\n";
<?php require dirname(__FILE__) . '/config.php'; require dirname(__FILE__) . '/php-git/Git.php'; Git::set_bin($pathToGitBinary); $repo = Git::open($repositoryPath); if ($repo->test_git() === false) { throw new Exception('Git is not installed in "' . $pathToGitBinary . '". Please update the path in config.php'); } $log = $repo->log("%H - %ad: %s"); $log = preg_split('/$\\R?^/m', $log); $i = 0; foreach ($log as $line) { //902a2a161048582a21fefddf2d4ac29461a64e57 - Tue Jun 25 17:52:42 2013 +0200: Workshop Daten vereinheitlicht if (preg_match('/([a-z0-9]{40}) - (.*?): (.*)/i', $line, $matches)) { $data[] = array('id' => $i++, 'hash' => $matches[1], 'date' => strtotime($matches[2]), 'message' => $matches[3]); } else { die('Could not parse line "' . $line . '"'); } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Billing for <?php echo $repositoryPath; ?> </title> <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
/** * @return \GitRepo|bool */ public function getGitRepository() { try { if (!$this->repository) { $repositoryPath = self::loadMODX()->getOption('Oldstyle.repository_path', null, MODX_BASE_PATH, true); $this->repository = \Git::open($repositoryPath); } } catch (\Exception $e) { return $e->getMessage(); } return $this->repository; }
#!/usr/bin/env php <?php require_once 'libraries/freepbx.php'; $help = array(); $help[] = array('--directory', 'Directory Location of modules root, always assumed to be ../freepbx from this location'); $freepbx_conf = freepbx::getFreePBXConfig(); if (is_array($freepbx_conf) && !empty($freepbx_conf)) { foreach ($freepbx_conf as $key => $value) { if (isset($value) && $value != '') { $vars[$key] = $value; } } } $vars['directory'] = !empty($vars['repo_directory']) ? $vars['repo_directory'] : ''; $vars['directory'] = !empty($vars['directory']) ? $vars['directory'] : dirname(dirname(__FILE__)) . '/freepbx'; $modules = glob($vars['directory'] . '/*', GLOB_ONLYDIR); foreach ($modules as $mod_dir) { freepbx::outn("Attempting to open module " . basename($mod_dir) . "..."); try { $repo = Git::open($mod_dir); freepbx::out("Done"); } catch (Exception $e) { freepbx::out($e->getMessage()); continue; } $remote = $repo->get_remote_uri('origin'); if (preg_match('/org\\/freep12/i', $remote)) { $newuri = preg_replace('/org\\/freep12/i', 'org/freepbx', $remote); $repo->update_remote('origin', $newuri); } }
if (!file_exists($directory)) { freepbx::out("Directories didn't exist! Aborting"); exit(0); } $fwlangpacksReop = $directory . "/fw_langpacks"; if (!file_exists($fwlangpacksReop)) { freepbx::out("Language Packs didn't exist! Aborting"); exit(0); } foreach (glob($directory . "/*", GLOB_ONLYDIR) as $moduleDir) { $module = basename($moduleDir); if ($module == 'fw_langpacks') { continue; } try { $repo = Git::open($moduleDir); } catch (Exception $e) { freepbx::out("Unable to open " . $moduleDir . " as a repo"); exit(0); } $branch = $repo->active_branch(); $stashed = $repo->add_stash(); freepbx::outn("Checking out master in " . $module . "..."); $repo->checkout('master'); $repo->pull('origin', 'master'); freepbx::out("Done"); freepbx::outn("\tChecking for i18n folder in " . $module . "..."); if (!file_exists($moduleDir . "/i18n")) { if ($module != "framework") { freepbx::out("Not Present, Skipping"); continue;
} elseif (preg_match('/framework$/i', $repodir)) { $translation->update_i18n_amp(); foreach (glob($repodir . '/amp_conf/htdocs/admin/i18n/*', GLOB_ONLYDIR) as $langDir) { $lang = basename($langDir); freepbx::outn("\t\tUpdating individual localization for " . $lang); $o = $translation->merge_i18n_amp($lang); freepbx::out($o); } freepbx::out("Done"); } else { freepbx::out("Core is done through framework"); } break; case !empty($m): FreePBX::refreshRepo($repodir); $repo = Git::open($repodir); $moduleMasterXmlString = $repo->show('origin/master', 'module.xml'); $masterXML = simplexml_load_string($moduleMasterXmlString); $activeb = $repo->active_branch(); $sver = (string) $masterXML->supported->version; $rbranches = $repo->list_remote_branches(); foreach ($rbranches as $branch) { if (!preg_match("/^origin\\/release\\/(.*)/", $branch, $bmatch)) { continue; } try { $xml = $repo->show('refs/remotes/' . $branch, 'module.xml'); } catch (Exception $e) { //no module xml here...nothing to see move along and try next branch freepbx::out("No Module.xml, skipping"); continue;
/** * @return \GitRepo|bool */ public function getGitRepository() { try { if (!$this->repository) { $gitPath = self::loadMODX()->getOption('gitify.git_path', null, '/usr/bin/git'); if (!empty($gitPath)) { \Git::set_bin($gitPath); } $repositoryPath = self::loadMODX()->getOption('gitify.repository_path', null, MODX_BASE_PATH, true); $this->repository = \Git::open($repositoryPath); } } catch (\Exception $e) { return $e->getMessage(); } return $this->repository; }
function gitpush($strRepo) { global $repo_dir, $eqdkp_dir, $git_path, $isWindows; try { if ($isWindows) { Git::windows_mode(); } Git::set_bin($git_path); $repoPath = $strRepo == 'local_core' ? $eqdkp_dir : $repo_dir . $strRepo; $repo = Git::open($repoPath); notify($repo->status(true), 'Git Status before push'); $repo->push('origin', 'master'); notify($repo->status(true), 'Git Status after push'); } catch (Exception $e) { echo $e->getMessage(); } }
function update_devtools() { $mypath = __DIR__; freepbx::outn("Updating devtools\n\tOpening devtools..."); //Attempt to open the module as a git repo, bail if it's not a repo try { $repo = Git::open($mypath); freepbx::out("Done"); } catch (Exception $e) { freepbx::out($e->getMessage()); exit; } freepbx::outn("\tIm going to update the master branch now..."); $stashable = $repo->add_stash(); $repo->fetch(); try { $merged = $repo->pull('origin', 'master'); } catch (\Exception $e) { $merged = false; } if (!$merged) { freepbx::out("\t\t\tMerge from master to this branch failed"); freepbx::out("Module " . $module . " will not be tagged!"); exit; } if ($stashable) { $repo->apply_stash(); $repo->drop_stash(); } freepbx::out("Done. Thanks for using FreePBX!"); }