mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
(refs #31)Make it possible to create empty repository.
This commit is contained in:
@@ -20,11 +20,13 @@ trait CreateRepositoryControllerBase extends ControllerBase {
|
||||
self: RepositoryService with WikiService with LabelsService with ActivityService
|
||||
with UsersAuthenticator =>
|
||||
|
||||
case class RepositoryCreationForm(name: String, description: Option[String])
|
||||
case class RepositoryCreationForm(name: String, description: Option[String], isPrivate: Boolean, createReadme: Boolean)
|
||||
|
||||
val form = mapping(
|
||||
"name" -> trim(label("Repository name", text(required, maxlength(40), identifier, unique))),
|
||||
"description" -> trim(label("Description" , optional(text())))
|
||||
"description" -> trim(label("Description" , optional(text()))),
|
||||
"isPrivate" -> trim(label("Repository Type", boolean())),
|
||||
"createReadme" -> trim(label("Create README" , boolean()))
|
||||
)(RepositoryCreationForm.apply)
|
||||
|
||||
/**
|
||||
@@ -42,7 +44,7 @@ trait CreateRepositoryControllerBase extends ControllerBase {
|
||||
val loginUserName = loginAccount.userName
|
||||
|
||||
// Insert to the database at first
|
||||
createRepository(form.name, loginUserName, form.description)
|
||||
createRepository(form.name, loginUserName, form.description, form.isPrivate)
|
||||
|
||||
// Insert default labels
|
||||
createLabel(loginUserName, form.name, "bug", "fc2929")
|
||||
@@ -62,6 +64,7 @@ trait CreateRepositoryControllerBase extends ControllerBase {
|
||||
config.setBoolean("http", null, "receivepack", true)
|
||||
config.save
|
||||
|
||||
if(form.createReadme){
|
||||
val tmpdir = getInitRepositoryDir(loginUserName, form.name)
|
||||
try {
|
||||
// Clone the repository
|
||||
@@ -83,6 +86,7 @@ trait CreateRepositoryControllerBase extends ControllerBase {
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmpdir)
|
||||
}
|
||||
}
|
||||
|
||||
// Create Wiki repository
|
||||
createWikiRepository(loginAccount, form.name)
|
||||
|
||||
@@ -210,18 +210,16 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
* @return HTML of the file list
|
||||
*/
|
||||
private def fileList(repository: RepositoryService.RepositoryInfo, revstr: String = "", path: String = ".") = {
|
||||
val revision = if(revstr.isEmpty){
|
||||
repository.repository.defaultBranch
|
||||
if(repository.commitCount == 0){
|
||||
repo.html.guide(repository)
|
||||
} else {
|
||||
revstr
|
||||
}
|
||||
val revision = if(revstr.isEmpty) repository.repository.defaultBranch else revstr
|
||||
|
||||
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
||||
// get latest commit
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision))
|
||||
|
||||
// get files
|
||||
val files = JGitUtil.getFileList(git, revision, path)
|
||||
|
||||
// process README.md
|
||||
val readme = files.find(_.name == "README.md").map { file =>
|
||||
new String(JGitUtil.getContent(Git.open(getRepositoryDir(repository.owner, repository.name)), file.id, true).get, "UTF-8")
|
||||
@@ -243,5 +241,6 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,19 +11,17 @@ trait RepositoryService { self: AccountService =>
|
||||
/**
|
||||
* Creates a new repository.
|
||||
*
|
||||
* The project is created as public repository at first. Users can modify the project type at the repository settings
|
||||
* page after the project creation to configure the project as the private repository.
|
||||
*
|
||||
* @param repositoryName the repository name
|
||||
* @param userName the user name of the repository owner
|
||||
* @param description the repository description
|
||||
* @param isPrivate the repository type (private is true, otherwise false)
|
||||
*/
|
||||
def createRepository(repositoryName: String, userName: String, description: Option[String]): Unit = {
|
||||
def createRepository(repositoryName: String, userName: String, description: Option[String], isPrivate: Boolean): Unit = {
|
||||
Repositories insert
|
||||
Repository(
|
||||
userName = userName,
|
||||
repositoryName = repositoryName,
|
||||
isPrivate = false,
|
||||
isPrivate = isPrivate,
|
||||
description = description,
|
||||
defaultBranch = "master",
|
||||
registeredDate = currentDate,
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType
|
||||
import org.eclipse.jgit.util.io.DisabledOutputStream
|
||||
import org.eclipse.jgit.errors.MissingObjectException
|
||||
import java.util.Date
|
||||
import org.eclipse.jgit.api.errors.NoHeadException
|
||||
|
||||
/**
|
||||
* Provides complex JGit operations.
|
||||
@@ -142,6 +143,7 @@ object JGitUtil {
|
||||
*/
|
||||
def getRepositoryInfo(owner: String, repository: String, baseUrl: String): RepositoryInfo = {
|
||||
withGit(getRepositoryDir(owner, repository)){ git =>
|
||||
try {
|
||||
// get commit count
|
||||
val i = git.log.all.call.iterator
|
||||
var commitCount = 0
|
||||
@@ -164,6 +166,12 @@ object JGitUtil {
|
||||
TagInfo(ref.getName.replaceFirst("^refs/tags/", ""), revCommit.getCommitterIdent.getWhen, revCommit.getName)
|
||||
}.toList
|
||||
)
|
||||
} catch {
|
||||
// not initialized
|
||||
case e: NoHeadException => RepositoryInfo(
|
||||
owner, repository, baseUrl + "/git/%s/%s.git".format(owner, repository), 0, Nil, Nil)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@()(implicit context: app.Context)
|
||||
@import context._
|
||||
@main("Create a New Repository"){
|
||||
<div style="width: 600px; margin: 10px auto;">
|
||||
<form id="form" method="post" action="@path/new" validate="true">
|
||||
<fieldset>
|
||||
<label for="name"><strong>Repository name</strong></label>
|
||||
@@ -9,10 +10,38 @@
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="description"><strong>Description</strong> (optional)</label>
|
||||
<input type="text" name="description" id="description" style="width: 600px;"/>
|
||||
<input type="text" name="description" id="description" style="width: 95%;"/>
|
||||
</fieldset>
|
||||
<fieldset class="margin">
|
||||
<label>
|
||||
<input type="radio" name="isPrivate" value="false" checked>
|
||||
<strong>Public</strong><br>
|
||||
<div>
|
||||
<span class="note">All users and guests can read this repository.</span>
|
||||
</div>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label>
|
||||
<input type="radio" name="isPrivate" value="true">
|
||||
<strong>Private</strong><br>
|
||||
<div>
|
||||
<span class="note">Only collaborators can read this repository.</span>
|
||||
</div>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset class="margin">
|
||||
<label for="createReadme">
|
||||
<input type="checkbox" name="createReadme" id="createReadme"/>
|
||||
<strong>Initialize this repository with a README</strong>
|
||||
<div>
|
||||
<span class="note">This will allow you to <code>git clone</code> the repository immediately.</span>
|
||||
</div>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset class="margin">
|
||||
<input type="submit" class="btn btn-success" value="Create repository"/>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
}
|
||||
21
src/main/twirl/repo/guide.scala.html
Normal file
21
src/main/twirl/repo/guide.scala.html
Normal file
@@ -0,0 +1,21 @@
|
||||
@(repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
@html.main(repository.owner + "/" + repository.name) {
|
||||
@html.header("code", repository)
|
||||
<h3 style="margin-top: 30px;">Create a new repository on the command line</h3>
|
||||
<pre>
|
||||
touch README.md
|
||||
git init
|
||||
git add README.md
|
||||
git commit -m "first commit"
|
||||
git remote add origin @repository.url
|
||||
git push -u origin master
|
||||
</pre>
|
||||
|
||||
<h3 style="margin-top: 30px;">Push an existing repository from the command line</h3>
|
||||
<pre>
|
||||
git remote add origin @repository.url
|
||||
git push -u origin master
|
||||
</pre>
|
||||
}
|
||||
@@ -22,15 +22,22 @@
|
||||
</select>
|
||||
</fieldset>
|
||||
<hr>
|
||||
<fieldset>
|
||||
<label><strong>Repository Type</strong></label>
|
||||
<fieldset class="margin">
|
||||
<label>
|
||||
<input type="radio" name="isPrivate" value="false"@if(!repository.repository.isPrivate){ checked}>
|
||||
<strong>Public</strong> - All users and guests can read this repository.
|
||||
<input type="radio" name="isPrivate" value="false" checked>
|
||||
<strong>Public</strong><br>
|
||||
<div>
|
||||
<span class="note">All users and guests can read this repository.</span>
|
||||
</div>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label>
|
||||
<input type="radio" name="isPrivate" value="true"@if(repository.repository.isPrivate){ checked}>
|
||||
<strong>Private</strong> - Only collaborators can read this repository.
|
||||
<input type="radio" name="isPrivate" value="true">
|
||||
<strong>Private</strong><br>
|
||||
<div>
|
||||
<span class="note">Only collaborators can read this repository.</span>
|
||||
</div>
|
||||
</label>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
@@ -193,6 +193,19 @@ hr {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
span.note {
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
fieldset.margin {
|
||||
border-top: 1px solid #eee;
|
||||
margin-top: 10px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* Sign-in form */
|
||||
/****************************************************************************/
|
||||
div.signin-form {
|
||||
width: 350px;
|
||||
margin: 30px auto;
|
||||
|
||||
Reference in New Issue
Block a user