function add_source_gitolite_repository()
 {
     $is_gitolite = GitoliteAdmin::is_gitolite();
     $logged_user = $this->logged_user;
     $user_id = $logged_user->getId();
     $no_key_warning = FALSE;
     $view_url = "";
     if (AngieApplication::isModuleLoaded("source") && $this->getControllerName() == 'ac_gitolite_source') {
         $do_continue = true;
     }
     if ($do_continue) {
         // Add Administrator , Leaders and Project Manager in allowed people list
         //$role = new Roles();
         //$admins = $role::findAdministrators();
         $usrobj = new Users();
         $users_details = $usrobj->findAdministrators();
         if (is_foreachable($users_details)) {
             foreach ($users_details as $key => $value) {
                 // check key exists
                 $user_keys = GitoliteAc::check_keys_added($value->getId());
                 if ($user_keys > 0) {
                     $user_detail_permissions[$value->getId()] = array('readaccess' => 0, 'writeaccess' => 0, 'writeaccessplus' => 1, 'user_keys' => $user_keys);
                     $allowed_users[$value->getId()] = $value->getDisplayName();
                 }
             }
         }
         $this->response->assign(array('curr_users' => $allowed_users, 'user_detail_permissions' => $user_detail_permissions, 'form_action' => Router::assemble('add_source_gitolite_repository'), 'noaccess' => GITOLITE_NOACCESS, 'readaccess' => GITOLITE_READACCESS, 'manageaccess' => GITOLITE_MANAGEACCESS, 'is_gitolite' => $is_gitolite, 'no_key_warning' => $no_key_warning, 'view_url' => $view_url));
     } else {
         $this->response->assign(array('add_error' => TRUE));
     }
     if ($this->request->isSubmitted()) {
         // check for form submission
         try {
             /* Check form with validation error */
             $repository_data = $this->request->post('repository');
             if (!isset($repository_data["repo_notification_setting"])) {
                 $repository_data["repo_notification_setting"] = "no";
             }
             $errors = new ValidationErrors();
             $post_data = $this->request->post();
             $settings = GitoliteAdmin::get_admin_settings();
             $is_remote = !isset($settings["git_server_location"]) || $settings["git_server_location"] != "remote" ? false : true;
             if (!$is_remote) {
                 $sever_user_path = GitoliteAdmin::get_server_user_path();
                 if (!$sever_user_path) {
                     $errors->addError('Repository path on server invalid');
                 }
             }
             $repo_name = trim($repository_data['name']);
             $access = $post_data['access'];
             if ($repo_name == "") {
                 $errors->addError('Please enter repository name', 'repo_name');
             }
             if (!is_array($access) && count($access) == 0) {
                 $errors->addError('Select access levels for user', 'access');
             }
             /* Check for duplications repository name and Key */
             if (!$errors->hasErrors()) {
                 if (!preg_match("/^[A-Za-z0-9-]+\$/", $repo_name)) {
                     $errors->addError('Please enter valid repository name.', 'repo_name');
                 }
                 $dup_cnt = ProjectGitolite::check_source_git_dup($repository_data);
                 if (count($dup_cnt) == 0) {
                     $errors->addError('Problem occured while saving data, please try again.');
                 } elseif (count($dup_cnt) > 0) {
                     if ($dup_cnt[0]['dup_name_cnt'] > 0) {
                         $errors->addError('Repository name already used');
                     }
                 }
             }
             // if errors found throw error exception
             if ($errors->hasErrors()) {
                 throw $errors;
             }
             /** save gitolite details in database * */
             // save reponame
             try {
                 DB::beginWork('Creating a new repository @ ' . __CLASS__);
                 /**
                  * if gitolite is setup on remote, change repo path
                  */
                 if (!$is_remote) {
                     $repo_path = $sever_user_path . "/repositories/" . $repository_data['name'] . ".git";
                 } elseif ($is_remote) {
                     $repo_path = GIT_FILES_PATH . "/" . $repo_name;
                 }
                 if (is_array($post_data)) {
                     $repository_path_url = array('repository_path_url' => $repo_path);
                 }
                 $repository_data = array_merge($repository_data, $repository_path_url);
                 $clone_url = $settings['git_clone_url'] . $repo_name;
                 $this->active_repository = new GitRepository();
                 $this->active_repository->setAttributes($repository_data);
                 $this->active_repository->setCreatedBy($this->logged_user);
                 $this->active_repository->save();
                 $repo_fk = $this->active_repository->getId();
                 if ($repo_fk) {
                     $repo_id = ProjectGitolite::add_repo_details($repo_fk, 0, $user_id, $repo_path, $repository_data, $clone_url);
                     if ($repo_id) {
                         $add_access = ProjectGitolite::add_access_levels($repo_id, serialize($post_data['access']), $user_id, 1);
                         if ($add_access) {
                             $res = ProjectGitolite::render_conf_file();
                             $dir = $settings['gitoliteadminpath'] . "gitolite-admin";
                             $command = "cd " . $dir . " && git add * && git commit -am 'render conf file' && git push  || echo 'Not found'";
                             exec($command, $output, $return_var);
                             if ($is_remote) {
                                 $git_server = $settings['gitoliteuser'] . "@" . $settings['gitoliteserveradd'];
                                 //$command = "cd ".$settings['gitoliteadminpath']." && git clone ".$git_server.":".$repo_name;
                                 chdir(GIT_FILES_PATH);
                                 $command = "git clone " . $git_server . ":" . $repo_name;
                                 exec($command, $output, $return_var);
                             }
                         } else {
                             $errors->addError('Error while saving access levels.');
                             throw $errors;
                         }
                     } else {
                         $errors->addError('Error while saving repository.');
                         throw $errors;
                     }
                 } else {
                     $errors->addError('Error while saving repository.');
                     throw $errors;
                 }
                 DB::commit('Repository created @ ' . __CLASS__);
                 $this->response->respondWithData($this->active_repository, array('as' => 'repository'));
             } catch (Exception $e) {
                 DB::rollback('Failed to create a repository @ ' . __CLASS__);
                 $this->response->exception($e);
             }
         } catch (Exception $e) {
             DB::rollback('Failed to create a repository @ ' . __CLASS__);
             $this->response->exception($e);
         }
     }
 }