hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 49ef6472039ede7d485242eba511207a8274495a
parent 8f08cdd0ac6a2decd5aa5c9c12c0b2c264f9a989
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Thu, 30 Jan 2020 09:08:49 +0100

modules: Fix "hugo mod get -u" with no arguments

Fixes #6826
Closes #6825

Diffstat:
Mcommands/commandeer.go | 12++----------
Mcommands/mod.go | 1+
Mhugolib/config.go | 12+++---------
Mmodules/client.go | 27+++++++++++++++++++++++++++
4 files changed, 33 insertions(+), 19 deletions(-)
diff --git a/commands/commandeer.go b/commands/commandeer.go
@@ -20,8 +20,6 @@ import (
 
 	"golang.org/x/sync/semaphore"
 
-	"github.com/gohugoio/hugo/modules"
-
 	"io/ioutil"
 
 	"github.com/gohugoio/hugo/common/herrors"
@@ -312,14 +310,8 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error {
 		doWithCommandeer,
 		doWithConfig)
 
-	if err != nil {
-		if mustHaveConfigFile {
-			return err
-		}
-		if err != hugolib.ErrNoConfigFile && !modules.IsNotExist(err) {
-			return err
-		}
-
+	if err != nil && mustHaveConfigFile {
+		return err
 	} else if mustHaveConfigFile && len(configFiles) == 0 {
 		return hugolib.ErrNoConfigFile
 	}
diff --git a/commands/mod.go b/commands/mod.go
@@ -77,6 +77,7 @@ Run "go help get" for more information. All flags available for "go get" is also
 ` + commonUsage,
 			RunE: func(cmd *cobra.Command, args []string) error {
 				return c.withModsClient(false, func(c *modules.Client) error {
+
 					// We currently just pass on the flags we get to Go and
 					// need to do the flag handling manually.
 					if len(args) == 1 && args[0] == "-h" {
diff --git a/hugolib/config.go b/hugolib/config.go
@@ -225,15 +225,12 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
 	}
 
 	_, modulesConfigFiles, err := l.collectModules(modulesConfig, v, collectHook)
-	if err != nil {
-		return v, configFiles, err
-	}
 
-	if len(modulesConfigFiles) > 0 {
+	if err == nil && len(modulesConfigFiles) > 0 {
 		configFiles = append(configFiles, modulesConfigFiles...)
 	}
 
-	return v, configFiles, nil
+	return v, configFiles, err
 
 }
 
@@ -465,9 +462,6 @@ func (l configLoader) collectModules(modConfig modules.Config, v1 *viper.Viper, 
 	v1.Set("modulesClient", modulesClient)
 
 	moduleConfig, err := modulesClient.Collect()
-	if err != nil {
-		return nil, nil, err
-	}
 
 	// Avoid recreating these later.
 	v1.Set("allModules", moduleConfig.ActiveModules)
@@ -478,7 +472,7 @@ func (l configLoader) collectModules(modConfig modules.Config, v1 *viper.Viper, 
 		configFilenames = append(configFilenames, moduleConfig.GoModulesFilename)
 	}
 
-	return moduleConfig.ActiveModules, configFilenames, nil
+	return moduleConfig.ActiveModules, configFilenames, err
 
 }
 
diff --git a/modules/client.go b/modules/client.go
@@ -259,6 +259,28 @@ func (c *Client) Vendor() error {
 
 // Get runs "go get" with the supplied arguments.
 func (c *Client) Get(args ...string) error {
+	if len(args) == 0 || (len(args) == 1 && args[0] == "-u") {
+		update := len(args) != 0
+
+		// We need to be explicit about the modules to get.
+		for _, m := range c.moduleConfig.Imports {
+			var args []string
+			if update {
+				args = []string{"-u"}
+			}
+			args = append(args, m.Path)
+			if err := c.get(args...); err != nil {
+				return err
+			}
+		}
+
+		return nil
+	}
+
+	return c.get(args...)
+}
+
+func (c *Client) get(args ...string) error {
 	if err := c.runGo(context.Background(), c.logger.Out, append([]string{"get"}, args...)...); err != nil {
 		errors.Wrapf(err, "failed to get %q", args)
 	}
@@ -426,6 +448,11 @@ func (c *Client) runGo(
 			return nil
 		}
 
+		if strings.Contains(stderr.String(), "invalid version: unknown revision") {
+			// See https://github.com/gohugoio/hugo/issues/6825
+			c.logger.FEEDBACK.Println(`hugo: you need to manually edit go.mod to resolve the unknown revision.`)
+		}
+
 		_, ok := err.(*exec.ExitError)
 		if !ok {
 			return errors.Errorf("failed to execute 'go %v': %s %T", args, err, err)