mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-19 18:52:38 +00:00
fix: Remove "create branch" button on mirrored repos (#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 #7639. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7640 Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: John Moon <john.moon@vts-i.com> Co-committed-by: John Moon <john.moon@vts-i.com>
This commit is contained in:
parent
63543afa2b
commit
09f7dbecda
3 changed files with 28 additions and 2 deletions
|
@ -132,6 +132,7 @@
|
|||
owner_name: org3
|
||||
lower_name: repo5
|
||||
name: repo5
|
||||
default_branch: master
|
||||
num_watches: 0
|
||||
num_stars: 0
|
||||
num_forks: 0
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<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}} {{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}</p>
|
||||
</td>
|
||||
<td class="right aligned middle aligned overflow-visible">
|
||||
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}}
|
||||
{{if and $.IsWriter (not $.Repository.IsArchived) (not $.Repository.IsMirror) (not .IsDeleted)}}
|
||||
<button class="btn interact-bg show-create-branch-modal tw-p-2"
|
||||
data-modal="#create-branch-modal"
|
||||
data-branch-from="{{$.DefaultBranchBranch.DBBranch.Name}}"
|
||||
|
@ -151,7 +151,7 @@
|
|||
{{end}}
|
||||
</td>
|
||||
<td class="three wide right aligned overflow-visible">
|
||||
{{if and $.IsWriter (not $.Repository.IsArchived) (not .DBBranch.IsDeleted)}}
|
||||
{{if and $.IsWriter (not $.Repository.IsArchived) (not $.Repository.IsMirror) (not .DBBranch.IsDeleted)}}
|
||||
<button class="btn interact-bg tw-p-2 show-modal show-create-branch-modal"
|
||||
data-branch-from="{{.DBBranch.Name}}"
|
||||
data-branch-from-urlcomponent="{{PathEscapeSegments .DBBranch.Name}}"
|
||||
|
|
|
@ -204,3 +204,28 @@ func TestDatabaseMissingABranch(t *testing.T) {
|
|||
assert.Equal(t, firstBranchCount-1, secondBranchCount)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateBranchButtonVisibility(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
t.Run("Check create branch button", func(t *testing.T) {
|
||||
t.Run("Normal repository", func(t *testing.T) {
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
|
||||
// Check that the button is present
|
||||
resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+repo1.FullName()+"/branches"), http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
assert.Positive(t, htmlDoc.doc.Find(".show-create-branch-modal").Length())
|
||||
})
|
||||
t.Run("Mirrored repository", func(t *testing.T) {
|
||||
repo5 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 5})
|
||||
|
||||
// Check that the button is NOT present
|
||||
resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+repo5.FullName()+"/branches"), http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
assert.Equal(t, 0, htmlDoc.doc.Find(".show-create-branch-modal").Length())
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue