* Copyright 2009, Roland Mas
* Copyright 2009, Mehdi Dogguy <mehdi@debian.org>
* Copyright 2012-2013, Franck Villaume - TrivialDev
+ * Copyright © 2013
+ * Thorsten Glaser <t.glaser@tarent.de>
* http://fusionforge.org
*
* This file is part of FusionForge.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-forge_define_config_item('default_server', 'scmgit', forge_get_config ('web_host')) ;
-forge_define_config_item('repos_path', 'scmgit', forge_get_config('chroot').'/scmrepos/git') ;
+forge_define_config_item('default_server', 'scmgit', forge_get_config ('web_host'));
+forge_define_config_item('repos_path', 'scmgit', forge_get_config('chroot').'/scmrepos/git');
+forge_define_config_item('use_ssh', 'scmgit', false);
+forge_set_config_item_bool('use_ssh', 'scmgit');
+forge_define_config_item('use_dav', 'scmgit', true);
+forge_set_config_item_bool('use_dav', 'scmgit');
+forge_define_config_item('use_ssl', 'scmgit', true);
+forge_set_config_item_bool('use_ssl', 'scmgit');
class GitPlugin extends SCMPlugin {
function GitPlugin() {
return;
}
- if ($project->usesPlugin($this->name)) {
+ if ($project->usesPlugin($this->name) && forge_check_perm('scm', $project->getID(), 'read')) {
$result = db_query_params('SELECT sum(commits) AS commits, sum(adds) AS adds FROM stats_cvs_group WHERE group_id=$1',
array ($project->getID())) ;
$commit_num = db_result($result,0,'commits');
}
function getBlurb() {
- return '<p>' . _('Documentation for Git is available at <a href="http://git-scm.com/">http://git-scm.com/</a>.') . '</p>';
+ return '<p>'
+ . sprintf(_('Documentation for %1$s is available at <a href="%2$s">%2$s</a>.'),
+ 'Git',
+ 'http://git-scm.com/')
+ . '</p>';
}
function getInstructionsForAnon($project) {
for ($i=0; $i<$rows; $i++) {
$repo_list[] = db_result($result,$i,'repo_name');
}
-
+
$b = '<h2>' . ngettext('Anonymous Access to the Git repository',
'Anonymous Access to the Git repositories',
count($repo_list)) . '</h2>';
-
+
$b .= '<p>';
$b .= ngettext('This project\'s Git repository can be checked out through anonymous access with the following command.',
'This project\'s Git repositories can be checked out through anonymous access with the following commands.',
count($repo_list));
-
+
$b .= '</p>';
-
+
foreach ($repo_list as $repo_name) {
$b .= '<p>' ;
$b .= '<tt>git clone '.util_make_url ('/anonscm/git/'.$project->getUnixName().'/'.$repo_name.'.git').'</tt><br />';
$b .= '</p>';
}
-
+
$result = db_query_params('SELECT u.user_id, u.user_name, u.realname FROM scm_personal_repos p, users u WHERE p.group_id=$1 AND u.user_id=p.user_id AND u.unix_status=$2 AND plugin_id=$3',
array ($project->getID(),
'A',
function getInstructionsForRW($project) {
$repo_list = array($project->getUnixName());
-
+
$result = db_query_params ('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND next_action = $2 AND plugin_id=$3 ORDER BY repo_name',
array ($project->getID(),
SCM_EXTRA_REPO_ACTION_UPDATE,
for ($i=0; $i<$rows; $i++) {
$repo_list[] = db_result($result,$i,'repo_name');
}
-
+
if (session_loggedin()) {
$u = user_get_object(user_getid());
$d = $u->getUnixName();
}
$validSetup = 1;
- }
+ }
if (forge_get_config('use_dav', 'scmgit')) {
$protocol = forge_get_config('use_ssl', 'scmgit')? 'https' : 'http';
$b .= '<h2>';
$b .= '<p><tt>git clone '.$protocol.'://'.$d.'@' . $project->getSCMBox() . '/'. forge_get_config('scm_root', 'scmgit') .'/'. $project->getUnixName() .'/'. $repo_name .'.git</tt></p>' ;
}
-
$validSetup = 1;
}
if ($validSetup == 0) {
$b .= '</h2>';
$b .= '<p>';
- $b .= ngettext('Only project developers can access the GIT repository via this method. SSH must be installed on your client machine. Substitute <i>developername</i> with the proper value. Enter your site password when prompted.',
- 'Only project developers can access the GIT repositories via this method. SSH must be installed on your client machine. Substitute <i>developername</i> with the proper value. Enter your site password when prompted.',
+ $b .= ngettext('Only project developers can access the GIT repository via this method. SSH must be installed on your client machine. Substitute <em>developername</em> with the proper value. Enter your site password when prompted.',
+ 'Only project developers can access the GIT repositories via this method. SSH must be installed on your client machine. Substitute <em>developername</em> with the proper value. Enter your site password when prompted.',
count($repo_list));
$b .= '</p>';
$b .= '<p><tt>git clone git+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . '/'. forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/'. $repo_name .'.git</tt></p>' ;
}
- }
+ }
if (forge_get_config('use_dav', 'scmgit')) {
$protocol = forge_get_config('use_ssl', 'scmgit')? 'https' : 'http';
$b = '<h2>';
} else {
$unix_group = forge_get_config('apache_group');
}
+ system ("chgrp $unix_group $root") ;
// Create main repository
$main_repo = $root . '/' . $project_name . '.git' ;
system ("echo \"Git repository for $project_name\" > $tmp_repo/description") ;
system ("find $tmp_repo -type d | xargs chmod g+s") ;
system ("chgrp -R $unix_group $tmp_repo") ;
+ system ("chmod -R g+wX,o+rX-w $tmp_repo") ;
if ($project->enableAnonSCM()) {
system ("chmod g+wX,o+rX-w $root") ;
- system ("chmod -R g+wX,o+rX-w $tmp_repo") ;
} else {
system ("chmod g+wX,o-rwx $root") ;
- system ("chmod -R g+wX,o-rwx $tmp_repo") ;
+ system ("chmod g+wX,o-rwx $tmp_repo") ;
}
$ret = true;
/*
if ($ret != 0) {
return false;
}
+ system ("echo \"Git repository for $project_name\" > $main_repo/description") ;
+ system ("find $main_repo -type d | xargs chmod g+s");
+ if (forge_get_config('use_dav','scmgit')) {
+ $f = fopen(forge_get_config('config_path').'/httpd.conf.d/plugin-scmgit-dav.inc','a');
+ fputs($f,'Use Project '.$project_name."\n");
+ fclose($f);
+ system(forge_get_config('httpd_reload_cmd','scmgit'));
+ }
}
if (forge_get_config('use_ssh','scmgit')) {
if ($project->enableAnonSCM()) {
system ("mkdir -p $root/users") ;
$user_name = db_result($result,$i,'user_name');
$repodir = $root . '/users/' . $user_name . '.git' ;
-
+
if (!is_dir($repodir) && mkdir ($repodir, 0700)) {
chown ($repodir, $user_name) ;
fwrite($config_f, "\$stylesheet = '". util_make_url('/plugins/scmgit/gitweb.css')."';\n");
fwrite($config_f, "\$javascript = '". util_make_url('/plugins/scmgit/gitweb.js')."';\n");
fwrite($config_f, "\$prevent_xss = 'true';\n");
+ fwrite($config_f, "\$feature{'actions'}{'default'} = [('project home', '" .
+ util_make_url('/plugins/scmgit/?func=grouppage/%n') .
+ "', 'summary')];\n");
fclose($config_f);
- chmod ($fname.'.new', 0644) ;
- rename ($fname.'.new', $fname) ;
+ chmod($fname.'.new', 0644);
+ rename($fname.'.new', $fname);
- $fname = $config_dir . '/gitweb.list' ;
+ $fname = $config_dir . '/gitweb.list';
+ $f = fopen($fname.'.new', 'w');
- $f = fopen ($fname.'.new', 'w');
+ $engine = RBACEngine::getInstance();
foreach ($list as $project) {
- $repos = $this->getRepositories($rootdir . "/" . $project->getUnixName());
- foreach ($repos as $repo) {
- $reldir = substr($repo, strlen($rootdir) + 1);
- fwrite($f, $reldir . "\n");
- }
+ $repos = $this->getRepositories($rootdir . "/" . $project->getUnixName());
+ foreach ($repos as $repo) {
+ $reldir = substr($repo, strlen($rootdir) + 1);
+ fwrite($f, $reldir . "\n");
+ }
+ $users = $engine->getUsersByAllowedAction('scm',$project->getID(),'write');
+ $password_data = '';
+ foreach ($users as $user) {
+ $password_data .= $user->getUnixName().':'.$user->getUnixPasswd()."\n";
+ }
+ $faname = forge_get_config('data_path').'/gituser-authfile.'.$project->getUnixName();
+ $fa = fopen($faname.'.new', 'w');
+ fwrite($fa, $password_data);
+ fclose($fa);
+ chmod($faname.'.new', 0644);
+ rename($faname.'.new', $faname);
}
fclose($f);
chmod($fname.'.new', 0644);
$repo = forge_get_config('repos_path', 'scmgit') . '/' . $project->getUnixName() . '/' . $project->getUnixName() . '.git';
if (!is_dir ($repo) || !is_dir ("$repo/refs")) {
- // echo "No repository\n" ;
+ // echo "No repository $repo\n" ;
return false ;
}
}
} else {
// Short-commit stats line
- preg_match("/^(?P<mode>[AM])\s+(?P<file>.+)$/", $line, $matches);
+ $result = preg_match("/^(?P<mode>[AMD])\s+(?P<file>.+)$/", $line, $matches);
+ if (!$result) continue;
if ($last_user == "") continue;
+ if (!isset ($usr_adds[$last_user])) $usr_adds[$last_user] = 0;
+ if (!isset ($usr_updates[$last_user])) $usr_updates[$last_user] = 0;
+ if (!isset ($usr_deletes[$last_user])) $usr_deletes[$last_user] = 0;
if ($matches['mode'] == 'A') {
$usr_adds[$last_user]++;
$adds++;
}
}
- $uu = $usr_updates[$user] ? $usr_updates[$user] : 0 ;
- $ua = $usr_adds[$user] ? $usr_adds[$user] : 0 ;
+ $uu = isset ($usr_updates[$user]) ? $usr_updates[$user] : 0 ;
+ $ua = isset ($usr_adds[$user]) ? $usr_adds[$user] : 0 ;
if ($uu > 0 || $ua > 0) {
if (!db_query_params ('INSERT INTO stats_cvs_user (month,day,group_id,user_id,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
array ($month_string,
if (! $project->usesPlugin ($this->name)) {
return false;
}
-
+
session_require_perm('project_admin', $params['group_id']);
$project_name = $project->getUnixName();
-
+
$select_repo = '<select name="frontpage">' . "\n";
$result = db_query_params('SELECT repo_name, description, clone_url FROM scm_secondary_repos WHERE group_id=$1 AND next_action = $2 AND plugin_id=$3 ORDER BY repo_name',
array ($params['group_id'],
}
$existing_repos = array();
while($data = db_fetch_array($result)) {
- $existing_repos[] = array('repo_name' => $data['repo_name'],
- 'description' => $data['description'],
+ $existing_repos[] = array('repo_name' => $data['repo_name'],
+ 'description' => $data['description'],
'clone_url' => $data['clone_url']);
}
if (count($existing_repos) == 0) {
<input type="hidden" name="repo_name" value="<?php echo $repo['repo_name']?>" />
<input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
</form>
-<?php
+<?php
print "</td></tr>\n";
}
print '</tbody></table>';
}
-
+
printf('<h2>'._('Create new Git repository for project %1$s').'</h2>', $project_name);
-
+
?>
<form name="form_create_repo"
action="<?php echo getStringFromServer('PHP_SELF'); ?>" method="post">