diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-16 21:30:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-16 21:30:11 +0800 |
commit | 48ccd325a1b81a58ac6d1d5d94fc4e90974599ea (patch) | |
tree | e7bb31d69343dd9845a1b0df013b093c8720f14b /modules/repository/init.go | |
parent | 447428f44659cee0e94e1c444f6291defac2bda2 (diff) | |
download | gitea-48ccd325a1b81a58ac6d1d5d94fc4e90974599ea.tar.gz gitea-48ccd325a1b81a58ac6d1d5d94fc4e90974599ea.zip |
Move some functions into services/repository (#17660)
Diffstat (limited to 'modules/repository/init.go')
-rw-r--r-- | modules/repository/init.go | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/modules/repository/init.go b/modules/repository/init.go index 5a1ff7e98b..076dbf748e 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -196,92 +196,6 @@ func checkInitRepository(owner, name string) (err error) { return nil } -func adoptRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { - isExist, err := util.IsExist(repoPath) - if err != nil { - log.Error("Unable to check if %s exists. Error: %v", repoPath, err) - return err - } - if !isExist { - return fmt.Errorf("adoptRepository: path does not already exist: %s", repoPath) - } - - if err := createDelegateHooks(repoPath); err != nil { - return fmt.Errorf("createDelegateHooks: %v", err) - } - - // Re-fetch the repository from database before updating it (else it would - // override changes that were done earlier with sql) - if repo, err = models.GetRepositoryByIDCtx(ctx, repo.ID); err != nil { - return fmt.Errorf("getRepositoryByID: %v", err) - } - - repo.IsEmpty = false - gitRepo, err := git.OpenRepository(repo.RepoPath()) - if err != nil { - return fmt.Errorf("openRepository: %v", err) - } - defer gitRepo.Close() - if len(opts.DefaultBranch) > 0 { - repo.DefaultBranch = opts.DefaultBranch - - if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { - return fmt.Errorf("setDefaultBranch: %v", err) - } - } else { - repo.DefaultBranch, err = gitRepo.GetDefaultBranch() - if err != nil { - repo.DefaultBranch = setting.Repository.DefaultBranch - if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { - return fmt.Errorf("setDefaultBranch: %v", err) - } - } - - repo.DefaultBranch = strings.TrimPrefix(repo.DefaultBranch, git.BranchPrefix) - } - branches, _, _ := gitRepo.GetBranches(0, 0) - found := false - hasDefault := false - hasMaster := false - hasMain := false - for _, branch := range branches { - if branch == repo.DefaultBranch { - found = true - break - } else if branch == setting.Repository.DefaultBranch { - hasDefault = true - } else if branch == "master" { - hasMaster = true - } else if branch == "main" { - hasMain = true - } - } - if !found { - if hasDefault { - repo.DefaultBranch = setting.Repository.DefaultBranch - } else if hasMaster { - repo.DefaultBranch = "master" - } else if hasMain { - repo.DefaultBranch = "main" - } else if len(branches) > 0 { - repo.DefaultBranch = branches[0] - } else { - repo.IsEmpty = true - repo.DefaultBranch = setting.Repository.DefaultBranch - } - - if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { - return fmt.Errorf("setDefaultBranch: %v", err) - } - } - - if err = models.UpdateRepositoryCtx(ctx, repo, false); err != nil { - return fmt.Errorf("updateRepository: %v", err) - } - - return nil -} - // InitRepository initializes README and .gitignore if needed. func initRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { if err = checkInitRepository(repo.OwnerName, repo.Name); err != nil { |