Skip to content

Commit 6382cc5

Browse files
committed
Remove unnecessary function parameter
1 parent cddff73 commit 6382cc5

File tree

7 files changed

+22
-32
lines changed

7 files changed

+22
-32
lines changed

routers/api/v1/repo/branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func CreateBranch(ctx *context.APIContext) {
243243
}
244244
}
245245

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

437-
msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, ctx.Repo.GitRepo, oldName, opt.Name)
437+
msg, err := repo_service.RenameBranch(ctx, repo, ctx.Doer, oldName, opt.Name)
438438
if err != nil {
439439
switch {
440440
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):

routers/web/repo/branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ func CreateBranch(ctx *context.Context) {
194194
}
195195
err = release_service.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, target, form.NewBranchName, "")
196196
} else if ctx.Repo.RefFullName.IsBranch() {
197-
err = repo_service.CreateNewBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.BranchName, form.NewBranchName)
197+
err = repo_service.CreateNewBranch(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.BranchName, form.NewBranchName)
198198
} else {
199-
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.CommitID, form.NewBranchName)
199+
err = repo_service.CreateNewBranchFromCommit(ctx, ctx.Doer, ctx.Repo.Repository, ctx.Repo.CommitID, form.NewBranchName)
200200
}
201201
if err != nil {
202202
if release_service.IsErrProtectedTagName(err) {

routers/web/repo/setting/protected_branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func RenameBranchPost(ctx *context.Context) {
337337
return
338338
}
339339

340-
msg, err := repository.RenameBranch(ctx, ctx.Repo.Repository, ctx.Doer, ctx.Repo.GitRepo, form.From, form.To)
340+
msg, err := repository.RenameBranch(ctx, ctx.Repo.Repository, ctx.Doer, form.From, form.To)
341341
if err != nil {
342342
switch {
343343
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):

services/repository/branch.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ import (
3838
)
3939

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

47-
return CreateNewBranchFromCommit(ctx, doer, repo, gitRepo, branch.CommitID, branchName)
47+
return CreateNewBranchFromCommit(ctx, doer, repo, branch.CommitID, branchName)
4848
}
4949

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

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

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

416-
if exist, _ := git_model.IsBranchExist(ctx, repo.ID, from); !exist {
417-
return "from_not_exist", nil
416+
fromBranch, err := git_model.GetBranch(ctx, repo.ID, from)
417+
if err != nil {
418+
if git_model.IsErrBranchNotExist(err) {
419+
return "from_not_exist", nil
420+
}
421+
return "", err
418422
}
419423

420424
perm, err := access_model.GetUserRepoPermission(ctx, repo, doer)
@@ -472,14 +476,9 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
472476
}); err != nil {
473477
return "", err
474478
}
475-
refNameTo := git.RefNameFromBranch(to)
476-
refID, err := gitRepo.GetRefCommitID(refNameTo.String())
477-
if err != nil {
478-
return "", err
479-
}
480479

481480
notify_service.DeleteRef(ctx, doer, repo, git.RefNameFromBranch(from))
482-
notify_service.CreateRef(ctx, doer, repo, refNameTo, refID)
481+
notify_service.CreateRef(ctx, doer, repo, git.RefNameFromBranch(to), fromBranch.CommitID)
483482

484483
return "", nil
485484
}

tests/integration/actions_trigger_test.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
user_model "code.gitea.io/gitea/models/user"
2424
actions_module "code.gitea.io/gitea/modules/actions"
2525
"code.gitea.io/gitea/modules/commitstatus"
26-
"code.gitea.io/gitea/modules/git"
2726
"code.gitea.io/gitea/modules/gitrepo"
2827
"code.gitea.io/gitea/modules/json"
2928
"code.gitea.io/gitea/modules/setting"
@@ -412,7 +411,7 @@ jobs:
412411
assert.NoError(t, err)
413412

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

531530
// create a new branch
532531
testBranch := "test-branch"
533-
gitRepo, err := git.OpenRepository(t.Context(), ".")
534-
assert.NoError(t, err)
535-
err = repo_service.CreateNewBranch(t.Context(), user2, repo, gitRepo, "main", testBranch)
532+
err = repo_service.CreateNewBranch(t.Context(), user2, repo, "main", testBranch)
536533
assert.NoError(t, err)
537534

538535
// create Pull
@@ -1507,14 +1504,11 @@ jobs:
15071504
assert.NotEmpty(t, addWorkflowToBaseResp)
15081505

15091506
// Get the commit ID of the default branch
1510-
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
1511-
assert.NoError(t, err)
1512-
defer gitRepo.Close()
15131507
branch, err := git_model.GetBranch(t.Context(), repo.ID, repo.DefaultBranch)
15141508
assert.NoError(t, err)
15151509

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

15861580
// Get the commit ID of the default branch
1587-
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
1588-
assert.NoError(t, err)
1589-
defer gitRepo.Close()
15901581
branch, err := git_model.GetBranch(t.Context(), repo.ID, repo.DefaultBranch)
15911582
assert.NoError(t, err)
15921583

15931584
// create a branch
1594-
err = repo_service.CreateNewBranchFromCommit(t.Context(), user2, repo, gitRepo, branch.CommitID, "test-action-run-name")
1585+
err = repo_service.CreateNewBranchFromCommit(t.Context(), user2, repo, branch.CommitID, "test-action-run-name")
15951586
assert.NoError(t, err)
15961587
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{
15971588
Title: "run name without variables",

tests/integration/api_repo_get_contents_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
8080

8181
// Make a new branch in repo1
8282
newBranch := "test_branch"
83-
err = repo_service.CreateNewBranch(t.Context(), user2, repo1, gitRepo, repo1.DefaultBranch, newBranch)
83+
err = repo_service.CreateNewBranch(t.Context(), user2, repo1, repo1.DefaultBranch, newBranch)
8484
assert.NoError(t, err)
8585

8686
commitID, _ := gitRepo.GetBranchCommitID(repo1.DefaultBranch)

tests/integration/api_repo_get_contents_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
8585

8686
// Make a new branch in repo1
8787
newBranch := "test_branch"
88-
err = repo_service.CreateNewBranch(t.Context(), user2, repo1, gitRepo, repo1.DefaultBranch, newBranch)
88+
err = repo_service.CreateNewBranch(t.Context(), user2, repo1, repo1.DefaultBranch, newBranch)
8989
require.NoError(t, err)
9090

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

0 commit comments

Comments
 (0)