watch: add 'watch' support
[girocco/ztw.git] / cgi / regproj.cgi
blob147dba7546d03ba82b1630bfaf18d339737c5457
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib qw(/home/repo/repomgr/cgi);
9 use Git::RepoCGI;
11 my $captcha_question = "What is the name of Earth's nearest star?";
12 my $captcha_answer = 'sun';
14 my $repo = Git::RepoCGI->new('Project Registration');
15 my $name = $repo->sparam('name');
17 my $mode = $repo->sparam('mode');
18 if ($name and $mode =~ /^(mirror|push)$/) {
19 # we permit the name to include '.git' suffix, but strip it off
20 my $name = $repo->wparam('name');
21 $name = $1 if $name =~ /(.*)\.git$/;
23 # for local forks, the name must be prefixed with origin
24 my $origin = $repo->wparam('origin');
25 $name = "$origin/$name" if $origin;
27 # FIXME: racy, do a lock
28 valid_proj_name($name)
29 and Git::RepoCGI::Project::does_exist($name)
30 and $repo->err("Project with the name '$name' already exists.");
32 if (lc($repo->sparam('mail')) ne lc('sun')) {
33 print "<p>Sorry, invalid captcha check.</p>";
34 exit;
37 my $mirror = $mode eq 'mirror';
38 my $proj = Git::RepoCGI::Project->ghost($name, $mirror);
39 if ($proj->cgi_fill($repo)) {
40 if ($mirror) {
41 $proj->premirror;
42 print "<p>Initiated mirroring. You will be notified about the result by mail.</p>\n";
43 } else {
44 $proj->conjure;
45 my $push_url = $proj->push_url;
46 print <<EOT;
47 <p>The project <a href="/w/$name.git">$name</a> was created successfuly.</p>
48 <p>The push URL for your project is <tt>$push_url</tt>.</p>
50 <p>To push changes, you must add yourself as a user first!</p> You must
51 <a href="reguser.cgi">register as a user</a> and provide a SSH key to
52 use for authenticating access to the server. A user may be given push
53 access to many projects, so other users may be given push access to your
54 project. You can <a href="editproj.cgi?name=$name">assign users</a>
55 now, supplying the admin password when submitting your changes.</p>
57 <p>You cannot clone the repository until you push from an existing local
58 repository to create one or more branch.</p>
60 <p>If you experience permission problems trying to push, make sure that
61 your user account has permission. A server script fixes some problems
62 periodically; if you get errors immediately after creating your project,
63 you may need to wait for its magic.</p>
65 <p>Enjoy your new project!</p>
66 EOT
68 exit;
72 my $origin = $repo->wparam('origin');
73 # if not specified, derive the project fork origin from its name
74 if (!$origin && $name =~ m{^(.*)/(.*?)(\.git)?$}) {
75 $origin = $1;
76 # user should edit only the final portion of specified name.
77 $name = $2;
79 $origin ||= '';
81 # if given, the origin must specify an existing project
82 if ($origin) {
83 valid_proj_name($origin)
84 && Git::RepoCGI::Project::does_exist($origin)
85 or $repo->err("No project with the name '$origin' exists.");
86 $origin = undef;
89 # enter fork mode when told explicitly or when we find an origin project
90 my $is_fork = $mode =~ /^fork$/ || $origin;
91 # if called in fork mode and origin project is missing, request it
92 if ($is_fork && !$origin) {
93 print <<EOT;
94 <form method="post">
95 <p>
96 Create a fork of <input type="text" name="origin" value="$name" />
97 <input type="submit" value="Continue" />
98 </p>
99 </form>
101 exit
104 my $example = $origin || 'repo';
105 print <<EOT;
106 <p>This page allows you to register a new project.</p>
108 <h2>Project E-mail and Password</h2>
110 <p>When creating a project, a password must be
111 provided in order to later <a href="editproj.cgi?name=$example">adjust
112 its settings</a>. If your admin password is lost, the
113 <a href="pwproj.cgi?name=$example">reset form</a></p> will produce
114 a new one and send it to the contact e-mail for the project.</p>
117 unless ($origin) {
118 print <<EOT;
119 <h2>Hosting Modes</h2>
121 <p>Projects can be hosted in one of two modes: <i>mirror</i> or
122 <i>depot</i>.</p>
124 <p>You currently cannot switch freely between these two modes; if you
125 want to switch from mirroring to depot mode, the project administrator
126 may delete and recreate the project. To switch the other way, you will
127 need to contact the site administrator.</p>
129 <h3>Mirror Mode</h3>
131 <p>In mirror mode, our dedicated git monkeys will check another
132 repository at a given URL every hour and mirror any new updates.</p>
134 <h3>Depot Mode</h3>
136 <p>In depot mode, <a href="reguser.cgi">registered users</a> can be
137 given permission to push changes to the repository.</p>
139 <h2>Importing an Existing Project</h2>
141 <p>If you want to develop a fork of another project hosted on this site,
142 this form should <b>not</b> be used. Instead, go to that project's
143 gitweb page, and click the 'fork' link in the top bar. This will save
144 hosting and user bandwidth, and -- more importantly -- your fork will
145 be properly categorized on the project's summary page.</p>
147 <p>If your project is a fork of an existing project that has not been
148 registered here, you should register a mirror for it first, then create
149 a fork from the mirror project. You do not have to be involved in the
150 upstream project to register a mirror of it here, though you can contact
151 its maintainers to make them aware of this new resource. A hosted mirror
152 provides an efficient solution for producing numerous forks of the project,
153 which may help attract new contributors to the project.</p>
155 <p>Remember, the distributed workflow available allowed by git means
156 that all team development proceeds in forks. Thus, forks usually have
157 positive social consequence and help a project fully distribute its
158 development efforts.</p>
160 <p>So, go forth and fork! Fork it all! Fork long, and prosper!!</p>
162 <h2>Create A Project</h2>
164 } else {
165 print <<EOT;
166 <h2>Create A Fork</h2>
167 <p>You are about to create a fork of the '$origin.git' project.</p>
169 <p>This means that it will be properly displayed as a subproject,
170 This process saves bandwidth (and time) because the original repository
171 contents become available automagically when pushing your branches.</p>
172 You will need to push only the data that <em>you</em> created.
174 <p>You do not need to specify any extra arguments during the push.
175 Specifically, you should <b>not</b> use <code>push --mirror</code> in
176 forked projects! If you have push permissions for its parent (the
177 forkee) project, then this operation will erase <i>its</i>
178 <tt>refs/</tt> hierarchy. This would upset its users considerably, so
179 this action should be avoided until a proper solution has been
180 developed and deployed.</p>
184 print <<EOT;
185 <form method="post">
186 <input type="hidden" name="origin" value="$origin" />
187 <p>Project name: <b>$origin/</b><input type="text" name="name" value="$name" /></p>
188 <p>Admin password: <input type="password" name="pwd" /></p>
189 <p>Admin password (retype): <input type="password" name="pwd2" /></p>
190 <p>E-mail contact: <input type="text" name="email" /></p>
193 if ($origin) {
194 print <<EOT;
195 <input type="hidden" name="mode" value="push" />
196 <input type="hidden" name="origin" value="$origin" />
198 } else {
199 print <<EOT;
200 <p>Hosting mode:</p><ul>
201 <li><input type="radio" name="mode" value="push" />Depot</li></ul>
202 <li><input type="radio" name="mode" value="mirror" />Mirror
203 URL: <input type="text" name="url" /> (e.g. git://example.com/foo/bar.git)</li>
204 <li><input type="radio" name="mode" value="fork" />Fork of
205 <input type="text" name="origin" value="$origin" />
206 (e.g. <a href="/w/repo.git"><tt>repo</tt></a> forks <tt>repo.git<tt>)</li>
210 print <<EOT;
211 <p>Description: <input type="text" name="desc" /></p>
212 <p>Homepage URL: <input type="text" name="hp" /></p>
213 <p>README (HTML, lt 8kb): <textarea name="README" rows="5" cols="80"></textarea></p>
214 <p>$captcha_question <input type="text" name="mail" /></p>
216 <p>By submitting this form, you are confirming that the repository
217 contains only free software and redistributing it does not violate any
218 law of Czech Republic. Read <a href="/about.html">more details</a> about
219 the hosting and terms and conditions.</p>
221 <p><input type="submit" name="y0" value="Register" /></p>
222 </form>