Skip to content

Commit 68be709

Browse files
committed
various fixes
1 parent 49052a5 commit 68be709

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

routers/web/repo/wiki.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
9393
}
9494

9595
func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
96-
wikiGitRepo, errCommit := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
97-
if errCommit != nil {
98-
ctx.ServerError("OpenRepository", errCommit)
99-
return nil, nil, errCommit
96+
wikiGitRepo, errGitRepo := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
97+
if errGitRepo != nil {
98+
ctx.ServerError("OpenRepository", errGitRepo)
99+
return nil, nil, errGitRepo
100100
}
101101

102102
commit, errCommit := wikiGitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultWikiBranch)
103103
if git.IsErrNotExist(errCommit) {
104104
// if the default branch recorded in database is out of sync, then re-sync it
105105
gitRepoDefaultBranch, errBranch := wikiGitRepo.GetDefaultBranch()
106106
if errBranch != nil {
107-
return wikiGitRepo, nil, errCommit
107+
return wikiGitRepo, nil, errBranch
108108
}
109109
// update the default branch in the database
110110
errDb := repo_model.UpdateRepositoryCols(ctx, &repo_model.Repository{ID: ctx.Repo.Repository.ID, DefaultWikiBranch: gitRepoDefaultBranch}, "default_wiki_branch")

services/repository/migrate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func cloneWiki(ctx context.Context, u *user_model.User, opts migration.MigrateOp
3333
}
3434

3535
if err := util.RemoveAll(wikiPath); err != nil {
36-
return "", fmt.Errorf("failed to remove existingi wiki dir %q, err: %w", wikiPath, err)
36+
return "", fmt.Errorf("failed to remove existing wiki dir %q, err: %w", wikiPath, err)
3737
}
3838

3939
cleanIncompleteWikiPath := func() {
@@ -67,7 +67,7 @@ func cloneWiki(ctx context.Context, u *user_model.User, opts migration.MigrateOp
6767
defaultBranch, err := wikiRepo.GetDefaultBranch()
6868
if err != nil {
6969
cleanIncompleteWikiPath()
70-
return "", fmt.Errorf("failed to get wiki repo defaul brach for %q, err: %w", wikiPath, err)
70+
return "", fmt.Errorf("failed to get wiki repo defaul branch for %q, err: %w", wikiPath, err)
7171
}
7272

7373
return defaultBranch, nil

services/wiki/wiki.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ func DeleteWiki(ctx context.Context, repo *repo_model.Repository) error {
360360
}
361361

362362
func ChangeDefaultWikiBranch(ctx context.Context, repo *repo_model.Repository, newBranch string) error {
363+
if !git.IsValidRefPattern(newBranch) {
364+
return fmt.Errorf("invalid branch name: %s", newBranch)
365+
}
363366
return db.WithTx(ctx, func(ctx context.Context) error {
364367
repo.DefaultWikiBranch = newBranch
365368
if err := repo_model.UpdateRepositoryCols(ctx, repo, "default_wiki_branch"); err != nil {

0 commit comments

Comments
 (0)