Don't create duplicated functions for code repositories and wiki repositories (#33924)

Fix
https://github.com/go-gitea/gitea/pull/33910#pullrequestreview-2688913865

This PR changed the Repositroy interface in `gitrepo` package which
makes it only focus the relative path in the disk and abstract whether
it's a wiki repository or not.
This commit is contained in:
Lunny Xiao
2025-03-19 11:17:19 -07:00
committed by GitHub
parent e25f860735
commit a9e8ac0fe0
20 changed files with 56 additions and 77 deletions

View File

@ -215,12 +215,24 @@ func init() {
db.RegisterModel(new(Repository)) db.RegisterModel(new(Repository))
} }
func (repo *Repository) GetName() string { func RelativePath(ownerName, repoName string) string {
return repo.Name return strings.ToLower(ownerName) + "/" + strings.ToLower(repoName) + ".git"
} }
func (repo *Repository) GetOwnerName() string { // RelativePath should be an unix style path like username/reponame.git
return repo.OwnerName func (repo *Repository) RelativePath() string {
return RelativePath(repo.OwnerName, repo.Name)
}
type StorageRepo string
// RelativePath should be an unix style path like username/reponame.git
func (sr StorageRepo) RelativePath() string {
return string(sr)
}
func (repo *Repository) WikiStorageRepo() StorageRepo {
return StorageRepo(strings.ToLower(repo.OwnerName) + "/" + strings.ToLower(repo.Name) + ".wiki.git")
} }
// SanitizedOriginalURL returns a sanitized OriginalURL // SanitizedOriginalURL returns a sanitized OriginalURL

View File

@ -44,24 +44,12 @@ func GetDefaultBranch(ctx context.Context, repo Repository) (string, error) {
return git.GetDefaultBranch(ctx, repoPath(repo)) return git.GetDefaultBranch(ctx, repoPath(repo))
} }
func GetWikiDefaultBranch(ctx context.Context, repo Repository) (string, error) {
return git.GetDefaultBranch(ctx, wikiPath(repo))
}
// IsReferenceExist returns true if given reference exists in the repository. // IsReferenceExist returns true if given reference exists in the repository.
func IsReferenceExist(ctx context.Context, repo Repository, name string) bool { func IsReferenceExist(ctx context.Context, repo Repository, name string) bool {
return git.IsReferenceExist(ctx, repoPath(repo), name) return git.IsReferenceExist(ctx, repoPath(repo), name)
} }
func IsWikiReferenceExist(ctx context.Context, repo Repository, name string) bool {
return git.IsReferenceExist(ctx, wikiPath(repo), name)
}
// IsBranchExist returns true if given branch exists in the repository. // IsBranchExist returns true if given branch exists in the repository.
func IsBranchExist(ctx context.Context, repo Repository, name string) bool { func IsBranchExist(ctx context.Context, repo Repository, name string) bool {
return IsReferenceExist(ctx, repo, git.BranchPrefix+name) return IsReferenceExist(ctx, repo, git.BranchPrefix+name)
} }
func IsWikiBranchExist(ctx context.Context, repo Repository, name string) bool {
return IsWikiReferenceExist(ctx, repo, git.BranchPrefix+name)
}

View File

