@@ -6,13 +6,15 @@ package cmd
66
77import (
88 "context"
9+ "errors"
910 "strings"
1011
1112 "code.gitea.io/gitea/modules/convert"
1213 "code.gitea.io/gitea/modules/log"
1314 "code.gitea.io/gitea/modules/migrations"
1415 "code.gitea.io/gitea/modules/migrations/base"
1516 "code.gitea.io/gitea/modules/setting"
17+ "code.gitea.io/gitea/modules/structs"
1618
1719 "github.com/urfave/cli"
1820)
@@ -27,7 +29,7 @@ var CmdDumpRepository = cli.Command{
2729 cli.StringFlag {
2830 Name : "git_service" ,
2931 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. " ,
3133 },
3234 cli.StringFlag {
3335 Name : "repo_dir, r" ,
@@ -84,9 +86,27 @@ func runDumpRepository(ctx *cli.Context) error {
8486 log .Trace ("Log path: %s" , setting .LogRootPath )
8587 setting .InitDBConfig ()
8688
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+
87107 var opts = base.MigrateOptions {
88- GitServiceType : convert . ToGitServiceType ( ctx . String ( "git_service" )) ,
89- CloneAddr : ctx . String ( "clone_addr" ) ,
108+ GitServiceType : serviceType ,
109+ CloneAddr : cloneAddr ,
90110 AuthUsername : ctx .String ("auth_username" ),
91111 AuthPassword : ctx .String ("auth_password" ),
92112 AuthToken : ctx .String ("auth_token" ),
0 commit comments