Skip to content

Commit 7c1f18a

Browse files
authored
Fix cli command restore-repo: "units" should be splitted to string slice, to match the old behavior and match the dump-repo's behavior (#20183)
1 parent 2eb713b commit 7c1f18a

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

cmd/dump_repo.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ func runDumpRepository(ctx *cli.Context) error {
134134
} else {
135135
units := strings.Split(ctx.String("units"), ",")
136136
for _, unit := range units {
137-
switch strings.ToLower(unit) {
137+
switch strings.ToLower(strings.TrimSpace(unit)) {
138+
case "":
139+
continue
138140
case "wiki":
139141
opts.Wiki = true
140142
case "issues":
@@ -151,6 +153,8 @@ func runDumpRepository(ctx *cli.Context) error {
151153
opts.Comments = true
152154
case "pull_requests":
153155
opts.PullRequests = true
156+
default:
157+
return errors.New("invalid unit: " + unit)
154158
}
155159
}
156160
}

cmd/restore_repo.go

+9-5
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

+1-1
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)