aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/wiki_test.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-03-06 14:26:32 +0800
committerGitHub <noreply@github.com>2024-03-06 14:26:32 +0800
commit5cddab4f74bbb307ddf13e458c7ac22f93b9283a (patch)
tree2eee924ffdbc2e1bedb6b63020e7b7fdd86417c3 /routers/web/repo/wiki_test.go
parentda15d6127c8d430dfc069f9815ce783dd9ca35f7 (diff)
downloadgitea-5cddab4f74bbb307ddf13e458c7ac22f93b9283a.tar.gz
gitea-5cddab4f74bbb307ddf13e458c7ac22f93b9283a.zip
Make wiki default branch name changable (#29603)
Fix #29000 Fix #28685 Fix #18568 Related: #27497 And by the way fix #24036, add a Cancel button there (one line)
Diffstat (limited to 'routers/web/repo/wiki_test.go')
-rw-r--r--routers/web/repo/wiki_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go
index 719cca3049..52e216e6a0 100644
--- a/routers/web/repo/wiki_test.go
+++ b/routers/web/repo/wiki_test.go
@@ -9,6 +9,7 @@ import (
"net/url"
"testing"
+ "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
@@ -221,3 +222,32 @@ func TestWikiRaw(t *testing.T) {
}
}
}
+
+func TestDefaultWikiBranch(t *testing.T) {
+ unittest.PrepareTestEnv(t)
+
+ assert.NoError(t, repo_model.UpdateRepositoryCols(db.DefaultContext, &repo_model.Repository{ID: 1, DefaultWikiBranch: "wrong-branch"}))
+
+ ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki")
+ ctx.SetParams("*", "Home")
+ contexttest.LoadRepo(t, ctx, 1)
+ assert.Equal(t, "wrong-branch", ctx.Repo.Repository.DefaultWikiBranch)
+ Wiki(ctx) // after the visiting, the out-of-sync database record will update the branch name to "master"
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ assert.Equal(t, "master", ctx.Repo.Repository.DefaultWikiBranch)
+
+ // invalid branch name should fail
+ assert.Error(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "the bad name"))
+ repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ assert.Equal(t, "master", repo.DefaultWikiBranch)
+
+ // the same branch name, should succeed (actually a no-op)
+ assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "master"))
+ repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ assert.Equal(t, "master", repo.DefaultWikiBranch)
+
+ // change to another name
+ assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "main"))
+ repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ assert.Equal(t, "main", repo.DefaultWikiBranch)
+}