From 906ecfd173a70650250288d7b0a6730aaeddd14f Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 8 Mar 2021 13:50:57 +0000 Subject: [PATCH] Re-enable import local paths after reversion from #13610 (#14925) (#14927) Backport #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 b3ecb8114a4..bb1b572e74f 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 3bad5cfd736..e8b71bb325b 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 }