@ -8,7 +8,6 @@ import (
"fmt" "fmt"
"io" "io"
"path/filepath" "path/filepath"
"strings"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/reqctx" "code.gitea.io/gitea/modules/reqctx"
@ -16,21 +15,15 @@ import (
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
) )
// Repository represents a git repository which stored in a disk
type Repository interface { type Repository interface {
GetName() string RelativePath() string // We don't assume how the directory structure of the repository is, so we only need the relative path
GetOwnerName() string
}
func absPath(owner, name string) string {
return filepath.Join(setting.RepoRootPath, strings.ToLower(owner), strings.ToLower(name)+".git")
} }
// RelativePath should be an unix style path like username/reponame.git
// This method should change it according to the current OS.
func repoPath(repo Repository) string { func repoPath(repo Repository) string {
return absPath(repo.GetOwnerName(), repo.GetName()) return filepath.Join(setting.RepoRootPath, filepath.FromSlash(repo.RelativePath()))
}
func wikiPath(repo Repository) string {
return filepath.Join(setting.RepoRootPath, strings.ToLower(repo.GetOwnerName()), strings.ToLower(repo.GetName())+".wiki.git")
} }
// OpenRepository opens the repository at the given relative path with the provided context. // OpenRepository opens the repository at the given relative path with the provided context.
@ -38,10 +31,6 @@ func OpenRepository(ctx context.Context, repo Repository) (*git.Repository, erro
return git.OpenRepository(ctx, repoPath(repo)) return git.OpenRepository(ctx, repoPath(repo))
} }
func OpenWikiRepository(ctx context.Context, repo Repository) (*git.Repository, error) {
return git.OpenRepository(ctx, wikiPath(repo))
}
// contextKey is a value for use with context.WithValue. // contextKey is a value for use with context.WithValue.
type contextKey struct { type contextKey struct {
repoPath string repoPath string
@ -86,9 +75,8 @@ func DeleteRepository(ctx context.Context, repo Repository) error {
} }
// RenameRepository renames a repository's name on disk // RenameRepository renames a repository's name on disk
func RenameRepository(ctx context.Context, repo Repository, newName string) error { func RenameRepository(ctx context.Context, repo, newRepo Repository) error {
newRepoPath := absPath(repo.GetOwnerName(), newName) if err := util.Rename(repoPath(repo), repoPath(newRepo)); err != nil {
if err := util.Rename(repoPath(repo), newRepoPath); err != nil {
return fmt.Errorf("rename repository directory: %w", err) return fmt.Errorf("rename repository directory: %w", err)
} }
return nil return nil

View File

@ -106,16 +106,11 @@ done
return hookNames, hookTpls, giteaHookTpls return hookNames, hookTpls, giteaHookTpls
} }
// CreateDelegateHooksForRepo creates all the hooks scripts for the repo // CreateDelegateHooks creates all the hooks scripts for the repo
func CreateDelegateHooksForRepo(_ context.Context, repo Repository) (err error) { func CreateDelegateHooks(_ context.Context, repo Repository) (err error) {
return createDelegateHooks(filepath.Join(repoPath(repo), "hooks")) return createDelegateHooks(filepath.Join(repoPath(repo), "hooks"))
} }
// CreateDelegateHooksForWiki creates all the hooks scripts for the wiki repo
func CreateDelegateHooksForWiki(_ context.Context, repo Repository) (err error) {
return createDelegateHooks(filepath.Join(wikiPath(repo), "hooks"))
}
func createDelegateHooks(hookDir string) (err error) { func createDelegateHooks(hookDir string) (err error) {
hookNames, hookTpls, giteaHookTpls := getHookTemplates() hookNames, hookTpls, giteaHookTpls := getHookTemplates()
@ -178,16 +173,11 @@ func ensureExecutable(filename string) error {
return os.Chmod(filename, mode) return os.Chmod(filename, mode)
} }
// CheckDelegateHooksForRepo checks the hooks scripts for the repo // CheckDelegateHooks checks the hooks scripts for the repo
func CheckDelegateHooksForRepo(_ context.Context, repo Repository) ([]string, error) { func CheckDelegateHooks(_ context.Context, repo Repository) ([]string, error) {
return checkDelegateHooks(filepath.Join(repoPath(repo), "hooks")) return checkDelegateHooks(filepath.Join(repoPath(repo), "hooks"))
} }
// CheckDelegateHooksForWiki checks the hooks scripts for the repo
func CheckDelegateHooksForWiki(_ context.Context, repo Repository) ([]string, error) {
return checkDelegateHooks(filepath.Join(wikiPath(repo), "hooks"))
}
func checkDelegateHooks(hookDir string) ([]string, error) { func checkDelegateHooks(hookDir string) ([]string, error) {
hookNames, hookTpls, giteaHookTpls := getHookTemplates() hookNames, hookTpls, giteaHookTpls := getHookTemplates()

View File

@ -138,7 +138,7 @@ func CheckInitRepository(ctx context.Context, repo *repo_model.Repository) (err
// Init git bare new repository. // Init git bare new repository.
if err = git.InitRepository(ctx, repo.RepoPath(), true, repo.ObjectFormatName); err != nil { if err = git.InitRepository(ctx, repo.RepoPath(), true, repo.ObjectFormatName); err != nil {
return fmt.Errorf("git.InitRepository: %w", err) return fmt.Errorf("git.InitRepository: %w", err)
} else if err = gitrepo.CreateDelegateHooksForRepo(ctx, repo); err != nil { } else if err = gitrepo.CreateDelegateHooks(ctx, repo); err != nil {
return fmt.Errorf("createDelegateHooks: %w", err) return fmt.Errorf("createDelegateHooks: %w", err)
} }
return nil return nil

View File

@ -476,7 +476,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
// findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error. // findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error.
// The caller is responsible for closing the returned repo again // The caller is responsible for closing the returned repo again
func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) { func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) {
wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) wikiRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository.WikiStorageRepo())
if err != nil { if err != nil {
if git.IsErrNotExist(err) || err.Error() == "no such file or directory" { if git.IsErrNotExist(err) || err.Error() == "no such file or directory" {
ctx.APIErrorNotFound(err) ctx.APIErrorNotFound(err)

View File

@ -284,7 +284,7 @@ func Diff(ctx *context.Context) {
) )
if ctx.Data["PageIsWiki"] != nil { if ctx.Data["PageIsWiki"] != nil {
gitRepo, err = gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) gitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository.WikiStorageRepo())
if err != nil { if err != nil {
ctx.ServerError("Repo.GitRepo.GetCommit", err) ctx.ServerError("Repo.GitRepo.GetCommit", err)
return return
@ -417,7 +417,7 @@ func Diff(ctx *context.Context) {
func RawDiff(ctx *context.Context) { func RawDiff(ctx *context.Context) {
var gitRepo *git.Repository var gitRepo *git.Repository
if ctx.Data["PageIsWiki"] != nil { if ctx.Data["PageIsWiki"] != nil {
wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) wikiRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository.WikiStorageRepo())
if err != nil { if err != nil {
ctx.ServerError("OpenRepository", err) ctx.ServerError("OpenRepository", err)
return return

View File

@ -885,7 +885,7 @@ func ExcerptBlob(ctx *context.Context) {
gitRepo := ctx.Repo.GitRepo gitRepo := ctx.Repo.GitRepo
if ctx.Data["PageIsWiki"] == true { if ctx.Data["PageIsWiki"] == true {
var err error var err error
gitRepo, err = gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) gitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository.WikiStorageRepo())
if err != nil { if err != nil {
ctx.ServerError("OpenRepository", err) ctx.ServerError("OpenRepository", err)
return return

View File

@ -96,7 +96,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
} }
func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) { func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
wikiGitRepo, errGitRepo := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository) wikiGitRepo, errGitRepo := gitrepo.OpenRepository(ctx, ctx.Repo.Repository.WikiStorageRepo())
if errGitRepo != nil { if errGitRepo != nil {
ctx.ServerError("OpenRepository", errGitRepo) ctx.ServerError("OpenRepository", errGitRepo)
return nil, nil, errGitRepo return nil, nil, errGitRepo
@ -105,7 +105,7 @@ func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, err
commit, errCommit := wikiGitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultWikiBranch) commit, errCommit := wikiGitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultWikiBranch)
if git.IsErrNotExist(errCommit) { if git.IsErrNotExist(errCommit) {
// if the default branch recorded in database is out of sync, then re-sync it // if the default branch recorded in database is out of sync, then re-sync it
gitRepoDefaultBranch, errBranch := gitrepo.GetWikiDefaultBranch(ctx, ctx.Repo.Repository) gitRepoDefaultBranch, errBranch := gitrepo.GetDefaultBranch(ctx, ctx.Repo.Repository.WikiStorageRepo())
if errBranch != nil { if errBranch != nil {
return wikiGitRepo, nil, errBranch return wikiGitRepo, nil, errBranch
} }

View File

@ -29,7 +29,7 @@ const (
) )
func wikiEntry(t *testing.T, repo *repo_model.Repository, wikiName wiki_service.WebPath) *git.TreeEntry { func wikiEntry(t *testing.T, repo *repo_model.Repository, wikiName wiki_service.WebPath) *git.TreeEntry {
wikiRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo) wikiRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo.WikiStorageRepo())
assert.NoError(t, err) assert.NoError(t, err)
defer wikiRepo.Close() defer wikiRepo.Close()
commit, err := wikiRepo.GetBranchCommit("master") commit, err := wikiRepo.GetBranchCommit("master")

View File

@ -204,7 +204,7 @@ Loop:
return false, "", nil, &ErrWontSign{twofa} return false, "", nil, &ErrWontSign{twofa}
} }
case parentSigned: case parentSigned:
gitRepo, err := gitrepo.OpenWikiRepository(ctx, repo) gitRepo, err := gitrepo.OpenRepository(ctx, repo.WikiStorageRepo())
if err != nil { if err != nil {
return false, "", nil, err return false, "", nil, err
} }

View File

@ -49,14 +49,14 @@ func checkScriptType(ctx context.Context, logger log.Logger, autofix bool) error
func checkHooks(ctx context.Context, logger log.Logger, autofix bool) error { func checkHooks(ctx context.Context, logger log.Logger, autofix bool) error {
if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error { if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
results, err := gitrepo.CheckDelegateHooksForRepo(ctx, repo) results, err := gitrepo.CheckDelegateHooks(ctx, repo)
if err != nil { if err != nil {
logger.Critical("Unable to check delegate hooks for repo %-v. ERROR: %v", repo, err) logger.Critical("Unable to check delegate hooks for repo %-v. ERROR: %v", repo, err)
return fmt.Errorf("Unable to check delegate hooks for repo %-v. ERROR: %w", repo, err) return fmt.Errorf("Unable to check delegate hooks for repo %-v. ERROR: %w", repo, err)
} }
if len(results) > 0 && autofix { if len(results) > 0 && autofix {
logger.Warn("Regenerated hooks for %s", repo.FullName()) logger.Warn("Regenerated hooks for %s", repo.FullName())
if err := gitrepo.CreateDelegateHooksForRepo(ctx, repo); err != nil { if err := gitrepo.CreateDelegateHooks(ctx, repo); err != nil {
logger.Critical("Unable to recreate delegate hooks for %-v. ERROR: %v", repo, err) logger.Critical("Unable to recreate delegate hooks for %-v. ERROR: %v", repo, err)
return fmt.Errorf("Unable to recreate delegate hooks for %-v. ERROR: %w", repo, err) return fmt.Errorf("Unable to recreate delegate hooks for %-v. ERROR: %w", repo, err)
} }

View File

@ -143,7 +143,7 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
var gitRepo *git.Repository var gitRepo *git.Repository
if isWiki { if isWiki {
gitRepo, err = gitrepo.OpenWikiRepository(ctx, repo) gitRepo, err = gitrepo.OpenRepository(ctx, repo.WikiStorageRepo())
} else { } else {
gitRepo, err = gitrepo.OpenRepository(ctx, repo) gitRepo, err = gitrepo.OpenRepository(ctx, repo)
} }

View File

@ -115,7 +115,7 @@ func adoptRepository(ctx context.Context, repo *repo_model.Repository, defaultBr
return fmt.Errorf("adoptRepository: path does not already exist: %s", repo.FullName()) return fmt.Errorf("adoptRepository: path does not already exist: %s", repo.FullName())
} }
if err := gitrepo.CreateDelegateHooksForRepo(ctx, repo); err != nil { if err := gitrepo.CreateDelegateHooks(ctx, repo); err != nil {
return fmt.Errorf("createDelegateHooks: %w", err) return fmt.Errorf("createDelegateHooks: %w", err)
} }

View File

@ -170,7 +170,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
return fmt.Errorf("git update-server-info: %w", err) return fmt.Errorf("git update-server-info: %w", err)
} }
if err = gitrepo.CreateDelegateHooksForRepo(ctx, repo); err != nil { if err = gitrepo.CreateDelegateHooks(ctx, repo); err != nil {
return fmt.Errorf("createDelegateHooks: %w", err) return fmt.Errorf("createDelegateHooks: %w", err)
} }

View File

@ -31,11 +31,11 @@ func SyncRepositoryHooks(ctx context.Context) error {
default: default:
} }
if err := gitrepo.CreateDelegateHooksForRepo(ctx, repo); err != nil { if err := gitrepo.CreateDelegateHooks(ctx, repo); err != nil {
return fmt.Errorf("SyncRepositoryHook: %w", err) return fmt.Errorf("SyncRepositoryHook: %w", err)
} }
if repo.HasWiki() { if repo.HasWiki() {
if err := gitrepo.CreateDelegateHooksForWiki(ctx, repo); err != nil { if err := gitrepo.CreateDelegateHooks(ctx, repo.WikiStorageRepo()); err != nil {
return fmt.Errorf("SyncRepositoryHook: %w", err) return fmt.Errorf("SyncRepositoryHook: %w", err)
} }
} }

View File

@ -265,11 +265,11 @@ func cleanUpMigrateGitConfig(ctx context.Context, repoPath string) error {
// CleanUpMigrateInfo finishes migrating repository and/or wiki with things that don't need to be done for mirrors. // CleanUpMigrateInfo finishes migrating repository and/or wiki with things that don't need to be done for mirrors.
func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo_model.Repository, error) { func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo_model.Repository, error) {
if err := gitrepo.CreateDelegateHooksForRepo(ctx, repo); err != nil { if err := gitrepo.CreateDelegateHooks(ctx, repo); err != nil {
return repo, fmt.Errorf("createDelegateHooks: %w", err) return repo, fmt.Errorf("createDelegateHooks: %w", err)
} }
if repo.HasWiki() { if repo.HasWiki() {
if err := gitrepo.CreateDelegateHooksForWiki(ctx, repo); err != nil { if err := gitrepo.CreateDelegateHooks(ctx, repo.WikiStorageRepo()); err != nil {
return repo, fmt.Errorf("createDelegateHooks.(wiki): %w", err) return repo, fmt.Errorf("createDelegateHooks.(wiki): %w", err)
} }
} }

View File

@ -331,12 +331,13 @@ func changeRepositoryName(ctx context.Context, repo *repo_model.Repository, newR
return fmt.Errorf("IsRepositoryExist: %w", err) return fmt.Errorf("IsRepositoryExist: %w", err)
} else if has { } else if has {
return repo_model.ErrRepoAlreadyExist{ return repo_model.ErrRepoAlreadyExist{
Uname: repo.Owner.Name, Uname: repo.OwnerName,
Name: newRepoName, Name: newRepoName,
} }
} }
if err = gitrepo.RenameRepository(ctx, repo, newRepoName); err != nil { if err = gitrepo.RenameRepository(ctx, repo,
repo_model.StorageRepo(repo_model.RelativePath(repo.OwnerName, newRepoName))); err != nil {
return fmt.Errorf("rename repository directory: %w", err) return fmt.Errorf("rename repository directory: %w", err)
} }

View File

@ -41,7 +41,7 @@ func InitWiki(ctx context.Context, repo *repo_model.Repository) error {
if err := git.InitRepository(ctx, repo.WikiPath(), true, repo.ObjectFormatName); err != nil { if err := git.InitRepository(ctx, repo.WikiPath(), true, repo.ObjectFormatName); err != nil {
return fmt.Errorf("InitRepository: %w", err) return fmt.Errorf("InitRepository: %w", err)
} else if err = gitrepo.CreateDelegateHooksForWiki(ctx, repo); err != nil { } else if err = gitrepo.CreateDelegateHooks(ctx, repo.WikiStorageRepo()); err != nil {
return fmt.Errorf("createDelegateHooks: %w", err) return fmt.Errorf("createDelegateHooks: %w", err)
} else if _, _, err = git.NewCommand("symbolic-ref", "HEAD").AddDynamicArguments(git.BranchPrefix+repo.DefaultWikiBranch).RunStdString(ctx, &git.RunOpts{Dir: repo.WikiPath()}); err != nil { } else if _, _, err = git.NewCommand("symbolic-ref", "HEAD").AddDynamicArguments(git.BranchPrefix+repo.DefaultWikiBranch).RunStdString(ctx, &git.RunOpts{Dir: repo.WikiPath()}); err != nil {
return fmt.Errorf("unable to set default wiki branch to %q: %w", repo.DefaultWikiBranch, err) return fmt.Errorf("unable to set default wiki branch to %q: %w", repo.DefaultWikiBranch, err)
@ -100,7 +100,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
return fmt.Errorf("InitWiki: %w", err) return fmt.Errorf("InitWiki: %w", err)
} }
hasDefaultBranch := gitrepo.IsWikiBranchExist(ctx, repo, repo.DefaultWikiBranch) hasDefaultBranch := gitrepo.IsBranchExist(ctx, repo.WikiStorageRepo(), repo.DefaultWikiBranch)
basePath, err := repo_module.CreateTemporaryPath("update-wiki") basePath, err := repo_module.CreateTemporaryPath("update-wiki")
if err != nil { if err != nil {
@ -381,7 +381,7 @@ func ChangeDefaultWikiBranch(ctx context.Context, repo *repo_model.Repository, n
return nil return nil
} }
oldDefBranch, err := gitrepo.GetWikiDefaultBranch(ctx, repo) oldDefBranch, err := gitrepo.GetDefaultBranch(ctx, repo.WikiStorageRepo())
if err != nil { if err != nil {
return fmt.Errorf("unable to get default branch: %w", err) return fmt.Errorf("unable to get default branch: %w", err)
} }
@ -389,7 +389,7 @@ func ChangeDefaultWikiBranch(ctx context.Context, repo *repo_model.Repository, n
return nil return nil
} }
gitRepo, err := gitrepo.OpenWikiRepository(ctx, repo) gitRepo, err := gitrepo.OpenRepository(ctx, repo.WikiStorageRepo())
if errors.Is(err, util.ErrNotExist) { if errors.Is(err, util.ErrNotExist) {
return nil // no git repo on storage, no need to do anything else return nil // no git repo on storage, no need to do anything else
} else if err != nil { } else if err != nil {

View File

@ -166,7 +166,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
webPath := UserTitleToWebPath("", userTitle) webPath := UserTitleToWebPath("", userTitle)
assert.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, webPath, wikiContent, commitMsg)) assert.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, webPath, wikiContent, commitMsg))
// Now need to show that the page has been added: // Now need to show that the page has been added:
gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo) gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo.WikiStorageRepo())
require.NoError(t, err) require.NoError(t, err)
defer gitRepo.Close() defer gitRepo.Close()
@ -213,7 +213,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
assert.NoError(t, EditWikiPage(git.DefaultContext, doer, repo, "Home", webPath, newWikiContent, commitMsg)) assert.NoError(t, EditWikiPage(git.DefaultContext, doer, repo, "Home", webPath, newWikiContent, commitMsg))
// Now need to show that the page has been added: // Now need to show that the page has been added:
gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo) gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo.WikiStorageRepo())
assert.NoError(t, err) assert.NoError(t, err)
masterTree, err := gitRepo.GetTree(repo.DefaultWikiBranch) masterTree, err := gitRepo.GetTree(repo.DefaultWikiBranch)
assert.NoError(t, err) assert.NoError(t, err)
@ -237,7 +237,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
assert.NoError(t, DeleteWikiPage(git.DefaultContext, doer, repo, "Home")) assert.NoError(t, DeleteWikiPage(git.DefaultContext, doer, repo, "Home"))
// Now need to show that the page has been added: // Now need to show that the page has been added:
gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo) gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo.WikiStorageRepo())
require.NoError(t, err) require.NoError(t, err)
defer gitRepo.Close() defer gitRepo.Close()
@ -251,7 +251,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
func TestPrepareWikiFileName(t *testing.T) { func TestPrepareWikiFileName(t *testing.T) {
unittest.PrepareTestEnv(t) unittest.PrepareTestEnv(t)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo) gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo.WikiStorageRepo())
require.NoError(t, err) require.NoError(t, err)
defer gitRepo.Close() defer gitRepo.Close()