Option to set default branch at repository creation (#10803)

* Option to set default branch at repository creation
* Handle template repos with non-default master branch
* Add DefaultBranch handling on creation to API

Fix #9542

Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
zeripath 2020-03-26 19:14:51 +00:00 committed by GitHub
parent b1c331c845
commit 52cfd2743c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 57 additions and 33 deletions

View file

@ -113,7 +113,8 @@ func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmp
// Clone to temporary path and do the init commit.
templateRepoPath := templateRepo.RepoPath()
if err := git.Clone(templateRepoPath, tmpDir, git.CloneRepoOptions{
Depth: 1,
Depth: 1,
Branch: templateRepo.DefaultBranch,
}); err != nil {
return fmt.Errorf("git clone: %v", err)
}
@ -180,7 +181,7 @@ func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmp
return fmt.Errorf("git remote add: %v", err)
}
return initRepoCommit(tmpDir, repo, repo.Owner)
return initRepoCommit(tmpDir, repo, repo.Owner, templateRepo.DefaultBranch)
}
func generateGitContent(ctx models.DBContext, repo, templateRepo, generateRepo *models.Repository) (err error) {
@ -204,7 +205,7 @@ func generateGitContent(ctx models.DBContext, repo, templateRepo, generateRepo *
return fmt.Errorf("getRepositoryByID: %v", err)
}
repo.DefaultBranch = "master"
repo.DefaultBranch = templateRepo.DefaultBranch
if err = models.UpdateRepositoryCtx(ctx, repo, false); err != nil {
return fmt.Errorf("updateRepository: %v", err)
}