Beispiel #1
0
 function mdiff_action()
 {
     $orig = $this->get('orig');
     $dest = \firegit\git\Util::normalBranch($this->get('dest'));
     $this->setBranch($orig);
     $ignore = $this->get('ignore') == '1';
     $diffs = $this->repo->listDiffs(\firegit\git\Util::normalBranch($dest), \firegit\git\Util::normalBranch($orig), null, $ignore);
     $this->response->set(array('diffs' => $diffs))->setView('git/components/diffs.phtml');
 }
Beispiel #2
0
 /**
  * 开始接收数据前
  * @param Hook $hook
  * @param $commits
  * @return bool
  */
 static function preReceive(Hook $hook, $commits)
 {
     $reposite = new Reposite($hook->group, $hook->name);
     // 检查用户是否能操作该库
     $mod = new \firegit\app\mod\git\Reposite();
     $users = $mod->getUsers($hook->group, $hook->name);
     $user = '';
     $role = -1;
     if ($hook->fromHttp) {
         $user = $hook->authUser;
         if (!$user) {
             ColorConsole::error('用户尚未登录');
             return false;
         }
         if (!isset($users[$user])) {
             ColorConsole::error('用户' . $user . '没有该项目的权限');
             return false;
         }
         $role = $users[$user]['repo_role'];
         if ($role <= \firegit\app\mod\git\Reposite::GROUP_ROLE_READER) {
             ColorConsole::error('用户' . $user . '没有提交该项目的权限');
             return false;
         }
     }
     // 检查每个分支是否已经创建过
     $merges = array();
     $branches = array();
     foreach ($commits as $commit) {
         $branch = $commit['branch'];
         if (strpos($branch, Util::TAG_PREFIX) !== 0) {
             if ($role == \firegit\app\mod\git\Reposite::GROUP_ROLE_BASIC) {
                 if (!$reposite->isBranchExists($branch)) {
                     if (!in_array($branch, array(Util::normalBranch('release'), Util::normalBranch('develop'), Util::normalBranch('beta')))) {
                         ColorConsole::error('服务器上还没有' . $branch . '分支,请先通过web界面创建');
                         return false;
                     } elseif ($commit['end'] == \firegit\git\util::ZERO_COMMIT) {
                         $repos = new \firegit\app\mod\git\Reposite();
                         $repos->delBranch($hook->group, $hook->name, $branch);
                     }
                 }
             }
             // 非管理员不能往主分支提交
             if (in_array($role, array(\firegit\app\mod\git\Reposite::GROUP_ROLE_BASIC, \firegit\app\mod\git\Reposite::GROUP_ROLE_ADVANCED))) {
                 if ($branch == Util::normalBranch('master') || $branch == Util::normalBranch('beta')) {
                     ColorConsole::error('您没有提交到' . $branch . '分支的权限');
                     return false;
                 }
             }
             // 找出增加或修改的文件,对其进行代码审查
             $diffFiles = self::getDiffFiles($commit['start'], $commit['end']);
             if ($diffFiles) {
                 if (!self::checkFiles($commit['end'], $diffFiles)) {
                     ColorConsole::error('代码审查没有通过,请修改完毕再提交!');
                     return false;
                 }
             }
             // 对分支做操作
             if (!$reposite->isBranchExists($branch)) {
                 $repos = new \firegit\app\mod\git\Reposite();
                 $repos->saveBranch($hook->group, $hook->name, $branch, $user);
             } elseif ($commit['end'] == \firegit\git\util::ZERO_COMMIT) {
                 $repos = new \firegit\app\mod\git\Reposite();
                 $repos->delBranch($hook->group, $hook->name, $branch);
             }
             $_ms = $reposite->listMergeCommits($commit['start'], $commit['end']);
             if ($_ms) {
                 $merges = array_merge($merges, $_ms);
             }
             $branches[substr($branch, strlen(Util::BRANCH_PREFIX))] = $commit['end'];
         }
     }
     // 设置分支信息
     $mod->setBranches($hook->group, $hook->name, $user, $commits);
     // 处理合并请求
     $merge = new \firegit\app\mod\git\Merge();
     if ($merges) {
         $merge->handleMerges($hook->group, $hook->name, $merges);
     }
     // 处理分支
     if ($branches) {
         $merge->updateBranches($hook->group, $hook->name, $branches);
     }
 }