mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 06:24:11 +01:00 
			
		
		
		
	Remove HasWiki method
This commit is contained in:
		
							parent
							
								
									18bd70054b
								
							
						
					
					
						commit
						ce4f8f4f13
					
				@ -11,7 +11,6 @@ import (
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	user_model "code.gitea.io/gitea/models/user"
 | 
			
		||||
	"code.gitea.io/gitea/modules/log"
 | 
			
		||||
	"code.gitea.io/gitea/modules/util"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -86,12 +85,3 @@ func WikiPath(userName, repoName string) string {
 | 
			
		||||
func (repo *Repository) WikiPath() string {
 | 
			
		||||
	return WikiPath(repo.OwnerName, repo.Name)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// HasWiki returns true if repository has wiki.
 | 
			
		||||
func (repo *Repository) HasWiki() bool {
 | 
			
		||||
	isDir, err := util.IsDir(repo.WikiPath())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error("Unable to check if %s is a directory: %v", repo.WikiPath(), err)
 | 
			
		||||
	}
 | 
			
		||||
	return isDir
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	repo_model "code.gitea.io/gitea/models/repo"
 | 
			
		||||
	"code.gitea.io/gitea/models/unittest"
 | 
			
		||||
	"code.gitea.io/gitea/modules/gitrepo"
 | 
			
		||||
	"code.gitea.io/gitea/modules/setting"
 | 
			
		||||
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
@ -39,7 +40,12 @@ func TestRepository_WikiPath(t *testing.T) {
 | 
			
		||||
func TestRepository_HasWiki(t *testing.T) {
 | 
			
		||||
	unittest.PrepareTestEnv(t)
 | 
			
		||||
	repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
 | 
			
		||||
	assert.True(t, repo1.HasWiki())
 | 
			
		||||
	exist, err := gitrepo.IsWikiRepositoryExist(t.Context(), repo1)
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.True(t, exist)
 | 
			
		||||
 | 
			
		||||
	repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
 | 
			
		||||
	assert.False(t, repo2.HasWiki())
 | 
			
		||||
	exist, err = gitrepo.IsWikiRepositoryExist(t.Context(), repo2)
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.False(t, exist)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -29,19 +29,11 @@ func repoPath(repo Repository) string {
 | 
			
		||||
	return absPath(repo.GetOwnerName(), repo.GetName())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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.
 | 
			
		||||
func OpenRepository(ctx context.Context, repo Repository) (*git.Repository, error) {
 | 
			
		||||
	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.
 | 
			
		||||
type contextKey struct {
 | 
			
		||||
	repoPath string
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										46
									
								
								modules/gitrepo/wiki.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								modules/gitrepo/wiki.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
			
		||||
// Copyright 2025 The Gitea Authors. All rights reserved.
 | 
			
		||||
// SPDX-License-Identifier: MIT
 | 
			
		||||
 | 
			
		||||
package gitrepo
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/modules/git"
 | 
			
		||||
	"code.gitea.io/gitea/modules/setting"
 | 
			
		||||
	"code.gitea.io/gitea/modules/util"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func absWikiPath(owner, name string) string {
 | 
			
		||||
	return filepath.Join(setting.RepoRootPath, strings.ToLower(owner), strings.ToLower(name)+".wiki.git")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func wikiPath(repo Repository) string {
 | 
			
		||||
	return absWikiPath(repo.GetOwnerName(), repo.GetName())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func OpenWikiRepository(ctx context.Context, repo Repository) (*git.Repository, error) {
 | 
			
		||||
	return git.OpenRepository(ctx, wikiPath(repo))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsWikiRepositoryExist returns true if the repository directory exists in the disk
 | 
			
		||||
func IsWikiRepositoryExist(ctx context.Context, repo Repository) (bool, error) {
 | 
			
		||||
	return util.IsExist(wikiPath(repo))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RenameRepository renames a repository's name on disk
 | 
			
		||||
func RenameWikiRepository(ctx context.Context, repo Repository, newName string) error {
 | 
			
		||||
	newRepoPath := absWikiPath(repo.GetOwnerName(), newName)
 | 
			
		||||
	if err := util.Rename(wikiPath(repo), newRepoPath); err != nil {
 | 
			
		||||
		return fmt.Errorf("rename repository directory: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DeleteWikiRepository deletes the repository directory from the disk
 | 
			
		||||
func DeleteWikiRepository(ctx context.Context, repo Repository) error {
 | 
			
		||||
	return util.RemoveAll(wikiPath(repo))
 | 
			
		||||
}
 | 
			
		||||
@ -557,7 +557,12 @@ func Wiki(ctx *context.Context) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !ctx.Repo.Repository.HasWiki() {
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, ctx.Repo.Repository)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.ServerError("IsWikiRepositoryExist", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if !hasWiki {
 | 
			
		||||
		ctx.Data["Title"] = ctx.Tr("repo.wiki")
 | 
			
		||||
		ctx.HTML(http.StatusOK, tplWikiStart)
 | 
			
		||||
		return
 | 
			
		||||
@ -598,7 +603,12 @@ func Wiki(ctx *context.Context) {
 | 
			
		||||
func WikiRevision(ctx *context.Context) {
 | 
			
		||||
	ctx.Data["CanWriteWiki"] = ctx.Repo.CanWrite(unit.TypeWiki) && !ctx.Repo.Repository.IsArchived
 | 
			
		||||
 | 
			
		||||
	if !ctx.Repo.Repository.HasWiki() {
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, ctx.Repo.Repository)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.ServerError("IsWikiRepositoryExist", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if !hasWiki {
 | 
			
		||||
		ctx.Data["Title"] = ctx.Tr("repo.wiki")
 | 
			
		||||
		ctx.HTML(http.StatusOK, tplWikiStart)
 | 
			
		||||
		return
 | 
			
		||||
@ -634,7 +644,12 @@ func WikiRevision(ctx *context.Context) {
 | 
			
		||||
 | 
			
		||||
// WikiPages render wiki pages list page
 | 
			
		||||
func WikiPages(ctx *context.Context) {
 | 
			
		||||
	if !ctx.Repo.Repository.HasWiki() {
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, ctx.Repo.Repository)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.ServerError("IsWikiRepositoryExist", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if !hasWiki {
 | 
			
		||||
		ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
@ -753,7 +768,12 @@ func WikiRaw(ctx *context.Context) {
 | 
			
		||||
func NewWiki(ctx *context.Context) {
 | 
			
		||||
	ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
 | 
			
		||||
 | 
			
		||||
	if !ctx.Repo.Repository.HasWiki() {
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, ctx.Repo.Repository)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.ServerError("IsWikiRepositoryExist", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if !hasWiki {
 | 
			
		||||
		ctx.Data["title"] = "Home"
 | 
			
		||||
	}
 | 
			
		||||
	if ctx.FormString("title") != "" {
 | 
			
		||||
@ -806,7 +826,12 @@ func NewWikiPost(ctx *context.Context) {
 | 
			
		||||
func EditWiki(ctx *context.Context) {
 | 
			
		||||
	ctx.Data["PageIsWikiEdit"] = true
 | 
			
		||||
 | 
			
		||||
	if !ctx.Repo.Repository.HasWiki() {
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, ctx.Repo.Repository)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.ServerError("IsWikiRepositoryExist", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if !hasWiki {
 | 
			
		||||
		ctx.Redirect(ctx.Repo.RepoLink + "/wiki")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -241,7 +241,9 @@ func TestDefaultWikiBranch(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// repo with no wiki
 | 
			
		||||
	repoWithNoWiki := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
 | 
			
		||||
	assert.False(t, repoWithNoWiki.HasWiki())
 | 
			
		||||
	exist, err := gitrepo.IsWikiRepositoryExist(db.DefaultContext, repoWithNoWiki)
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.False(t, exist)
 | 
			
		||||
	assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repoWithNoWiki, "main"))
 | 
			
		||||
 | 
			
		||||
	// repo with wiki
 | 
			
		||||
 | 
			
		||||
@ -63,7 +63,9 @@ func TestGiteaUploadRepo(t *testing.T) {
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
 | 
			
		||||
	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID, Name: repoName})
 | 
			
		||||
	assert.True(t, repo.HasWiki())
 | 
			
		||||
	exist, err := gitrepo.IsRepositoryExist(ctx, repo)
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.True(t, exist)
 | 
			
		||||
	assert.EqualValues(t, repo_model.RepositoryReady, repo.Status)
 | 
			
		||||
 | 
			
		||||
	milestones, err := db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
 | 
			
		||||
 | 
			
		||||
@ -52,7 +52,11 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if m.Repo.HasWiki() {
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, m.Repo)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if hasWiki {
 | 
			
		||||
		wikiPath := m.Repo.WikiPath()
 | 
			
		||||
		wikiRemotePath := repo_module.WikiRemoteURL(ctx, addr)
 | 
			
		||||
		// Remove old remote of wiki
 | 
			
		||||
@ -339,17 +343,21 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
 | 
			
		||||
		endpoint := lfs.DetermineEndpoint(remoteURL.String(), m.LFSEndpoint)
 | 
			
		||||
		lfsClient := lfs.NewClient(endpoint, nil)
 | 
			
		||||
		if err = repo_module.StoreMissingLfsObjectsInRepository(ctx, m.Repo, gitRepo, lfsClient); err != nil {
 | 
			
		||||
			log.Error("SyncMirrors [repo: %-v]: failed to synchronize LFS objects for repository: %v", m.Repo, err)
 | 
			
		||||
			log.Error("SyncMirrors [repo: %-v]: failed to synchronize LFS objects for repository: %v", m.Repo.FullName(), err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	gitRepo.Close()
 | 
			
		||||
 | 
			
		||||
	log.Trace("SyncMirrors [repo: %-v]: updating size of repository", m.Repo)
 | 
			
		||||
	if err := repo_module.UpdateRepoSize(ctx, m.Repo); err != nil {
 | 
			
		||||
		log.Error("SyncMirrors [repo: %-v]: failed to update size for mirror repository: %v", m.Repo, err)
 | 
			
		||||
		log.Error("SyncMirrors [repo: %-v]: failed to update size for mirror repository: %v", m.Repo.FullName(), err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if m.Repo.HasWiki() {
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, m.Repo)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error("SyncMirrors [repo: %-v]: failed to check if wiki repository exists: %v", m.Repo.FullName(), err)
 | 
			
		||||
	}
 | 
			
		||||
	if hasWiki {
 | 
			
		||||
		log.Trace("SyncMirrors [repo: %-v Wiki]: running git remote update...", m.Repo)
 | 
			
		||||
		stderrBuilder.Reset()
 | 
			
		||||
		stdoutBuilder.Reset()
 | 
			
		||||
 | 
			
		||||
@ -47,7 +47,11 @@ func AddPushMirrorRemote(ctx context.Context, m *repo_model.PushMirror, addr str
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if m.Repo.HasWiki() {
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, m.Repo)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if hasWiki {
 | 
			
		||||
		wikiRemoteURL := repository.WikiRemoteURL(ctx, addr)
 | 
			
		||||
		if len(wikiRemoteURL) > 0 {
 | 
			
		||||
			if err := addRemoteAndConfig(wikiRemoteURL, m.Repo.WikiPath()); err != nil {
 | 
			
		||||
@ -68,7 +72,11 @@ func RemovePushMirrorRemote(ctx context.Context, m *repo_model.PushMirror) error
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if m.Repo.HasWiki() {
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, m.Repo)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if hasWiki {
 | 
			
		||||
		if _, _, err := cmd.RunStdString(ctx, &git.RunOpts{Dir: m.Repo.WikiPath()}); err != nil {
 | 
			
		||||
			// The wiki remote may not exist
 | 
			
		||||
			log.Warn("Wiki Remote[%d] could not be removed: %v", m.ID, err)
 | 
			
		||||
@ -183,7 +191,11 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if m.Repo.HasWiki() {
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, m.Repo)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if hasWiki {
 | 
			
		||||
		_, err := git.GetRemoteAddress(ctx, m.Repo.WikiPath(), m.RemoteName)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			err := performPush(m.Repo, true)
 | 
			
		||||
 | 
			
		||||
@ -299,8 +299,12 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, repoID
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Remove wiki files
 | 
			
		||||
	if repo.HasWiki() {
 | 
			
		||||
		system_model.RemoveAllWithNotice(ctx, "Delete repository wiki", repo.WikiPath())
 | 
			
		||||
	if err := gitrepo.DeleteWikiRepository(ctx, repo); err != nil {
 | 
			
		||||
		desc := fmt.Sprintf("Delete wiki repository files [%s]: %v", repo.FullName(), err)
 | 
			
		||||
		// Note we use the db.DefaultContext here rather than passing in a context as the context may be cancelled
 | 
			
		||||
		if err = system_model.CreateNotice(db.DefaultContext, system_model.NoticeRepository, desc); err != nil {
 | 
			
		||||
			log.Error("CreateRepositoryNotice: %v", err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Remove archives
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,11 @@ func SyncRepositoryHooks(ctx context.Context) error {
 | 
			
		||||
			if err := gitrepo.CreateDelegateHooksForRepo(ctx, repo); err != nil {
 | 
			
		||||
				return fmt.Errorf("SyncRepositoryHook: %w", err)
 | 
			
		||||
			}
 | 
			
		||||
			if repo.HasWiki() {
 | 
			
		||||
			exist, err := gitrepo.IsWikiRepositoryExist(ctx, repo)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return fmt.Errorf("SyncRepositoryHook: %w", err)
 | 
			
		||||
			}
 | 
			
		||||
			if exist {
 | 
			
		||||
				if err := gitrepo.CreateDelegateHooksForWiki(ctx, repo); err != nil {
 | 
			
		||||
					return fmt.Errorf("SyncRepositoryHook: %w", err)
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@ -268,18 +268,23 @@ func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo
 | 
			
		||||
	if err := gitrepo.CreateDelegateHooksForRepo(ctx, repo); err != nil {
 | 
			
		||||
		return repo, fmt.Errorf("createDelegateHooks: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
	if repo.HasWiki() {
 | 
			
		||||
 | 
			
		||||
	hasWiki, err := gitrepo.IsWikiRepositoryExist(ctx, repo)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return repo, fmt.Errorf("IsWikiRepositoryExist: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
	if hasWiki {
 | 
			
		||||
		if err := gitrepo.CreateDelegateHooksForWiki(ctx, repo); err != nil {
 | 
			
		||||
			return repo, fmt.Errorf("createDelegateHooks.(wiki): %w", err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, _, err := git.NewCommand("remote", "rm", "origin").RunStdString(ctx, &git.RunOpts{Dir: repo.RepoPath()})
 | 
			
		||||
	_, _, err = git.NewCommand("remote", "rm", "origin").RunStdString(ctx, &git.RunOpts{Dir: repo.RepoPath()})
 | 
			
		||||
	if err != nil && !git.IsRemoteNotExistError(err) {
 | 
			
		||||
		return repo, fmt.Errorf("CleanUpMigrateInfo: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if repo.HasWiki() {
 | 
			
		||||
	if hasWiki {
 | 
			
		||||
		if err := cleanUpMigrateGitConfig(ctx, repo.WikiPath()); err != nil {
 | 
			
		||||
			return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %w", err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -340,14 +340,13 @@ func changeRepositoryName(ctx context.Context, repo *repo_model.Repository, newR
 | 
			
		||||
		return fmt.Errorf("rename repository directory: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	wikiPath := repo.WikiPath()
 | 
			
		||||
	isExist, err := util.IsExist(wikiPath)
 | 
			
		||||
	isExist, err := gitrepo.IsWikiRepositoryExist(ctx, repo)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error("Unable to check if %s exists. Error: %v", wikiPath, err)
 | 
			
		||||
		log.Error("Unable to check if the wiki of %s exists. Error: %v", repo.FullName(), err)
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if isExist {
 | 
			
		||||
		if err = util.Rename(wikiPath, repo_model.WikiPath(repo.Owner.Name, newRepoName)); err != nil {
 | 
			
		||||
		if err = gitrepo.RenameWikiRepository(ctx, repo, newRepoName); err != nil {
 | 
			
		||||
			return fmt.Errorf("rename repository wiki: %w", err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,9 @@ func getWikiWorkingLockKey(repoID int64) string {
 | 
			
		||||
// InitWiki initializes a wiki for repository,
 | 
			
		||||
// it does nothing when repository already has wiki.
 | 
			
		||||
func InitWiki(ctx context.Context, repo *repo_model.Repository) error {
 | 
			
		||||
	if repo.HasWiki() {
 | 
			
		||||
	if exist, err := gitrepo.IsWikiRepositoryExist(ctx, repo); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	} else if exist {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -377,7 +379,9 @@ func ChangeDefaultWikiBranch(ctx context.Context, repo *repo_model.Repository, n
 | 
			
		||||
			return fmt.Errorf("unable to update database: %w", err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if !repo.HasWiki() {
 | 
			
		||||
		if exist, err := gitrepo.IsWikiRepositoryExist(ctx, repo); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		} else if !exist {
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -149,7 +149,9 @@ func TestRepository_InitWiki(t *testing.T) {
 | 
			
		||||
	// repo2 does not already have a wiki
 | 
			
		||||
	repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
 | 
			
		||||
	assert.NoError(t, InitWiki(git.DefaultContext, repo2))
 | 
			
		||||
	assert.True(t, repo2.HasWiki())
 | 
			
		||||
	exist, err := gitrepo.IsWikiRepositoryExist(git.DefaultContext, repo2)
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.True(t, exist)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestRepository_AddWikiPage(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user