mirror of
https://github.com/harness/drone.git
synced 2025-05-17 01:20:13 +08:00
fix for branch create in empty repo, minor config changes for err shadow
This commit is contained in:
parent
75ec201c2b
commit
e38b0ebc65
@ -297,6 +297,8 @@ issues:
|
|||||||
max-same-issues: 50
|
max-same-issues: 50
|
||||||
|
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
|
- text: 'shadow: declaration of "err" shadows declaration at'
|
||||||
|
linters: [ govet ]
|
||||||
- source: "^//\\s*go:generate\\s"
|
- source: "^//\\s*go:generate\\s"
|
||||||
linters: [ lll ]
|
linters: [ lll ]
|
||||||
- source: "(noinspection|TODO)"
|
- source: "(noinspection|TODO)"
|
||||||
|
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -18,7 +18,7 @@
|
|||||||
"type": "go",
|
"type": "go",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "auto",
|
"mode": "auto",
|
||||||
"program": "${workspaceFolder}",
|
"program": "cmd/gitness",
|
||||||
"args": ["server", "../../.local.env"]
|
"args": ["server", "../../.local.env"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -7,7 +7,6 @@ package gitrpc
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/harness/gitness/gitrpc/rpc"
|
"github.com/harness/gitness/gitrpc/rpc"
|
||||||
@ -31,19 +30,19 @@ func (params *BlameParams) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if params.GitRef == "" {
|
if params.GitRef == "" {
|
||||||
return fmt.Errorf("git ref needs to be provided: %w", ErrInvalidArgument)
|
return Errorf(StatusInvalidArgument, "git ref needs to be provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.Path == "" {
|
if params.Path == "" {
|
||||||
return fmt.Errorf("file path needs to be provided: %w", ErrInvalidArgument)
|
return Errorf(StatusInvalidArgument, "file path needs to be provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.LineFrom < 0 || params.LineTo < 0 {
|
if params.LineFrom < 0 || params.LineTo < 0 {
|
||||||
return fmt.Errorf("line from and line to can't be negative: %w", ErrInvalidArgument)
|
return Errorf(StatusInvalidArgument, "line from and line to can't be negative")
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.LineTo > 0 && params.LineFrom > params.LineTo {
|
if params.LineTo > 0 && params.LineFrom > params.LineTo {
|
||||||
return fmt.Errorf("line from can't be after line after: %w", ErrInvalidArgument)
|
return Errorf(StatusInvalidArgument, "line from can't be after line after")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -36,6 +36,10 @@ func (s ReferenceService) CreateBranch(ctx context.Context,
|
|||||||
return nil, processGitErrorf(err, "failed to open repo")
|
return nil, processGitErrorf(err, "failed to open repo")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ok, err := repo.IsEmpty(); ok {
|
||||||
|
return nil, ErrInvalidArgumentf("branch cannot be created on empty repository", err)
|
||||||
|
}
|
||||||
|
|
||||||
sharedRepo, err := NewSharedRepo(s.tmpDir, base.GetRepoUid(), repo)
|
sharedRepo, err := NewSharedRepo(s.tmpDir, base.GetRepoUid(), repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, processGitErrorf(err, "failed to create new shared repo")
|
return nil, processGitErrorf(err, "failed to create new shared repo")
|
||||||
|
@ -64,6 +64,9 @@ func Errorf(code codes.Code, format string, args ...any) (err error) {
|
|||||||
newargs := make([]any, 0, len(args))
|
newargs := make([]any, 0, len(args))
|
||||||
|
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
|
if arg == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
switch t := arg.(type) {
|
switch t := arg.(type) {
|
||||||
case error:
|
case error:
|
||||||
err = t
|
err = t
|
||||||
|
Loading…
Reference in New Issue
Block a user