modules: Do not check for remote modules if main project is vendored
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 14 Nov 2019 11:24:55 +0000 (12:24 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 14 Nov 2019 11:24:55 +0000 (12:24 +0100)
Fixes #6506

modules/client_test.go
modules/collect.go

index 8bb9df8655d7575c266013cdccf602bfc793cf9d..07b71c4091d0f6ed58eff09425128d1776cee0ab 100644 (file)
@@ -78,9 +78,9 @@ github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/h
        c.Assert(client.Vendor(), qt.IsNil)
        graphb.Reset()
        c.Assert(client.Graph(&graphb), qt.IsNil)
-       expectVendored := `github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0+vendor
-github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2_1v@v1.3.0+vendor
-github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
+       expectVendored := `project github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0+vendor
+project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_1v@v1.3.0+vendor
+project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
 `
        c.Assert(graphb.String(), qt.Equals, expectVendored)
 
index 731a991b80dc1be64ce6b118ba75f0c244332d31..f5972a5b0393a881c748c1db946df7f831bd8552 100644 (file)
@@ -191,6 +191,11 @@ func (c *collector) initModules() error {
        c.collected = &collected{
                seen:     make(map[string]bool),
                vendored: make(map[string]vendoredModule),
+               gomods:   goModules{},
+       }
+
+       if !c.ccfg.IgnoreVendor && c.isVendored(c.ccfg.WorkingDir) {
+               return nil
        }
 
        // We may fail later if we don't find the mods.
@@ -463,6 +468,7 @@ func (c *collector) applyThemeConfig(tc *moduleAdapter) error {
 }
 
 func (c *collector) collect() {
+
        if err := c.initModules(); err != nil {
                c.err = err
                return
@@ -480,6 +486,11 @@ func (c *collector) collect() {
 
 }
 
+func (c *collector) isVendored(dir string) bool {
+       _, err := c.fs.Stat(filepath.Join(dir, vendord, vendorModulesFilename))
+       return err == nil
+}
+
 func (c *collector) collectModulesTXT(owner Module) error {
        vendorDir := filepath.Join(owner.Dir(), vendord)
        filename := filepath.Join(vendorDir, vendorModulesFilename)