Skip to content

Commit

Permalink
Avoid showing Failed to change the default wiki branch if repo has …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
GiteaBot and yp05327 authored Apr 8, 2024
1 parent c541616 commit 22a18e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions routers/web/repo/wiki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions services/wiki/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 22a18e6

Please sign in to comment.