From eb576269d4fe83684c6946c2fa65038391362075 Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 8 Mar 2021 13:10:17 +0000 Subject: [PATCH] Re-enable import local paths after reversion from #13610 (#14925) PR #13610 unfortunately disabled importing repositories from local paths. This PR restores this functionality. Fix #14700 Signed-off-by: Andrew Thornton --- modules/migrations/migrate.go | 7 +++++++ modules/migrations/migrate_test.go | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/modules/migrations/migrate.go b/modules/migrations/migrate.go index b9c17478a9..656b78a584 100644 --- a/modules/migrations/migrate.go +++ b/modules/migrations/migrate.go @@ -52,6 +52,13 @@ func isMigrateURLAllowed(remoteURL string) error { } } + if u.Host == "" { + if !setting.ImportLocalPaths { + return &models.ErrMigrationNotAllowed{Host: ""} + } + return nil + } + if !setting.Migrations.AllowLocalNetworks { addrList, err := net.LookupIP(strings.Split(u.Host, ":")[0]) if err != nil { diff --git a/modules/migrations/migrate_test.go b/modules/migrations/migrate_test.go index 3bad5cfd73..e8b71bb325 100644 --- a/modules/migrations/migrate_test.go +++ b/modules/migrations/migrate_test.go @@ -31,4 +31,16 @@ func TestMigrateWhiteBlocklist(t *testing.T) { err = isMigrateURLAllowed("https://github.com/go-gitea/gitea.git") assert.Error(t, err) + + old := setting.ImportLocalPaths + setting.ImportLocalPaths = false + + err = isMigrateURLAllowed("/home/foo/bar/goo") + assert.Error(t, err) + + setting.ImportLocalPaths = true + err = isMigrateURLAllowed("/home/foo/bar/goo") + assert.NoError(t, err) + + setting.ImportLocalPaths = old }