Skip to content

Commit de4e466

Browse files
authoredOct 22, 2023
Fix so hugo get -u updates transitively
1 parent c23a0c4 commit de4e466

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed
 

‎modules/client.go

+27-8
Original file line numberDiff line numberDiff line change
@@ -318,22 +318,41 @@ func (c *Client) Get(args ...string) error {
318318
patch := update && (args[0] == "-u=patch") //
319319

320320
// We need to be explicit about the modules to get.
321-
for _, m := range c.moduleConfig.Imports {
322-
if !isProbablyModule(m.Path) {
323-
// Skip themes/components stored below /themes etc.
324-
// There may be false positives in the above, but those
325-
// should be rare, and they will fail below with an
326-
// "cannot find module providing ..." message.
327-
continue
321+
var modules []string
322+
// Update all active modules if the -u flag presents.
323+
if update {
324+
mc, coll := c.collect(true)
325+
if coll.err != nil {
326+
return coll.err
328327
}
328+
for _, m := range mc.AllModules {
329+
if m.Owner() == nil {
330+
continue
331+
}
332+
modules = append(modules, m.Path())
333+
}
334+
} else {
335+
for _, m := range c.moduleConfig.Imports {
336+
if !isProbablyModule(m.Path) {
337+
// Skip themes/components stored below /themes etc.
338+
// There may be false positives in the above, but those
339+
// should be rare, and they will fail below with an
340+
// "cannot find module providing ..." message.
341+
continue
342+
}
343+
modules = append(modules, m.Path)
344+
}
345+
}
346+
347+
for _, m := range modules {
329348
var args []string
330349

331350
if update && !patch {
332351
args = append(args, "-u")
333352
} else if update && patch {
334353
args = append(args, "-u=patch")
335354
}
336-
args = append(args, m.Path)
355+
args = append(args, m)
337356

338357
if err := c.get(args...); err != nil {
339358
return err

‎testscripts/commands/mod_get.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
hugo mod get
2+
stderr 'withhugotoml.*v1.1.0'
3+
4+
-- hugo.toml --
5+
title = "Hugo Modules Test"
6+
[module]
7+
[[module.imports]]
8+
path="github.com/gohugoio/hugo-mod-integrationtests/withconfigtoml"
9+
disable = true
10+
[[module.imports]]
11+
path="github.com/gohugoio/hugo-mod-integrationtests/withhugotoml"
12+
-- go.mod --
13+
module foo
14+
go 1.20
15+

‎testscripts/commands/mod_get_u.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
hugo mod get -u
2+
hugo mod graph
3+
stdout 'commonmod@v1.0.1.*commonmod2@v1.0.2'
4+
5+
-- hugo.toml --
6+
title = "Hugo Modules Update Test"
7+
[module]
8+
[[module.imports]]
9+
path="github.com/gohugoio/hugo-mod-integrationtests/withconfigtoml"
10+
disable = true
11+
[[module.imports]]
12+
path="github.com/gohugoio/hugo-mod-integrationtests/withhugotoml"
13+
-- go.mod --
14+
module foo
15+
go 1.20
16+
require (
17+
github.com/gohugoio/hugo-mod-integrationtests/withhugotoml v1.1.0 // indirect
18+
github.com/gohugoio/hugo-mod-integrationtests/commonmod v0.0.0-20230823103305-919cefe8a425 // indirect
19+
)
20+

0 commit comments

Comments
 (0)