diff --git a/src/main/scala/app/CreateRepositoryController.scala b/src/main/scala/app/CreateRepositoryController.scala index a74031d..1e51caa 100644 --- a/src/main/scala/app/CreateRepositoryController.scala +++ b/src/main/scala/app/CreateRepositoryController.scala @@ -20,11 +20,13 @@ 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()))) + "name" -> trim(label("Repository name", text(required, maxlength(40), identifier, unique))), + "description" -> trim(label("Description" , optional(text()))), + "isPrivate" -> trim(label("Repository Type", boolean())), + "createReadme" -> trim(label("Create README" , boolean())) )(RepositoryCreationForm.apply) /** @@ -42,7 +44,7 @@ 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,26 +64,28 @@ config.setBoolean("http", null, "receivepack", true) config.save - val tmpdir = getInitRepositoryDir(loginUserName, form.name) - try { - // Clone the repository - Git.cloneRepository.setURI(gitdir.toURI.toString).setDirectory(tmpdir).call - - // Create README.md - FileUtils.writeStringToFile(new File(tmpdir, "README.md"), - if(form.description.nonEmpty){ - form.name + "\n===============\n\n" + form.description.get - } else { - form.name + "\n===============\n" - }, "UTF-8") - - val git = Git.open(tmpdir) - git.add.addFilepattern("README.md").call - git.commit.setMessage("Initial commit").call - git.push.call - - } finally { - FileUtils.deleteDirectory(tmpdir) + if(form.createReadme){ + val tmpdir = getInitRepositoryDir(loginUserName, form.name) + try { + // Clone the repository + Git.cloneRepository.setURI(gitdir.toURI.toString).setDirectory(tmpdir).call + + // Create README.md + FileUtils.writeStringToFile(new File(tmpdir, "README.md"), + if(form.description.nonEmpty){ + form.name + "\n===============\n\n" + form.description.get + } else { + form.name + "\n===============\n" + }, "UTF-8") + + val git = Git.open(tmpdir) + git.add.addFilepattern("README.md").call + git.commit.setMessage("Initial commit").call + git.push.call + + } finally { + FileUtils.deleteDirectory(tmpdir) + } } // Create Wiki repository diff --git a/src/main/scala/app/RepositoryViewerController.scala b/src/main/scala/app/RepositoryViewerController.scala index be5b36d..2d1b6a3 100644 --- a/src/main/scala/app/RepositoryViewerController.scala +++ b/src/main/scala/app/RepositoryViewerController.scala @@ -210,37 +210,36 @@ * @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)) + 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") + } - 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") + repo.html.files( + // current branch + revision, + // repository + repository, + // current path + if(path == ".") Nil else path.split("/").toList, + // latest commit + new JGitUtil.CommitInfo(revCommit), + // file list + files, + // readme + readme + ) } - - repo.html.files( - // current branch - revision, - // repository - repository, - // current path - if(path == ".") Nil else path.split("/").toList, - // latest commit - new JGitUtil.CommitInfo(revCommit), - // file list - files, - // readme - readme - ) } } diff --git a/src/main/scala/service/RepositoryService.scala b/src/main/scala/service/RepositoryService.scala index adb9157..153aa95 100644 --- a/src/main/scala/service/RepositoryService.scala +++ b/src/main/scala/service/RepositoryService.scala @@ -11,19 +11,17 @@ /** * 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, diff --git a/src/main/scala/util/JGitUtil.scala b/src/main/scala/util/JGitUtil.scala index dc094bd..e69fcd3 100644 --- a/src/main/scala/util/JGitUtil.scala +++ b/src/main/scala/util/JGitUtil.scala @@ -14,6 +14,7 @@ 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,28 +143,35 @@ */ def getRepositoryInfo(owner: String, repository: String, baseUrl: String): RepositoryInfo = { withGit(getRepositoryDir(owner, repository)){ git => - // get commit count - val i = git.log.all.call.iterator - var commitCount = 0 - while(i.hasNext && commitCount <= 1000){ - i.next - commitCount = commitCount + 1 - } + try { + // get commit count + val i = git.log.all.call.iterator + var commitCount = 0 + while(i.hasNext && commitCount <= 1000){ + i.next + commitCount = commitCount + 1 + } - RepositoryInfo( - owner, repository, baseUrl + "/git/%s/%s.git".format(owner, repository), - // commit count - commitCount, - // branches - git.branchList.call.asScala.map { ref => - ref.getName.replaceFirst("^refs/heads/", "") - }.toList, - // tags - git.tagList.call.asScala.map { ref => - val revCommit = getRevCommitFromId(git, ref.getObjectId) - TagInfo(ref.getName.replaceFirst("^refs/tags/", ""), revCommit.getCommitterIdent.getWhen, revCommit.getName) - }.toList - ) + RepositoryInfo( + owner, repository, baseUrl + "/git/%s/%s.git".format(owner, repository), + // commit count + commitCount, + // branches + git.branchList.call.asScala.map { ref => + ref.getName.replaceFirst("^refs/heads/", "") + }.toList, + // tags + git.tagList.call.asScala.map { ref => + val revCommit = getRevCommitFromId(git, ref.getObjectId) + 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) + + } } } diff --git a/src/main/twirl/newrepo.scala.html b/src/main/twirl/newrepo.scala.html index ada4715..6cec56f 100644 --- a/src/main/twirl/newrepo.scala.html +++ b/src/main/twirl/newrepo.scala.html @@ -1,6 +1,7 @@ @()(implicit context: app.Context) @import context._ @main("Create a New Repository"){ +
@@ -9,10 +10,38 @@
- + +
+
+
+ +
+
+ +
+
-} \ No newline at end of file +
+} diff --git a/src/main/twirl/repo/guide.scala.html b/src/main/twirl/repo/guide.scala.html new file mode 100644 index 0000000..a51b7c5 --- /dev/null +++ b/src/main/twirl/repo/guide.scala.html @@ -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) +

Create a new repository on the command line

+
+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
+
+ +

Push an existing repository from the command line

+
+git remote add origin @repository.url
+git push -u origin master
+
+} diff --git a/src/main/twirl/settings/options.scala.html b/src/main/twirl/settings/options.scala.html index 1c075e2..5426d75 100644 --- a/src/main/twirl/settings/options.scala.html +++ b/src/main/twirl/settings/options.scala.html @@ -22,17 +22,24 @@
-
- - - -
+
+ +
+
+ +
@* diff --git a/src/main/webapp/assets/common/css/gitbucket.css b/src/main/webapp/assets/common/css/gitbucket.css index d9af09b..8a35e0c 100644 --- a/src/main/webapp/assets/common/css/gitbucket.css +++ b/src/main/webapp/assets/common/css/gitbucket.css @@ -193,6 +193,19 @@ 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;