Skip to content

Commit 6eb5950

Browse files
authored
Allow set branch protection in an empty repository (#32095)
1 parent 3f2d8f8 commit 6eb5950

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

routers/web/web.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ func registerRoutes(m *web.Router) {
10691069
m.Combo("/edit").Get(repo_setting.SettingsProtectedBranch).
10701070
Post(web.Bind(forms.ProtectBranchForm{}), context.RepoMustNotBeArchived(), repo_setting.SettingsProtectedBranchPost)
10711071
m.Post("/{id}/delete", repo_setting.DeleteProtectedBranchRulePost)
1072-
}, repo.MustBeNotEmpty)
1072+
})
10731073

10741074
m.Group("/tags", func() {
10751075
m.Get("", repo_setting.ProtectedTags)

templates/repo/settings/branches.tmpl

+10-12
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@
1515
<form class="tw-flex" action="{{.Link}}" method="post">
1616
{{.CsrfTokenHtml}}
1717
<input type="hidden" name="action" value="default_branch">
18-
{{if not .Repository.IsEmpty}}
19-
<div class="ui dropdown selection search tw-flex-1 tw-mr-2 tw-max-w-96">
20-
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
21-
<input type="hidden" name="branch" value="{{.Repository.DefaultBranch}}">
22-
<div class="default text">{{.Repository.DefaultBranch}}</div>
23-
<div class="menu">
24-
{{range .Branches}}
25-
<div class="item" data-value="{{.}}">{{.}}</div>
26-
{{end}}
27-
</div>
18+
<div class="ui dropdown selection search tw-flex-1 tw-mr-2 tw-max-w-96">
19+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
20+
<input type="hidden" name="branch" value="{{.Repository.DefaultBranch}}">
21+
<div class="default text">{{.Repository.DefaultBranch}}</div>
22+
<div class="menu">
23+
{{range .Branches}}
24+
<div class="item" data-value="{{.}}">{{.}}</div>
25+
{{end}}
2826
</div>
29-
<button class="ui primary button">{{ctx.Locale.Tr "repo.settings.branches.update_default_branch"}}</button>
30-
{{end}}
27+
</div>
28+
<button class="ui primary button"{{if .Repository.IsEmpty}} disabled{{end}}>{{ctx.Locale.Tr "repo.settings.branches.update_default_branch"}}</button>
3129
</form>
3230
</div>
3331

templates/repo/settings/navbar.tmpl

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
</a>
1414
{{end}}
1515
{{if .Repository.UnitEnabled $.Context ctx.Consts.RepoUnitTypeCode}}
16-
{{if not .Repository.IsEmpty}}
17-
<a class="{{if .PageIsSettingsBranches}}active {{end}}item" href="{{.RepoLink}}/settings/branches">
18-
{{ctx.Locale.Tr "repo.settings.branches"}}
19-
</a>
20-
{{end}}
16+
<a class="{{if .PageIsSettingsBranches}}active {{end}}item" href="{{.RepoLink}}/settings/branches">
17+
{{ctx.Locale.Tr "repo.settings.branches"}}
18+
</a>
2119
<a class="{{if .PageIsSettingsTags}}active {{end}}item" href="{{.RepoLink}}/settings/tags">
2220
{{ctx.Locale.Tr "repo.settings.tags"}}
2321
</a>

0 commit comments

Comments
 (0)