diff options
author | kolaente <konrad@kola-entertainments.de> | 2019-06-12 21:41:28 +0200 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-06-12 15:41:28 -0400 |
commit | f9ec2f89f2265bc1371a6c62359de9816534fa6b (patch) | |
tree | f48b138a457e5ac6cf843bbb38400926704370f7 /modules/repofiles | |
parent | 5832f8d90df2d72cb38698c3e9050f2b29717dc7 (diff) | |
download | gitea-f9ec2f89f2265bc1371a6c62359de9816534fa6b.tar.gz gitea-f9ec2f89f2265bc1371a6c62359de9816534fa6b.zip |
Add golangci (#6418)
Diffstat (limited to 'modules/repofiles')
-rw-r--r-- | modules/repofiles/delete.go | 10 | ||||
-rw-r--r-- | modules/repofiles/file.go | 4 | ||||
-rw-r--r-- | modules/repofiles/tree.go | 11 | ||||
-rw-r--r-- | modules/repofiles/update.go | 14 | ||||
-rw-r--r-- | modules/repofiles/upload.go | 8 | ||||
-rw-r--r-- | modules/repofiles/verification.go | 6 |
6 files changed, 26 insertions, 27 deletions
diff --git a/modules/repofiles/delete.go b/modules/repofiles/delete.go index 09a4dbb44c..91910fa860 100644 --- a/modules/repofiles/delete.go +++ b/modules/repofiles/delete.go @@ -53,11 +53,9 @@ func DeleteRepoFile(repo *models.Repository, doer *models.User, opts *DeleteRepo BranchName: opts.NewBranch, } } - } else { - if protected, _ := repo.IsProtectedBranchForPush(opts.OldBranch, doer); protected { - return nil, models.ErrUserCannotCommit{ - UserName: doer.LowerName, - } + } else if protected, _ := repo.IsProtectedBranchForPush(opts.OldBranch, doer); protected { + return nil, models.ErrUserCannotCommit{ + UserName: doer.LowerName, } } @@ -74,10 +72,10 @@ func DeleteRepoFile(repo *models.Repository, doer *models.User, opts *DeleteRepo author, committer := GetAuthorAndCommitterUsers(opts.Committer, opts.Author, doer) t, err := NewTemporaryUploadRepository(repo) - defer t.Close() if err != nil { return nil, err } + defer t.Close() if err := t.Clone(opts.OldBranch); err != nil { return nil, err } diff --git a/modules/repofiles/file.go b/modules/repofiles/file.go index de3ee71dba..70fd57bba0 100644 --- a/modules/repofiles/file.go +++ b/modules/repofiles/file.go @@ -86,7 +86,7 @@ func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *models // If only one of the two are provided, we set both of them to it. // If neither are provided, both are the doer. if committer != nil && committer.Email != "" { - if doer != nil && strings.ToLower(doer.Email) == strings.ToLower(committer.Email) { + if doer != nil && strings.EqualFold(doer.Email, committer.Email) { committerUser = doer // the committer is the doer, so will use their user object if committer.Name != "" { committerUser.FullName = committer.Name @@ -99,7 +99,7 @@ func GetAuthorAndCommitterUsers(author, committer *IdentityOptions, doer *models } } if author != nil && author.Email != "" { - if doer != nil && strings.ToLower(doer.Email) == strings.ToLower(author.Email) { + if doer != nil && strings.EqualFold(doer.Email, author.Email) { authorUser = doer // the author is the doer, so will use their user object if authorUser.Name != "" { authorUser.FullName = author.Name diff --git a/modules/repofiles/tree.go b/modules/repofiles/tree.go index 4eb54a2598..318a5d152d 100644 --- a/modules/repofiles/tree.go +++ b/modules/repofiles/tree.go @@ -16,6 +16,9 @@ import ( // GetTreeBySHA get the GitTreeResponse of a repository using a sha hash. func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recursive bool) (*api.GitTreeResponse, error) { gitRepo, err := git.OpenRepository(repo.RepoPath()) + if err != nil { + return nil, err + } gitTree, err := gitRepo.GetTree(sha) if err != nil || gitTree == nil { return nil, models.ErrSHANotFound{ @@ -39,12 +42,12 @@ func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recurs // 51 is len(sha1) + len("/git/blobs/"). 40 + 11. blobURL := make([]byte, apiURLLen+51) - copy(blobURL[:], apiURL) + copy(blobURL, apiURL) copy(blobURL[apiURLLen:], "/git/blobs/") // 51 is len(sha1) + len("/git/trees/"). 40 + 11. treeURL := make([]byte, apiURLLen+51) - copy(treeURL[:], apiURL) + copy(treeURL, apiURL) copy(treeURL[apiURLLen:], "/git/trees/") // 40 is the size of the sha1 hash in hexadecimal format. @@ -83,10 +86,10 @@ func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recurs if entries[e].IsDir() { copy(treeURL[copyPos:], entries[e].ID.String()) - tree.Entries[i].URL = string(treeURL[:]) + tree.Entries[i].URL = string(treeURL) } else { copy(blobURL[copyPos:], entries[e].ID.String()) - tree.Entries[i].URL = string(blobURL[:]) + tree.Entries[i].URL = string(blobURL) } } return tree, nil diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go index 569c89ac51..f011017a5e 100644 --- a/modules/repofiles/update.go +++ b/modules/repofiles/update.go @@ -99,6 +99,10 @@ func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string } result, n, err := transform.String(charsetEncoding.NewDecoder(), string(buf)) + if err != nil { + // return default + return "UTF-8", false + } if n > 2 { return encoding, bytes.Equal([]byte(result)[0:3], base.UTF8BOM) @@ -135,10 +139,8 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up if err != nil && !git.IsErrBranchNotExist(err) { return nil, err } - } else { - if protected, _ := repo.IsProtectedBranchForPush(opts.OldBranch, doer); protected { - return nil, models.ErrUserCannotCommit{UserName: doer.LowerName} - } + } else if protected, _ := repo.IsProtectedBranchForPush(opts.OldBranch, doer); protected { + return nil, models.ErrUserCannotCommit{UserName: doer.LowerName} } // If FromTreePath is not set, set it to the opts.TreePath @@ -166,10 +168,10 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up author, committer := GetAuthorAndCommitterUsers(opts.Committer, opts.Author, doer) t, err := NewTemporaryUploadRepository(repo) - defer t.Close() if err != nil { - return nil, err + log.Error("%v", err) } + defer t.Close() if err := t.Clone(opts.OldBranch); err != nil { return nil, err } diff --git a/modules/repofiles/upload.go b/modules/repofiles/upload.go index 5f428c3139..2da101c64d 100644 --- a/modules/repofiles/upload.go +++ b/modules/repofiles/upload.go @@ -57,10 +57,10 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep } t, err := NewTemporaryUploadRepository(repo) - defer t.Close() if err != nil { return err } + defer t.Close() if err := t.Clone(opts.OldBranch); err != nil { return err } @@ -108,10 +108,8 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep } infos[i] = uploadInfo - } else { - if objectHash, err = t.HashObject(file); err != nil { - return err - } + } else if objectHash, err = t.HashObject(file); err != nil { + return err } // Add the object to the index diff --git a/modules/repofiles/verification.go b/modules/repofiles/verification.go index be56f9b8b8..9fc084daaf 100644 --- a/modules/repofiles/verification.go +++ b/modules/repofiles/verification.go @@ -20,10 +20,8 @@ func GetPayloadCommitVerification(commit *git.Commit) *structs.PayloadCommitVeri } if verification.Reason != "" { verification.Reason = commitVerification.Reason - } else { - if verification.Verified { - verification.Reason = "unsigned" - } + } else if verification.Verified { + verification.Reason = "unsigned" } return verification } |