]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix so hugo get -u updates transitively
authorRazon Yang <razonyang@gmail.com>
Sun, 22 Oct 2023 14:32:01 +0000 (22:32 +0800)
committerGitHub <noreply@github.com>
Sun, 22 Oct 2023 14:32:01 +0000 (16:32 +0200)
modules/client.go
testscripts/commands/mod_get.txt [new file with mode: 0644]
testscripts/commands/mod_get_u.txt [new file with mode: 0644]

index b41ca142a992e4e6c7cc9768e3d999804877bb25..b9a2a48d4d2d1d9d3096d7801dec80b85544ecc6 100644 (file)
@@ -318,14 +318,33 @@ func (c *Client) Get(args ...string) error {
                patch := update && (args[0] == "-u=patch") //
 
                // We need to be explicit about the modules to get.
-               for _, m := range c.moduleConfig.Imports {
-                       if !isProbablyModule(m.Path) {
-                               // Skip themes/components stored below /themes etc.
-                               // There may be false positives in the above, but those
-                               // should be rare, and they will fail below with an
-                               // "cannot find module providing ..." message.
-                               continue
+               var modules []string
+               // Update all active modules if the -u flag presents.
+               if update {
+                       mc, coll := c.collect(true)
+                       if coll.err != nil {
+                               return coll.err
                        }
+                       for _, m := range mc.AllModules {
+                               if m.Owner() == nil {
+                                       continue
+                               }
+                               modules = append(modules, m.Path())
+                       }
+               } else {
+                       for _, m := range c.moduleConfig.Imports {
+                               if !isProbablyModule(m.Path) {
+                                       // Skip themes/components stored below /themes etc.
+                                       // There may be false positives in the above, but those
+                                       // should be rare, and they will fail below with an
+                                       // "cannot find module providing ..." message.
+                                       continue
+                               }
+                               modules = append(modules, m.Path)
+                       }
+               }
+
+               for _, m := range modules {
                        var args []string
 
                        if update && !patch {
@@ -333,7 +352,7 @@ func (c *Client) Get(args ...string) error {
                        } else if update && patch {
                                args = append(args, "-u=patch")
                        }
-                       args = append(args, m.Path)
+                       args = append(args, m)
 
                        if err := c.get(args...); err != nil {
                                return err
diff --git a/testscripts/commands/mod_get.txt b/testscripts/commands/mod_get.txt
new file mode 100644 (file)
index 0000000..d11d3b8
--- /dev/null
@@ -0,0 +1,15 @@
+hugo mod get
+stderr 'withhugotoml.*v1.1.0'
+
+-- hugo.toml --
+title = "Hugo Modules Test"
+[module]
+[[module.imports]]
+path="github.com/gohugoio/hugo-mod-integrationtests/withconfigtoml"
+disable = true
+[[module.imports]]
+path="github.com/gohugoio/hugo-mod-integrationtests/withhugotoml"
+-- go.mod --
+module foo
+go 1.20
+
diff --git a/testscripts/commands/mod_get_u.txt b/testscripts/commands/mod_get_u.txt
new file mode 100644 (file)
index 0000000..b070309
--- /dev/null
@@ -0,0 +1,20 @@
+hugo mod get -u
+hugo mod graph
+stdout 'commonmod@v1.0.1.*commonmod2@v1.0.2'
+
+-- hugo.toml --
+title = "Hugo Modules Update Test"
+[module]
+[[module.imports]]
+path="github.com/gohugoio/hugo-mod-integrationtests/withconfigtoml"
+disable = true
+[[module.imports]]
+path="github.com/gohugoio/hugo-mod-integrationtests/withhugotoml"
+-- go.mod --
+module foo
+go 1.20
+require (
+  github.com/gohugoio/hugo-mod-integrationtests/withhugotoml v1.1.0 // indirect
+  github.com/gohugoio/hugo-mod-integrationtests/commonmod v0.0.0-20230823103305-919cefe8a425 // indirect
+)
+