$b .= '<p>' ;
$b .= '<tt>git clone '.util_make_url ('/anonscm/git/'.$project->getUnixName().'/'.$project->getUnixName().'.git').'</tt><br />';
$b .= '</p>';
+
+ $result = db_query_params ('SELECT u.user_id, u.user_name, u.realname FROM plugin_scmgit_personal_repos p, users u WHERE p.group_id=$1 AND u.user_id=p.user_id AND u.unix_status=$2',
+ array ($project->getID(),
+ 'A')) ;
+ $rows = db_numrows ($result) ;
+
+ if ($rows > 0) {
+ $b .= ngettext ('<p><b>Developer\'s repository</b></p><p>One of this project\'s members also has a personal Git repository that can be checked out anonymously.</p>',
+ '<p><b>Developers\' repositories</b></p><p>Some of this project\'s members also have personal Git repositories that can be checked out anonymously.</p>',
+ $rows);
+ $b .= '<p>' ;
+ for ($i=0; $i<$rows; $i++) {
+ $user_id = db_result($result,$i,'user_id');
+ $user_name = db_result($result,$i,'user_name');
+ $real_name = db_result($result,$i,'realname');
+ $b .= '<tt>git clone '.util_make_url ('/anonscm/git/'.$project->getUnixName().'/users/'.$user_name.'.git').'</tt> ('.util_make_link_u ($user_name, $user_id, $real_name).')<br />';
+ }
+ $b .= '</p>';
+ }
+
return $b ;
}
function getInstructionsForRW ($project) {
- if (session_logged_in()) {
+ if (session_loggedin()) {
$u =& user_get_object(user_getid()) ;
$d = $u->getUnixName() ;
$b = _('<p><b>Developer GIT Access via SSH</b></p><p>Only project developers can access the GIT tree via this method. SSH must be installed on your client machine. Enter your site password when prompted.</p>');
} else {
$b = _('<p><b>Developer GIT Access via SSH</b></p><p>Only project developers can access the GIT tree 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.</p>');
$b .= '<p><tt>git clone git+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . $this->git_root .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
+
+ if (session_loggedin()) {
+ $u =& user_get_object(user_getid()) ;
+ if ($u->getUnixStatus() == 'A') {
+ $result = db_query_params ('SELECT * FROM plugin_scmgit_personal_repos p WHERE p.group_id=$1 AND p.user_id=$2',
+ array ($project->getID(),
+ $u->getID())) ;
+ if ($result && db_numrows ($result) > 0) {
+ $b .= _('<p><b>Access to your personal repository</b></p><p>You have a personal repository for this project, accessible through SSH with the following method. Enter your site password when prompted.</p>');
+ $b .= '<p><tt>git clone git+ssh://'.$u->getUnixName().'@' . $project->getSCMBox() . $this->git_root .'/'. $project->getUnixName() .'/users/'. $u->getUnixName() .'.git</tt></p>' ;
+ } else {
+ $glist = $u->getGroups();
+ foreach ($glist as $g) {
+ if ($g->getID() == $project->getID()) {
+ $b .= sprintf (_('<p><b>Request a personal repository</b></p><p>You can clone the project repository into a personal one into which you alone will be able to write. Other members of the project will only have read access. Access for non-members will follow the same rules as for the project\'s main repository. Note that the personal repository may take some time before it is created (less than an hour in most situations).</p><p><a href="%s">Request a personal repository</a>.</p>'),
+ util_make_url ('/plugins/scmgit/index.php?func=request-personal-repo&group_id='.$project->getID()));
+ }
+ }
+ }
+ }
}
+
return $b ;
}
$project_name = $project->getUnixName() ;
$root = $this->git_root . '/' . $project_name ;
- $repo = $root . '/' . $project_name . '.git' ;
$unix_group = 'scm_' . $project_name ;
-
- system ("mkdir -p $repo") ;
- if (!is_file ("$repo/HEAD") && !is_dir("$repo/objects") && !is_dir("$repo/refs")) {
- system ("GIT_DIR=\"$repo\" git init --bare --shared=group") ;
- system ("GIT_DIR=\"$repo\" git update-server-info") ;
- if (is_file ("$repo/hooks/post-update.sample")) {
- rename ("$repo/hooks/post-update.sample",
- "$repo/hooks/post-update") ;
+ system ("mkdir -p $root") ;
+
+ $main_repo = $root . '/' . $project_name . '.git' ;
+ if (!is_file ("$main_repo/HEAD") && !is_dir("$main_repo/objects") && !is_dir("$main_repo/refs")) {
+ system ("GIT_DIR=\"$main_repo\" git init --bare --shared=group") ;
+ system ("GIT_DIR=\"$main_repo\" git update-server-info") ;
+ if (is_file ("$main_repo/hooks/post-update.sample")) {
+ rename ("$main_repo/hooks/post-update.sample",
+ "$main_repo/hooks/post-update") ;
}
- if (!is_file ("$repo/hooks/post-update")) {
- $f = fopen ("$repo/hooks/post-update") ;
+ if (!is_file ("$main_repo/hooks/post-update")) {
+ $f = fopen ("$main_repo/hooks/post-update") ;
fwrite ($f, "exec git-update-server-info\n") ;
fclose ($f) ;
}
- if (is_file ("$repo/hooks/post-update")) {
- system ("chmod +x $repo/hooks/post-update") ;
+ if (is_file ("$main_repo/hooks/post-update")) {
+ system ("chmod +x $main_repo/hooks/post-update") ;
}
- system ("echo \"Git repository for $project_name\" > $repo/description") ;
- system ("find $repo -type d | xargs chmod g+s") ;
+ system ("echo \"Git repository for $project_name\" > $main_repo/description") ;
+ system ("find $main_repo -type d | xargs chmod g+s") ;
}
-
system ("chgrp -R $unix_group $root") ;
system ("chmod g+s $root") ;
if ($project->enableAnonSCM()) {
- system ("chmod -R g+wX,o+rX-w $root") ;
+ system ("chmod g+wX,o+rX-w $root") ;
+ system ("chmod -R g+wX,o+rX-w $main_repo") ;
} else {
- system ("chmod -R g+wX,o-rwx $root") ;
+ system ("chmod g+wX,o-rwx $root") ;
+ system ("chmod -R g+wX,o-rwx $main_repo") ;
+ }
+
+ $result = db_query_params ('SELECT u.user_name FROM plugin_scmgit_personal_repos p, users u WHERE p.group_id=$1 AND u.user_id=p.user_id AND u.unix_status=$2',
+ array ($project->getID(),
+ 'A')) ;
+ $rows = db_numrows ($result) ;
+ for ($i=0; $i<$rows; $i++) {
+ system ("mkdir -p $root/users") ;
+ $user_name = db_result($result,$i,'user_name');
+ $repodir = $root . '/users/' . $user_name . '.git' ;
+
+ if (!is_file ("$repodir/HEAD") && !is_dir("$repodir/objects") && !is_dir("$repodir/refs")) {
+ system ("git clone --bare $main_repo $repodir") ;
+ system ("GIT_DIR=\"$repodir\" git update-server-info") ;
+ system ("echo \"Git repository for user $owner in project $project_name\" > $repodir/description") ;
+ system ("chown -R $user_name:$unix_group $repodir") ;
+ }
+ }
+ if (is_dir ("$root/users")) {
+ if ($project->enableAnonSCM()) {
+ system ("chmod -R g+rX-w,o+rX-w $root/users") ;
+ } else {
+ system ("chmod -R g+rX-w,o-rwx $root/users") ;
+ }
}
}