Skip to content

Commit d0b5c68

Browse files
JohnMoon-VTSforgejo-backport-action
authored and
forgejo-backport-action
committed
fix: Remove "create branch" button on mirrored repos (go-gitea#7640)
Currently, if you have a mirrored repo, the button on the "branches" page to create a new branch is available to be pressed. Once you name your new branch and click submit, you get a 404 page that doesn't explain what went wrong. As new branch creation is not supported on mirrored repos, let's just take that button away if the repo is a mirror. This is already done for archived repos, so we just need to add another check. Fixes go-gitea#7639. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7640 Reviewed-by: Otto <[email protected]> Co-authored-by: John Moon <[email protected]> Co-committed-by: John Moon <[email protected]> (cherry picked from commit 09f7dbe)
1 parent 738ec94 commit d0b5c68

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

models/fixtures/repository.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
owner_name: org3
133133
lower_name: repo5
134134
name: repo5
135+
default_branch: master
135136
num_watches: 0
136137
num_stars: 0
137138
num_forks: 0

templates/repo/branch/list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<p class="info tw-flex tw-items-center tw-my-1">{{svg "octicon-git-commit" 16 "tw-mr-1"}}<a href="{{.RepoLink}}/commit/{{PathEscape .DefaultBranchBranch.DBBranch.CommitID}}">{{ShortSha .DefaultBranchBranch.DBBranch.CommitID}}</a> · <span class="commit-message">{{RenderCommitMessage $.Context .DefaultBranchBranch.DBBranch.CommitMessage (.Repository.ComposeMetas ctx)}}</span> · {{ctx.Locale.Tr "org.repo_updated" (DateUtils.TimeSince .DefaultBranchBranch.DBBranch.CommitTime)}}{{if .DefaultBranchBranch.DBBranch.Pusher}} &nbsp;{{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}</p>
3131
</td>
3232
<td class="right aligned middle aligned overflow-visible">
33-
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}}
33+
{{if and $.IsWriter (not $.Repository.IsArchived) (not $.Repository.IsMirror) (not .IsDeleted)}}
3434
<button class="btn interact-bg show-create-branch-modal tw-p-2"
3535
data-modal="#create-branch-modal"
3636
data-branch-from="{{$.DefaultBranchBranch.DBBranch.Name}}"
@@ -151,7 +151,7 @@
151151
{{end}}
152152
</td>
153153
<td class="three wide right aligned overflow-visible">
154-
{{if and $.IsWriter (not $.Repository.IsArchived) (not .DBBranch.IsDeleted)}}
154+
{{if and $.IsWriter (not $.Repository.IsArchived) (not $.Repository.IsMirror) (not .DBBranch.IsDeleted)}}
155155
<button class="btn interact-bg tw-p-2 show-modal show-create-branch-modal"
156156
data-branch-from="{{.DBBranch.Name}}"
157157
data-branch-from-urlcomponent="{{PathEscapeSegments .DBBranch.Name}}"

tests/integration/repo_branch_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,28 @@ func TestDatabaseMissingABranch(t *testing.T) {
204204
assert.Equal(t, firstBranchCount-1, secondBranchCount)
205205
})
206206
}
207+
208+
func TestCreateBranchButtonVisibility(t *testing.T) {
209+
onGiteaRun(t, func(t *testing.T, u *url.URL) {
210+
session := loginUser(t, "user1")
211+
212+
t.Run("Check create branch button", func(t *testing.T) {
213+
t.Run("Normal repository", func(t *testing.T) {
214+
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
215+
216+
// Check that the button is present
217+
resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+repo1.FullName()+"/branches"), http.StatusOK)
218+
htmlDoc := NewHTMLParser(t, resp.Body)
219+
assert.Positive(t, htmlDoc.doc.Find(".show-create-branch-modal").Length())
220+
})
221+
t.Run("Mirrored repository", func(t *testing.T) {
222+
repo5 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 5})
223+
224+
// Check that the button is NOT present
225+
resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+repo5.FullName()+"/branches"), http.StatusOK)
226+
htmlDoc := NewHTMLParser(t, resp.Body)
227+
assert.Equal(t, 0, htmlDoc.doc.Find(".show-create-branch-modal").Length())
228+
})
229+
})
230+
})
231+
}

0 commit comments

Comments
 (0)