forked from kevadesu/forgejo
fix(hook): ignore unknown push options instead of failing
If a repository has
git config --add push.pushOption submit=".sourcehut/*.yml"
it failed when pushed because of the unknown submit push
option. It will be ignored instead.
Filtering out the push options is done in an earlier stage, when the
hook command runs, before it submits the options map to the private
endpoint.
* move all the push options logic to modules/git/pushoptions
* add 100% test coverage for modules/git/pushoptions
Test coverage for the code paths from which code was moved to the
modules/git/pushoptions package:
* cmd/hook.go:runHookPreReceive
* routers/private/hook_pre_receive.go:validatePushOptions
tests/integration/git_push_test.go:TestOptionsGitPush runs through
both. The test verifying the option is rejected was removed and, if
added again, will fail because the option is now ignored instead of
being rejected.
* cmd/hook.go:runHookProcReceive
* services/agit/agit.go:ProcReceive
tests/integration/git_test.go: doCreateAgitFlowPull runs through
both. It uses variations of AGit related push options.
* cmd/hook.go:runHookPostReceive
* routers/private/hook_post_receive.go:HookPostReceive
tests/integration/git_test.go:doPushCreate called by TestGit/HTTP/sha1/PushCreate
runs through both.
Note that although it provides coverage for this code path it does not use push options.
Fixes: https://codeberg.org/forgejo/forgejo/issues/3651
(cherry picked from commit 5561e80b04
)
This commit is contained in:
parent
c290a40063
commit
0d09acf669
10 changed files with 266 additions and 92 deletions
|
@ -7,10 +7,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/git/pushoptions"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
@ -20,28 +20,8 @@ const (
|
|||
GitAlternativeObjectDirectories = "GIT_ALTERNATE_OBJECT_DIRECTORIES"
|
||||
GitObjectDirectory = "GIT_OBJECT_DIRECTORY"
|
||||
GitQuarantinePath = "GIT_QUARANTINE_PATH"
|
||||
GitPushOptionCount = "GIT_PUSH_OPTION_COUNT"
|
||||
)
|
||||
|
||||
// GitPushOptions is a wrapper around a map[string]string
|
||||
type GitPushOptions map[string]string
|
||||
|
||||
// GitPushOptions keys
|
||||
const (
|
||||
GitPushOptionRepoPrivate = "repo.private"
|
||||
GitPushOptionRepoTemplate = "repo.template"
|
||||
)
|
||||
|
||||
// Bool checks for a key in the map and parses as a boolean
|
||||
func (g GitPushOptions) Bool(key string, def bool) bool {
|
||||
if val, ok := g[key]; ok {
|
||||
if b, err := strconv.ParseBool(val); err == nil {
|
||||
return b
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
// HookOptions represents the options for the Hook calls
|
||||
type HookOptions struct {
|
||||
OldCommitIDs []string
|
||||
|
@ -52,7 +32,7 @@ type HookOptions struct {
|
|||
GitObjectDirectory string
|
||||
GitAlternativeObjectDirectories string
|
||||
GitQuarantinePath string
|
||||
GitPushOptions GitPushOptions
|
||||
GitPushOptions map[string]string
|
||||
PullRequestID int64
|
||||
PushTrigger repository.PushTrigger
|
||||
DeployKeyID int64 // if the pusher is a DeployKey, then UserID is the repo's org user.
|
||||
|
@ -60,6 +40,10 @@ type HookOptions struct {
|
|||
ActionPerm int
|
||||
}
|
||||
|
||||
func (o *HookOptions) GetGitPushOptions() pushoptions.Interface {
|
||||
return pushoptions.NewFromMap(&o.GitPushOptions)
|
||||
}
|
||||
|
||||
// SSHLogOption ssh log options
|
||||
type SSHLogOption struct {
|
||||
IsError bool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue