diff options
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/models/repo.go b/models/repo.go index cb040d5b..17c0082c 100644 --- a/models/repo.go +++ b/models/repo.go @@ -241,6 +241,14 @@ func (repo *Repository) ComposeMetas() map[string]string { return repo.ExternalMetas } +// DeleteWiki removes the actual and local copy of repository wiki. +func (repo *Repository) DeleteWiki() { + wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()} + for _, wikiPath := range wikiPaths { + RemoveAllWithNotice("Delete repository wiki", wikiPath) + } +} + // GetAssignees returns all users that have write access of repository. func (repo *Repository) GetAssignees() (_ []*User, err error) { if err = repo.GetOwner(); err != nil { @@ -662,6 +670,31 @@ func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) { return repo, fmt.Errorf("Clone: %v", err) } + // Check if repository is empty. + _, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1") + if err != nil { + if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") { + repo.IsBare = true + } else { + return repo, fmt.Errorf("check bare: %v - %s", err, stderr) + } + } + + if !repo.IsBare { + // Try to get HEAD branch and set it as default branch. + gitRepo, err := git.OpenRepository(repoPath) + if err != nil { + return repo, fmt.Errorf("OpenRepository: %v", err) + } + headBranch, err := gitRepo.GetHEADBranch() + if err != nil { + return repo, fmt.Errorf("GetHEADBranch: %v", err) + } + if headBranch != nil { + repo.DefaultBranch = headBranch.Name + } + } + if opts.IsMirror { if _, err = x.InsertOne(&Mirror{ RepoID: repo.ID, @@ -696,31 +729,6 @@ func CleanUpMigrateInfo(repo *Repository, repoPath string) (*Repository, error) return repo, fmt.Errorf("save config file: %v", err) } - // Check if repository is empty. - _, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1") - if err != nil { - if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") { - repo.IsBare = true - } else { - return repo, fmt.Errorf("check bare: %v - %s", err, stderr) - } - } - - // Try to get HEAD branch and set it as default branch. - gitRepo, err := git.OpenRepository(repoPath) - if err != nil { - log.Error(4, "OpenRepository: %v", err) - return repo, nil - } - headBranch, err := gitRepo.GetHEADBranch() - if err != nil { - log.Error(4, "GetHEADBranch: %v", err) - return repo, nil - } - if headBranch != nil { - repo.DefaultBranch = headBranch.Name - } - return repo, UpdateRepository(repo, false) } @@ -1335,10 +1343,7 @@ func DeleteRepository(uid, repoID int64) error { repoPath := repo.repoPath(sess) RemoveAllWithNotice("Delete repository files", repoPath) - wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()} - for _, wikiPath := range wikiPaths { - RemoveAllWithNotice("Delete repository wiki", wikiPath) - } + repo.DeleteWiki() // Remove attachment files. for i := range attachmentPaths { |