forked from forgejo/forgejo
[FEAT] Allow non-explicit push options
- Currently the parsing of the push options require that `=` is present in the value, however we shouldn't be that strict and assume if that's not set the value is `true`. - This allow for more natural commands, so become `-o force-push=true` simply `-o force-push`. - Add unit test.
This commit is contained in:
parent
7d35a76ebf
commit
f5ad6d4be5
3 changed files with 24 additions and 7 deletions
14
cmd/hook.go
14
cmd/hook.go
|
@ -488,10 +488,11 @@ func pushOptions() map[string]string {
|
|||
if pushCount, err := strconv.Atoi(os.Getenv(private.GitPushOptionCount)); err == nil {
|
||||
for idx := 0; idx < pushCount; idx++ {
|
||||
opt := os.Getenv(fmt.Sprintf("GIT_PUSH_OPTION_%d", idx))
|
||||
kv := strings.SplitN(opt, "=", 2)
|
||||
if len(kv) == 2 {
|
||||
opts[kv[0]] = kv[1]
|
||||
key, value, found := strings.Cut(opt, "=")
|
||||
if !found {
|
||||
value = "true"
|
||||
}
|
||||
opts[key] = value
|
||||
}
|
||||
}
|
||||
return opts
|
||||
|
@ -631,10 +632,11 @@ Forgejo or set your environment appropriately.`, "")
|
|||
break
|
||||
}
|
||||
|
||||
kv := strings.SplitN(string(rs.Data), "=", 2)
|
||||
if len(kv) == 2 {
|
||||
hookOptions.GitPushOptions[kv[0]] = kv[1]
|
||||
key, value, found := strings.Cut(string(rs.Data), "=")
|
||||
if !found {
|
||||
value = "true"
|
||||
}
|
||||
hookOptions.GitPushOptions[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue