Skip to content

Commit 22a18e6

Browse files
GiteaBotyp05327
andauthored
Avoid showing Failed to change the default wiki branch if repo has no wiki when saving repo settings (#30329) (#30337)
Backport #30329 by @yp05327 If repo does not have wiki, we should return after save the default wiki branch into DB. Or you will always see `Failed to change the default wiki branch` error. Co-authored-by: yp05327 <576951401@qq.com>
1 parent c541616 commit 22a18e6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

routers/web/repo/wiki_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ func TestWikiRaw(t *testing.T) {
226226
func TestDefaultWikiBranch(t *testing.T) {
227227
unittest.PrepareTestEnv(t)
228228

229+
// repo with no wiki
230+
repoWithNoWiki := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
231+
assert.False(t, repoWithNoWiki.HasWiki())
232+
assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repoWithNoWiki, "main"))
233+
234+
// repo with wiki
229235
assert.NoError(t, repo_model.UpdateRepositoryCols(db.DefaultContext, &repo_model.Repository{ID: 1, DefaultWikiBranch: "wrong-branch"}))
230236

231237
ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki")

services/wiki/wiki.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ func ChangeDefaultWikiBranch(ctx context.Context, repo *repo_model.Repository, n
370370
return fmt.Errorf("unable to update database: %w", err)
371371
}
372372

373+
if !repo.HasWiki() {
374+
return nil
375+
}
376+
373377
oldDefBranch, err := gitrepo.GetWikiDefaultBranch(ctx, repo)
374378
if err != nil {
375379
return fmt.Errorf("unable to get default branch: %w", err)

0 commit comments

Comments
 (0)