]> source.dussan.org Git - gitea.git/commitdiff
Re-enable import local paths after reversion from #13610 (#14925) (#14927)
authorzeripath <art27@cantab.net>
Mon, 8 Mar 2021 13:50:57 +0000 (13:50 +0000)
committerGitHub <noreply@github.com>
Mon, 8 Mar 2021 13:50:57 +0000 (14:50 +0100)
Backport #14925

PR #13610 unfortunately disabled importing repositories from local paths.
This PR restores this functionality.

Fix #14700

Signed-off-by: Andrew Thornton <art27@cantab.net>
modules/migrations/migrate.go
modules/migrations/migrate_test.go

index b3ecb8114a402676a553ad69d9289191c41f479a..bb1b572e74f31d4a358b2dfec09281344de6dbe8 100644 (file)
@@ -52,6 +52,13 @@ func isMigrateURLAllowed(remoteURL string) error {
                }
        }
 
+       if u.Host == "" {
+               if !setting.ImportLocalPaths {
+                       return &models.ErrMigrationNotAllowed{Host: "<LOCAL_FILESYSTEM>"}
+               }
+               return nil
+       }
+
        if !setting.Migrations.AllowLocalNetworks {
                addrList, err := net.LookupIP(strings.Split(u.Host, ":")[0])
                if err != nil {
index 3bad5cfd736be14b69f5b1a113d43390db8ac1ec..e8b71bb325bfc692b7f6bf75524c5b204d0e26c4 100644 (file)
@@ -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
 }