@@ -6,13 +6,15 @@ package cmd
6
6
7
7
import (
8
8
"context"
9
+ "errors"
9
10
"strings"
10
11
11
12
"code.gitea.io/gitea/modules/convert"
12
13
"code.gitea.io/gitea/modules/log"
13
14
"code.gitea.io/gitea/modules/migrations"
14
15
"code.gitea.io/gitea/modules/migrations/base"
15
16
"code.gitea.io/gitea/modules/setting"
17
+ "code.gitea.io/gitea/modules/structs"
16
18
17
19
"github.com/urfave/cli"
18
20
)
@@ -27,7 +29,7 @@ var CmdDumpRepository = cli.Command{
27
29
cli.StringFlag {
28
30
Name : "git_service" ,
29
31
Value : "" ,
30
- Usage : "Git service, git, github, gitea, gitlab" ,
32
+ Usage : "Git service, git, github, gitea, gitlab. If clone_addr could be recognized, this could be ignored. " ,
31
33
},
32
34
cli.StringFlag {
33
35
Name : "repo_dir, r" ,
@@ -84,9 +86,27 @@ func runDumpRepository(ctx *cli.Context) error {
84
86
log .Trace ("Log path: %s" , setting .LogRootPath )
85
87
setting .InitDBConfig ()
86
88
89
+ var (
90
+ serviceType structs.GitServiceType
91
+ cloneAddr = ctx .String ("clone_addr" )
92
+ serviceStr = ctx .String ("git_service" )
93
+ )
94
+
95
+ if strings .HasPrefix (strings .ToLower (cloneAddr ), "https://github.com/" ) {
96
+ serviceStr = "github"
97
+ } else if strings .HasPrefix (strings .ToLower (cloneAddr ), "https://gitlab.com/" ) {
98
+ serviceStr = "gitlab"
99
+ } else if strings .HasPrefix (strings .ToLower (cloneAddr ), "https://gitea.com/" ) {
100
+ serviceStr = "gitea"
101
+ }
102
+ if serviceStr == "" {
103
+ return errors .New ("git_service missed or clone_addr cannot be recognized" )
104
+ }
105
+ serviceType = convert .ToGitServiceType (serviceStr )
106
+
87
107
var opts = base.MigrateOptions {
88
- GitServiceType : convert . ToGitServiceType ( ctx . String ( "git_service" )) ,
89
- CloneAddr : ctx . String ( "clone_addr" ) ,
108
+ GitServiceType : serviceType ,
109
+ CloneAddr : cloneAddr ,
90
110
AuthUsername : ctx .String ("auth_username" ),
91
111
AuthPassword : ctx .String ("auth_password" ),
92
112
AuthToken : ctx .String ("auth_token" ),
0 commit comments