Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions models/perm/access/repo_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func GetActionsUserRepoPermission(ctx context.Context, repo *repo_model.Reposito
// The task repo can access the current repo only if the task repo is private and
// the owner of the task repo is a collaborative owner of the current repo.
// FIXME allow public repo read access if tokenless pull is enabled
// FIXME should owner's visibility also be considered here?
return perm, nil
}
accessMode = perm_model.AccessModeRead
Expand Down
4 changes: 2 additions & 2 deletions routers/api/v1/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func CreateBranch(ctx *context.APIContext) {
}
}

err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, oldCommit.ID.String(), opt.BranchName)
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, oldCommit.ID.String(), opt.BranchName)
if err != nil {
if git_model.IsErrBranchNotExist(err) {
ctx.APIError(http.StatusNotFound, "The old branch does not exist")
Expand Down Expand Up @@ -434,7 +434,7 @@ func RenameBranch(ctx *context.APIContext) {
return
}

msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, ctx.Repo.GitRepo, oldName, opt.Name)
msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, oldName, opt.Name)
if err != nil {
switch {
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):
Expand Down
4 changes: 2 additions & 2 deletions routers/web/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ func CreateBranch(ctx *context.Context) {
}
err = release_service.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, target, form.NewBranchName, "")
} else if ctx.Repo.RefFullName.IsBranch() {
err = repo_service.CreateNewBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.BranchName, form.NewBranchName)
err = repo_service.CreateNewBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
} else {
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.CommitID, form.NewBranchName)
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
}
if err != nil {
if release_service.IsErrProtectedTagName(err) {
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/setting/protected_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func RenameBranchPost(ctx *context.Context) {
return
}

msg, err := repository.RenameBranch(ctx, ctx.Repo.Repository, ctx.Doer, ctx.Repo.GitRepo, form.From, form.To)
msg, err := repository.RenameBranch(ctx, ctx.Repo.Repository, ctx.Doer, form.From, form.To)
if err != nil {
switch {
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):
Expand Down
5 changes: 0 additions & 5 deletions routers/web/repo/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ func handleSettingsPostUpdate(ctx *context.Context) {
repo.Website = form.Website
repo.IsTemplate = form.Template

// Visibility of forked repository is forced sync with base repository.
if repo.IsFork {
form.Private = repo.BaseRepo.IsPrivate || repo.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate
}

if err := repo_service.UpdateRepository(ctx, repo, false); err != nil {
ctx.ServerError("UpdateRepository", err)
return
Expand Down
5 changes: 0 additions & 5 deletions services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ type RepoSettingForm struct {
PushMirrorPassword string
PushMirrorSyncOnCommit bool
PushMirrorInterval string
Private bool
Template bool
EnablePrune bool

Expand Down Expand Up @@ -148,10 +147,6 @@ type RepoSettingForm struct {
AllowOnlyContributorsToTrackTime bool
EnableIssueDependencies bool

EnableActions bool

IsArchived bool

// Signing Settings
TrustModel string

Expand Down
23 changes: 11 additions & 12 deletions services/repository/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ import (
)

// CreateNewBranch creates a new repository branch
func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, oldBranchName, branchName string) (err error) {
func CreateNewBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldBranchName, branchName string) (err error) {
branch, err := git_model.GetBranch(ctx, repo.ID, oldBranchName)
if err != nil {
return err
}

return CreateNewBranchFromCommit(ctx, doer, repo, gitRepo, branch.CommitID, branchName)
return CreateNewBranchFromCommit(ctx, doer, repo, branch.CommitID, branchName)
}

// Branch contains the branch information
Expand Down Expand Up @@ -374,7 +374,7 @@ func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames,
}

// CreateNewBranchFromCommit creates a new repository branch
func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, commitID, branchName string) (err error) {
func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, commitID, branchName string) (err error) {
err = repo.MustNotBeArchived()
if err != nil {
return err
Expand All @@ -399,7 +399,7 @@ func CreateNewBranchFromCommit(ctx context.Context, doer *user_model.User, repo
}

// RenameBranch rename a branch
func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, gitRepo *git.Repository, from, to string) (string, error) {
func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, from, to string) (string, error) {
err := repo.MustNotBeArchived()
if err != nil {
return "", err
Expand All @@ -413,8 +413,12 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
return "target_exist", nil
}

if exist, _ := git_model.IsBranchExist(ctx, repo.ID, from); !exist {
return "from_not_exist", nil
fromBranch, err := git_model.GetBranch(ctx, repo.ID, from)
if err != nil {
if git_model.IsErrBranchNotExist(err) {
return "from_not_exist", nil
}
return "", err
}

perm, err := access_model.GetUserRepoPermission(ctx, repo, doer)
Expand Down Expand Up @@ -472,14 +476,9 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
}); err != nil {
return "", err
}
refNameTo := git.RefNameFromBranch(to)
refID, err := gitRepo.GetRefCommitID(refNameTo.String())
if err != nil {
return "", err
}

notify_service.DeleteRef(ctx, doer, repo, git.RefNameFromBranch(from))
notify_service.CreateRef(ctx, doer, repo, refNameTo, refID)
notify_service.CreateRef(ctx, doer, repo, git.RefNameFromBranch(to), fromBranch.CommitID)

return "", nil
}
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/notice.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{{.CsrfTokenHtml}}
<button type="submit" class="ui red small button">{{ctx.Locale.Tr "admin.notices.delete_all"}}</button>
</form>
<div class="ui floating upward dropdown small button">{{/* TODO: Make this dropdown accessible */}}
<div class="ui floating upward dropdown small button">
<span class="text">{{ctx.Locale.Tr "admin.notices.operations"}}</span>
<div class="menu">
<div class="item select action" data-action="select-all">
Expand Down
2 changes: 1 addition & 1 deletion templates/projects/new.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</div>
<div class="field">
<label>{{ctx.Locale.Tr "repo.projects.description"}}</label>
{{/* TODO: repo-level project and org-level project have different behaviros to render */}}
{{/* TODO: repo-level project and org-level project have different behaviors to render */}}
{{/* the "Repository" is nil when the project is org-level */}}
{{template "shared/combomarkdowneditor" (dict
"MarkdownPreviewInRepo" $.Repository
Expand Down
3 changes: 2 additions & 1 deletion templates/repo/issue/branch_selector_field.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
PR: https://github.com/go-gitea/gitea/pull/32744

The Issue.Ref was added by Add possibility to record branch or tag information in an issue (#780)
After 8 years, this "branch selector" does nothing more than saving the branch/tag name into database and displays it.
After 8 years, this "branch selector" does nothing more than saving the branch/tag name into database and displays it,
or sometimes auto-close a ref-matched issue by a commit message when CloseIssuesViaCommitInAnyBranch=false.

There are still users using it:
* @didim99: it is a really useful feature to specify a branch in which issue found.
Expand Down
6 changes: 3 additions & 3 deletions templates/repo/settings/actions_general.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="inline field">
<label>{{ctx.Locale.Tr "actions.actions"}}</label>
<div class="ui checkbox{{if $isActionsGlobalDisabled}} disabled{{end}}"{{if $isActionsGlobalDisabled}} data-tooltip-content="{{ctx.Locale.Tr "repo.unit_disabled"}}"{{end}}>
<input class="enable-system" name="enable_actions" type="checkbox" {{if $isActionsGlobalDisabled}}disabled{{end}} {{if $isActionsEnabled}}checked{{end}}>
<input name="enable_actions" type="checkbox" {{if $isActionsGlobalDisabled}}disabled{{end}} {{if $isActionsEnabled}}checked{{end}}>
<label>{{ctx.Locale.Tr "repo.settings.actions_desc"}}</label>
</div>
</div>
Expand All @@ -23,7 +23,7 @@
</form>
</div>

{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
{{if .Repository.IsPrivate}}
<h4 class="ui top attached header">
{{ctx.Locale.Tr "actions.general.collaborative_owners_management"}}
Expand Down Expand Up @@ -65,5 +65,5 @@
{{ctx.Locale.Tr "actions.general.collaborative_owners_management_help"}}
</div>
{{end}}
{{end}}
{{end}}
</div>
17 changes: 4 additions & 13 deletions tests/integration/actions_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
user_model "code.gitea.io/gitea/models/user"
actions_module "code.gitea.io/gitea/modules/actions"
"code.gitea.io/gitea/modules/commitstatus"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/setting"
Expand Down Expand Up @@ -412,7 +411,7 @@ jobs:
assert.NoError(t, err)

// create a branch
err = repo_service.CreateNewBranchFromCommit(t.Context(), user2, repo, gitRepo, branch.CommitID, "test-create-branch")
err = repo_service.CreateNewBranchFromCommit(t.Context(), user2, repo, branch.CommitID, "test-create-branch")
assert.NoError(t, err)
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{
Title: "add workflow",
Expand Down Expand Up @@ -530,9 +529,7 @@ jobs:

// create a new branch
testBranch := "test-branch"
gitRepo, err := git.OpenRepository(t.Context(), ".")
assert.NoError(t, err)
err = repo_service.CreateNewBranch(t.Context(), user2, repo, gitRepo, "main", testBranch)
err = repo_service.CreateNewBranch(t.Context(), user2, repo, "main", testBranch)
assert.NoError(t, err)

// create Pull
Expand Down Expand Up @@ -1507,14 +1504,11 @@ jobs:
assert.NotEmpty(t, addWorkflowToBaseResp)

// Get the commit ID of the default branch
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
branch, err := git_model.GetBranch(t.Context(), repo.ID, repo.DefaultBranch)
assert.NoError(t, err)

// create a branch
err = repo_service.CreateNewBranchFromCommit(t.Context(), user2, repo, gitRepo, branch.CommitID, "test-action-run-name-with-variables")
err = repo_service.CreateNewBranchFromCommit(t.Context(), user2, repo, branch.CommitID, "test-action-run-name-with-variables")
assert.NoError(t, err)
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{
Title: user2.LoginName + " is running this workflow",
Expand Down Expand Up @@ -1584,14 +1578,11 @@ jobs:
assert.NotEmpty(t, addWorkflowToBaseResp)

// Get the commit ID of the default branch
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
assert.NoError(t, err)
defer gitRepo.Close()
branch, err := git_model.GetBranch(t.Context(), repo.ID, repo.DefaultBranch)
assert.NoError(t, err)

// create a branch
err = repo_service.CreateNewBranchFromCommit(t.Context(), user2, repo, gitRepo, branch.CommitID, "test-action-run-name")
err = repo_service.CreateNewBranchFromCommit(t.Context(), user2, repo, branch.CommitID, "test-action-run-name")
assert.NoError(t, err)
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{
Title: "run name without variables",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/api_repo_get_contents_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {

// Make a new branch in repo1
newBranch := "test_branch"
err = repo_service.CreateNewBranch(t.Context(), user2, repo1, gitRepo, repo1.DefaultBranch, newBranch)
err = repo_service.CreateNewBranch(t.Context(), user2, repo1, repo1.DefaultBranch, newBranch)
assert.NoError(t, err)

commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/api_repo_get_contents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {

// Make a new branch in repo1
newBranch := "test_branch"
err = repo_service.CreateNewBranch(t.Context(), user2, repo1, gitRepo, repo1.DefaultBranch, newBranch)
err = repo_service.CreateNewBranch(t.Context(), user2, repo1, repo1.DefaultBranch, newBranch)
require.NoError(t, err)

commitID, err := gitRepo.GetBranchCommitID(repo1.DefaultBranch)
Expand Down