Avoid showing `Failed to change the default wiki branch` if repo has no wiki when saving repo settings (#30329)

pull/30331/head^2
yp05327 8 months ago committed by GitHub
parent 074a3e05f6
commit 7d66b9ea65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      routers/web/repo/wiki_test.go
  2. 4
      services/wiki/wiki.go

@ -226,6 +226,12 @@ func TestWikiRaw(t *testing.T) {
func TestDefaultWikiBranch(t *testing.T) { func TestDefaultWikiBranch(t *testing.T) {
unittest.PrepareTestEnv(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"})) assert.NoError(t, repo_model.UpdateRepositoryCols(db.DefaultContext, &repo_model.Repository{ID: 1, DefaultWikiBranch: "wrong-branch"}))
ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki") ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki")

@ -370,6 +370,10 @@ func ChangeDefaultWikiBranch(ctx context.Context, repo *repo_model.Repository, n
return fmt.Errorf("unable to update database: %w", err) return fmt.Errorf("unable to update database: %w", err)
} }
if !repo.HasWiki() {
return nil
}
oldDefBranch, err := gitrepo.GetWikiDefaultBranch(ctx, repo) oldDefBranch, err := gitrepo.GetWikiDefaultBranch(ctx, repo)
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)

Loading…
Cancel
Save