Skip to content

Commit a9c552e

Browse files
committed
Fix tests and lint
1 parent f834dca commit a9c552e

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

routers/web/repo/editor.go

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ func renderCommitRights(ctx *context.Context, editRepo *repo_model.Repository) b
6262
ctx.Data["CanCreatePullRequest"] = ctx.Repo.Repository.UnitEnabled(ctx, unit.TypePullRequests) || canCreateBasePullRequest(ctx, editRepo)
6363

6464
return canCommitToBranch.CanCommitToBranch
65-
} else {
66-
// Editing a user fork of the repository we are viewing
67-
ctx.Data["CanCommitToBranch"] = context.CanCommitToBranchResults{}
68-
ctx.Data["CanCreatePullRequest"] = canCreateBasePullRequest(ctx, editRepo)
69-
70-
return false
7165
}
66+
67+
// Editing a user fork of the repository we are viewing
68+
ctx.Data["CanCommitToBranch"] = context.CanCommitToBranchResults{}
69+
ctx.Data["CanCreatePullRequest"] = canCreateBasePullRequest(ctx, editRepo)
70+
71+
return false
7272
}
7373

7474
// redirectForCommitChoice redirects after committing the edit to a branch
@@ -150,7 +150,13 @@ func editFileCommon(ctx *context.Context, isNewFile bool) (*repo_model.Repositor
150150
return nil, ctx.Tr("repo.editor.fork_internal_error", userRepo.FullName())
151151
}
152152

153-
// Check permissions, code unit and archiving
153+
// Check code unit, archiving and permissions.
154+
if !userRepo.UnitEnabled(ctx, unit.TypeCode) {
155+
return nil, ctx.Tr("repo.editor.fork_code_disabled", userRepo.FullName())
156+
}
157+
if userRepo.IsArchived {
158+
return nil, ctx.Tr("repo.editor.fork_is_archived", userRepo.FullName())
159+
}
154160
permission, err := access_model.GetUserRepoPermission(ctx, userRepo, ctx.Doer)
155161
if err != nil {
156162
log.Error("access_model.GetUserRepoPermission: %v", err)
@@ -159,12 +165,6 @@ func editFileCommon(ctx *context.Context, isNewFile bool) (*repo_model.Repositor
159165
if !permission.CanWrite(unit.TypeCode) {
160166
return nil, ctx.Tr("repo.editor.fork_no_permission", userRepo.FullName())
161167
}
162-
if !userRepo.UnitEnabled(ctx, unit.TypeCode) {
163-
return nil, ctx.Tr("repo.editor.fork_code_disabled", userRepo.FullName())
164-
}
165-
if userRepo.IsArchived {
166-
return nil, ctx.Tr("repo.editor.fork_is_archived", userRepo.FullName())
167-
}
168168

169169
editRepo = userRepo
170170
ctx.Data["ForkRepo"] = userRepo
@@ -208,7 +208,7 @@ func forkToEditFilePost(ctx *context.Context, form forms.ForkToEditRepoFileForm)
208208

209209
// Fork repository, if it doesn't already exist
210210
if editRepo == nil && notEditableMessage == nil {
211-
newRepo, err := ForkRepository(ctx, ctx.Doer, repo_service.ForkRepoOptions{
211+
_, err := ForkRepository(ctx, ctx.Doer, repo_service.ForkRepoOptions{
212212
BaseRepo: ctx.Repo.Repository,
213213
Name: GetUniqueRepositoryName(ctx, ctx.Repo.Repository.Name),
214214
Description: ctx.Repo.Repository.Description,
@@ -219,8 +219,6 @@ func forkToEditFilePost(ctx *context.Context, form forms.ForkToEditRepoFileForm)
219219
ctx.HTML(http.StatusOK, tplForkFile)
220220
return
221221
}
222-
223-
editRepo = newRepo
224222
}
225223

226224
// Redirect back to editing page
@@ -354,15 +352,11 @@ func pushBranchToUserRepo(ctx *context.Context, userRepo *repo_model.Repository,
354352

355353
log.Trace("pushBranchToUserRepo: pushing branch to user repo for editing: %s:%s %s:%s", baseRepo.FullName(), baseBranchName, userRepo.FullName(), userBranchName)
356354

357-
if err := git.Push(ctx, baseRepo.RepoPath(), git.PushOptions{
355+
return git.Push(ctx, baseRepo.RepoPath(), git.PushOptions{
358356
Remote: userRepo.RepoPath(),
359357
Branch: baseBranchName + ":" + userBranchName,
360358
Env: repo_module.PushingEnvironment(ctx.Doer, userRepo),
361-
}); err != nil {
362-
return err
363-
}
364-
365-
return nil
359+
})
366360
}
367361

368362
func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile bool) {
@@ -435,18 +429,20 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
435429
operation = "create"
436430
}
437431

432+
oldBranchName := ctx.Repo.BranchName
438433
if editRepo != ctx.Repo.Repository {
439434
// If editing a user fork, first push the branch to that repository
440435
err := pushBranchToUserRepo(ctx, editRepo, branchName)
441436
if err != nil {
442437
ctx.RenderWithErr(ctx.Tr("repo.editor.fork_failed_to_push_branch", branchName), tplEditFile, &form)
443438
return
444439
}
440+
oldBranchName = branchName
445441
}
446442

447443
if _, err := files_service.ChangeRepoFiles(ctx, editRepo, ctx.Doer, &files_service.ChangeRepoFilesOptions{
448444
LastCommitID: form.LastCommit,
449-
OldBranch: branchName,
445+
OldBranch: oldBranchName,
450446
NewBranch: branchName,
451447
Message: message,
452448
Files: []*files_service.ChangeRepoFile{

0 commit comments

Comments
 (0)