Skip to content

Commit

Permalink
Fix so hugo get -u updates transitively
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang authored Oct 22, 2023
1 parent c23a0c4 commit de4e466
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
35 changes: 27 additions & 8 deletions modules/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,22 +318,41 @@ 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 {
args = append(args, "-u")
} 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
Expand Down
15 changes: 15 additions & 0 deletions testscripts/commands/mod_get.txt
Original file line number Diff line number Diff line change
@@ -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

20 changes: 20 additions & 0 deletions testscripts/commands/mod_get_u.txt
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit de4e466

Please sign in to comment.