Skip to content

Commit bf43db1

Browse files
authored
Fix cli command restore-repo: "units" should be parsed as cli.String (#20183) (#20187)
1 parent 3e4fe00 commit bf43db1

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

cmd/dump_repo.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ func runDumpRepository(ctx *cli.Context) error {
128128
} else {
129129
units := strings.Split(ctx.String("units"), ",")
130130
for _, unit := range units {
131-
switch strings.ToLower(unit) {
131+
switch strings.ToLower(strings.TrimSpace(unit)) {
132+
case "":
133+
continue
132134
case "wiki":
133135
opts.Wiki = true
134136
case "issues":
@@ -145,6 +147,8 @@ func runDumpRepository(ctx *cli.Context) error {
145147
opts.Comments = true
146148
case "pull_requests":
147149
opts.PullRequests = true
150+
default:
151+
return errors.New("invalid unit: " + unit)
148152
}
149153
}
150154
}

cmd/restore_repo.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77
import (
88
"errors"
99
"net/http"
10+
"strings"
1011

1112
"code.gitea.io/gitea/modules/log"
1213
"code.gitea.io/gitea/modules/private"
@@ -37,10 +38,10 @@ var CmdRestoreRepository = cli.Command{
3738
Value: "",
3839
Usage: "Restore destination repository name",
3940
},
40-
cli.StringSliceFlag{
41+
cli.StringFlag{
4142
Name: "units",
42-
Value: nil,
43-
Usage: `Which items will be restored, one or more units should be repeated with this flag.
43+
Value: "",
44+
Usage: `Which items will be restored, one or more units should be separated as comma.
4445
wiki, issues, labels, releases, release_assets, milestones, pull_requests, comments are allowed. Empty means all units.`,
4546
},
4647
cli.BoolFlag{
@@ -55,13 +56,16 @@ func runRestoreRepository(c *cli.Context) error {
5556
defer cancel()
5657

5758
setting.LoadFromExisting()
58-
59+
var units []string
60+
if s := c.String("units"); s != "" {
61+
units = strings.Split(s, ",")
62+
}
5963
statusCode, errStr := private.RestoreRepo(
6064
ctx,
6165
c.String("repo_dir"),
6266
c.String("owner_name"),
6367
c.String("repo_name"),
64-
c.StringSlice("units"),
68+
units,
6569
c.Bool("validation"),
6670
)
6771
if statusCode == http.StatusOK {

services/migrations/dump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func updateOptionsUnits(opts *base.MigrateOptions, units []string) error {
590590
opts.ReleaseAssets = true
591591
} else {
592592
for _, unit := range units {
593-
switch strings.ToLower(unit) {
593+
switch strings.ToLower(strings.TrimSpace(unit)) {
594594
case "":
595595
continue
596596
case "wiki":

0 commit comments

Comments
 (0)