Skip to content

Commit 610802d

Browse files
silverwindGiteaBot
andauthored
Fix tautological conditions (#30735)
As discovered by #30729. --------- Co-authored-by: Giteabot <teabot@gitea.io>
1 parent f2d8ccc commit 610802d

File tree

5 files changed

+20
-29
lines changed

5 files changed

+20
-29
lines changed

modules/indexer/code/indexer.go

-6
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,6 @@ func Init() {
178178
}()
179179

180180
rIndexer = elasticsearch.NewIndexer(setting.Indexer.RepoConnStr, setting.Indexer.RepoIndexerName)
181-
if err != nil {
182-
cancel()
183-
(*globalIndexer.Load()).Close()
184-
close(waitChannel)
185-
log.Fatal("PID: %d Unable to create the elasticsearch Repository Indexer connstr: %s Error: %v", os.Getpid(), setting.Indexer.RepoConnStr, err)
186-
}
187181
existed, err = rIndexer.Init(ctx)
188182
if err != nil {
189183
cancel()

routers/private/hook_post_receive.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,14 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
117117
}
118118
}
119119
if len(branchesToSync) > 0 {
120-
if gitRepo == nil {
121-
var err error
122-
gitRepo, err = gitrepo.OpenRepository(ctx, repo)
123-
if err != nil {
124-
log.Error("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err)
125-
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
126-
Err: fmt.Sprintf("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err),
127-
})
128-
return
129-
}
120+
var err error
121+
gitRepo, err = gitrepo.OpenRepository(ctx, repo)
122+
if err != nil {
123+
log.Error("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err)
124+
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
125+
Err: fmt.Sprintf("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err),
126+
})
127+
return
130128
}
131129

132130
var (

services/auth/source/oauth2/providers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func createProvider(providerName string, source *Source) (goth.Provider, error)
182182
}
183183

184184
// always set the name if provider is created so we can support multiple setups of 1 provider
185-
if err == nil && provider != nil {
185+
if provider != nil {
186186
provider.SetName(providerName)
187187
}
188188

services/convert/issue.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,11 @@ func ToLabel(label *issues_model.Label, repo *repo_model.Repository, org *user_m
211211
IsArchived: label.IsArchived(),
212212
}
213213

214+
labelBelongsToRepo := label.BelongsToRepo()
215+
214216
// calculate URL
215-
if label.BelongsToRepo() && repo != nil {
216-
if repo != nil {
217-
result.URL = fmt.Sprintf("%s/labels/%d", repo.APIURL(), label.ID)
218-
} else {
219-
log.Error("ToLabel did not get repo to calculate url for label with id '%d'", label.ID)
220-
}
217+
if labelBelongsToRepo && repo != nil {
218+
result.URL = fmt.Sprintf("%s/labels/%d", repo.APIURL(), label.ID)
221219
} else { // BelongsToOrg
222220
if org != nil {
223221
result.URL = fmt.Sprintf("%sapi/v1/orgs/%s/labels/%d", setting.AppURL, url.PathEscape(org.Name), label.ID)
@@ -226,6 +224,10 @@ func ToLabel(label *issues_model.Label, repo *repo_model.Repository, org *user_m
226224
}
227225
}
228226

227+
if labelBelongsToRepo && repo == nil {
228+
log.Error("ToLabel did not get repo to calculate url for label with id '%d'", label.ID)
229+
}
230+
229231
return result
230232
}
231233

tests/integration/git_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func testGit(t *testing.T, u *url.URL) {
8181
rawTest(t, &httpContext, little, big, littleLFS, bigLFS)
8282
mediaTest(t, &httpContext, little, big, littleLFS, bigLFS)
8383

84-
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &httpContext, "master", "test/head"))
84+
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &httpContext, "test/head"))
8585
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&httpContext, dstPath))
8686
t.Run("AutoMerge", doAutoPRMerge(&httpContext, dstPath))
8787
t.Run("CreatePRAndSetManuallyMerged", doCreatePRAndSetManuallyMerged(httpContext, httpContext, dstPath, "master", "test-manually-merge"))
@@ -122,7 +122,7 @@ func testGit(t *testing.T, u *url.URL) {
122122
rawTest(t, &sshContext, little, big, littleLFS, bigLFS)
123123
mediaTest(t, &sshContext, little, big, littleLFS, bigLFS)
124124

125-
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &sshContext, "master", "test/head2"))
125+
t.Run("CreateAgitFlowPull", doCreateAgitFlowPull(dstPath, &sshContext, "test/head2"))
126126
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&sshContext, dstPath))
127127
t.Run("MergeFork", func(t *testing.T) {
128128
defer tests.PrintCurrentTest(t)()
@@ -329,9 +329,6 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin
329329
}
330330
written += n
331331
}
332-
if err != nil {
333-
return "", err
334-
}
335332

336333
// Commit
337334
// Now here we should explicitly allow lfs filters to run
@@ -693,7 +690,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
693690
}
694691
}
695692

696-
func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headBranch string) func(t *testing.T) {
693+
func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, headBranch string) func(t *testing.T) {
697694
return func(t *testing.T) {
698695
defer tests.PrintCurrentTest(t)()
699696

0 commit comments

Comments
 (0)