diff --git a/cmd/dump.go b/cmd/dump.go index eddd9f7c008..aa22b0c96d9 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -90,7 +90,7 @@ func newDumpCommand() *cli.Command { }, &cli.StringFlag{ Name: "type", - Usage: `Dump output format, default to "zip", supported types: ` + strings.Join(dump.SupportedOutputTypes, ", "), + Usage: `Dump output format, default to the --file extension if supported, else "zip", supported types: ` + strings.Join(dump.SupportedOutputTypes, ", "), }, }, } diff --git a/modules/dump/dumper.go b/modules/dump/dumper.go index 7e0c22353bf..7499a7938c3 100644 --- a/modules/dump/dumper.go +++ b/modules/dump/dumper.go @@ -34,15 +34,11 @@ func PrepareFileNameAndType(argFile, argType string) (outFileName, outType strin outType = argType outFileName = fmt.Sprintf("gitea-dump-%d.%s", timeutil.TimeStampNow(), outType) } else if argType == "" { - if filepath.Ext(outFileName) == "" { - outType = SupportedOutputTypes[0] - outFileName = argFile - } else { - for _, t := range SupportedOutputTypes { - if strings.HasSuffix(argFile, "."+t) { - outFileName = argFile - outType = t - } + outFileName, outType = argFile, SupportedOutputTypes[0] + for _, t := range SupportedOutputTypes { + if strings.HasSuffix(argFile, "."+t) { + outType = t + break } } } else { diff --git a/modules/dump/dumper_test.go b/modules/dump/dumper_test.go index b713c87121b..86c5141f3e5 100644 --- a/modules/dump/dumper_test.go +++ b/modules/dump/dumper_test.go @@ -47,9 +47,11 @@ func TestPrepareFileNameAndType(t *testing.T) { test("a.zip", "tar.gz", "a.zip", "tar.gz") test("a.zip", "no-such", "", "") - test("a.tar.gz", "", "a.tar.gz", "zip") + test("a.tar.gz", "", "a.tar.gz", "tar.gz") test("a.tar.gz", "tar.gz", "a.tar.gz", "tar.gz") test("a.tar.gz", "no-such", "", "") + + test("a.b", "", "a.b", "zip") } func TestIsSubDir(t *testing.T) {