From 7d66b9ea65cc416046ec7075bc327932a4f2094f Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 8 Apr 2024 20:43:23 +0900 Subject: [PATCH] Avoid showing `Failed to change the default wiki branch` if repo has no wiki when saving repo settings (#30329) --- routers/web/repo/wiki_test.go | 6 ++++++ services/wiki/wiki.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index 8b5207f9d9..2894c06fbd 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -226,6 +226,12 @@ func TestWikiRaw(t *testing.T) { func TestDefaultWikiBranch(t *testing.T) { unittest.PrepareTestEnv(t) + // repo with no wiki + repoWithNoWiki := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}) + assert.False(t, repoWithNoWiki.HasWiki()) + assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repoWithNoWiki, "main")) + + // repo with wiki assert.NoError(t, repo_model.UpdateRepositoryCols(db.DefaultContext, &repo_model.Repository{ID: 1, DefaultWikiBranch: "wrong-branch"})) ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki") diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go index f8387416c1..fdcc5feefa 100644 --- a/services/wiki/wiki.go +++ b/services/wiki/wiki.go @@ -370,6 +370,10 @@ func ChangeDefaultWikiBranch(ctx context.Context, repo *repo_model.Repository, n return fmt.Errorf("unable to update database: %w", err) } + if !repo.HasWiki() { + return nil + } + oldDefBranch, err := gitrepo.GetWikiDefaultBranch(ctx, repo) if err != nil { return fmt.Errorf("unable to get default branch: %w", err)