diff --git a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala index 9ed2205..852f9c0 100644 --- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala @@ -221,13 +221,22 @@ } } + val repositoryInfo = getRepository(owner, repository).get + + // Update default branch if repository is empty and pushed branch is not current default branch + if(JGitUtil.isEmpty(git) && commits.nonEmpty && branchName != repositoryInfo.repository.defaultBranch){ + saveRepositoryDefaultBranch(owner, repository, branchName) + // Change repository HEAD + using(Git.open(Directory.getRepositoryDir(owner, repository))) { git => + git.getRepository.updateRef(Constants.HEAD, true).link(Constants.R_HEADS + branchName) + } + } + // Retrieve all issue count in the repository val issueCount = countIssue(IssueSearchCondition(state = "open"), false, owner -> repository) + countIssue(IssueSearchCondition(state = "closed"), false, owner -> repository) - val repositoryInfo = getRepository(owner, repository).get - // Extract new commit and apply issue comment val defaultBranch = repositoryInfo.repository.defaultBranch val newCommits = commits.flatMap { commit =>