Add new initialize option as git commit -m "..." --allow-empty"

This commit is contained in:
KOUNOIKE Yuusuke
2018-01-28 18:59:39 +09:00
parent c8b6eb1bd9
commit 3793a51e3f
2 changed files with 22 additions and 12 deletions

View File

@@ -89,11 +89,13 @@ trait RepositoryCreationService {
val gitdir = getRepositoryDir(owner, name)
JGitUtil.initRepository(gitdir)
if (initOption == "README") {
if (initOption == "README" || initOption == "EMPTY_COMMIT") {
using(Git.open(gitdir)) { git =>
val builder = DirCache.newInCore.builder()
val inserter = git.getRepository.newObjectInserter()
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
if (initOption == "README") {
val content = if (description.nonEmpty) {
name + "\n" +
"===============\n" +
@@ -106,6 +108,7 @@ trait RepositoryCreationService {
builder.add(JGitUtil.createDirCacheEntry("README.md", FileMode.REGULAR_FILE,
inserter.insert(Constants.OBJ_BLOB, content.getBytes("UTF-8"))))
}
builder.finish()
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter),

View File

@@ -65,6 +65,13 @@ isCreateRepoOptionPublic: Boolean)(implicit context: gitbucket.core.controller.C
Create an empty repository. You have to initialize by yourself initially.
</div>
</label>
<label class="radio">
<input type="radio" name="initOption" value="EMPTY_COMMIT"/>
<span class="strong">Initialize this repository with an empty commit</span>
<div class="normal muted">
Create an empty repository with empty commit. You can clone the repository immediately.
</div>
</label>
<label class="radio">
<input type="radio" name="initOption" value="README"/>
<span class="strong">Initialize this repository with a README</span>