gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.68k stars 7.52k forks source link

Improve flag handling in hugo mod get #10719

Closed razonyang closed 11 months ago

razonyang commented 1 year ago

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.110.0-e32a493b7826d02763c3b79623952e625402b168+extended linux/amd64 BuildDate=2023-01-17T12:16:09Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

Log

➜  simple-icons git:(main) pwd
/home/razonyang/Projects/razonyang/hugo-mod-icons/vendors/simple-icons

➜  simple-icons git:(main) cat go.mod
module github.com/razonyang/hugo-mod-icons/vendors/simple-icons

go 1.18

require (
        github.com/razonyang/hugo-mod-icons v0.3.0 // indirect
        github.com/razonyang/simple-icons v8.4.0+incompatible // indirect
)

➜  simple-icons git:(main) hugo mod get -u -v ./...
Update module in /home/razonyang/Projects/razonyang/hugo-mod-icons/vendors/simple-icons
go: no package to get in current directory

➜  simple-icons git:(main) hugo-109 mod get -u -v ./...
Update module in /home/razonyang/Projects/razonyang/hugo-mod-icons/vendors/simple-icons
go: no package to get in current directory

➜  simple-icons git:(main) hugo-104 mod get -u -v ./...
Update module in /home/razonyang/Projects/razonyang/hugo-mod-icons/vendors/simple-icons
go: no package to get in current directory

➜  simple-icons git:(main) hugo-98 mod get -u -v ./...
Update module in /home/razonyang/Projects/razonyang/hugo-mod-icons/vendors/simple-icons
go: no package to get in current directory

➜  simple-icons git:(main) hugo mod get -u -v github.com/razonyang/simple-icons
go: downloading github.com/razonyang/simple-icons v8.5.0+incompatible
go: upgraded github.com/razonyang/simple-icons v8.4.0+incompatible => v8.5.0+incompatible

asciicast

Reproduce Steps

I'm not sure if it's my environment issue.

Btw, I renamed the hugo.toml to config.toml for testing other versions less than 0.110.0.

$ git clone https://github.com/razonyang/hugo-mod-icons.git
$ cd hugo-mod-icons/vendors/simple-icons
$ hugo mod get -u -v ./...
bep commented 1 year ago

I was a little puzzled about this, because everything worked fine for me, testing with my own project and your project, all without hickups. Then I copied and pasted your command "hugo mod get -u -v ./..." ... and boom ...

The thing is, the flag handling in "hugo mod get" is a little peculiar, as we pass on most of the flags to the go command, which had a peculiar effect in your case.

Try running without the -v flag:

hugo mod get -u ./...
razonyang commented 1 year ago

Try running without the -v flag.

$ hugo mod get -u ./...
Update module in /home/razonyang/Projects/razonyang/hb-site
go: downloading github.com/razonyang/hb/modules/base v0.4.0
go: upgraded github.com/razonyang/hb/modules/base v0.3.9 => v0.4.0

$ hugo mod get -u ./...
Update module in /home/razonyang/Projects/razonyang/hb-site

$ cat go.mod | grep hugo-mod-bootstrap
// replace github.com/razonyang/hugo-mod-bootstrap => ../hugo-mod-bootstrap
        github.com/gohugoio/hugo-mod-bootstrap-scss/v5 v5.20200.20101 // indirect
        github.com/razonyang/hugo-mod-bootstrap v0.4.0 // indirect

$ hugo mod get -u github.com/razonyang/hugo-mod-bootstrap
go: downloading github.com/razonyang/hugo-mod-bootstrap v0.5.1
go: upgraded github.com/razonyang/hugo-mod-bootstrap v0.4.0 => v0.5.1

Just tested this in another site, some modules haven't been upgraded until explicitly specify the module after hugo mod get -u.

The v0.5.1 is released yesterday.

I'll try to test this in other environments.

razonyang commented 1 year ago

I just tested this on the US (NY) Server, but same issue reached.

Full steps:

$ git clone https://github.com/razonyang/hb-site.git
Cloning into 'hb-site'...
remote: Enumerating objects: 639, done.
remote: Counting objects: 100% (639/639), done.
remote: Compressing objects: 100% (378/378), done.
remote: Total 639 (delta 204), reused 577 (delta 142), pack-reused 0
Receiving objects: 100% (639/639), 3.01 MiB | 36.64 MiB/s, done.
Resolving deltas: 100% (204/204), done.

$ cd hb-site

$ git checkout b13f5e34d46909a0dd1d35ebc8c2f5645b00f899

$ cat go.mod | grep razonyang/hugo-mod-bootstrap
// replace github.com/razonyang/hugo-mod-bootstrap => ../hugo-mod-bootstrap
        github.com/razonyang/hugo-mod-bootstrap v0.5.1 // indirect

$ echo $HUGO_MODULE_PROXY

$ hugo mod get -u ./...
Update module in /root/hb-site
hugo: collected modules in 1970 ms

$ cat go.mod | grep razonyang/hugo-mod-bootstrap
// replace github.com/razonyang/hugo-mod-bootstrap => ../hugo-mod-bootstrap
        github.com/razonyang/hugo-mod-bootstrap v0.5.1 // indirect

$ hugo mod get -u github.com/razonyang/hugo-mod-bootstrap
go: github.com/razonyang/hugo-mod-bootstrap upgrade => v0.6.4
$ hugo env
hugo v0.111.1-39a4a3cf676533859217805c36181c7a3dfa321c+extended linux/amd64 BuildDate=2023-03-02T10:08:26Z VendorInfo=gohugoio
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.20.1"
github.com/sass/libsass="3.6.5"
github.com/webmproject/libwebp="v1.2.4"
razonyang commented 1 year ago

I realized that the modules not imported directly will not be updated.

The github.com/razonyang/hugo-mod-bootstrap is imported by github.com/razonyang/hb/modules/bootstrap, it works when I declare the module in site's configuration. hugo mod get -u ./... seems won't update requirements of submodules.

$ hugo mod graph | grep razonyang/hugo-mod-bootstrap
github.com/razonyang/hb/modules/bootstrap@v0.1.0 github.com/razonyang/hugo-mod-bootstrap@v0.5.1
$ git diff config/_default/hugo.yml
diff --git a/config/_default/hugo.yml b/config/_default/hugo.yml
index db75644..bcba64f 100644
--- a/config/_default/hugo.yml
+++ b/config/_default/hugo.yml
@@ -11,6 +11,7 @@ module:
   imports:
     # site modules
     - path: github.com/razonyang/hugo-mod-html
+    - path: github.com/razonyang/hugo-mod-bootstrap
     - path: github.com/razonyang/hb/modules/progress-bar
     - path: github.com/razonyang/hb/modules/back-to-top
     - path: github.com/razonyang/hb/modules/base
$ hugo mod get -u
go: github.com/razonyang/hugo-mod-bootstrap upgrade => v0.6.4
markdumay commented 1 year ago

I'm encountering similar issues, although in my repository the update command fails for direct dependencies too. The particular example contains a subfolder exampleSite that references its parent with a module replacement (in exampleSite/config/_default/hugo.toml).

[module]
  replacements = 'github.com/gethinode/hinode -> ../..'
  [[module.imports]]
    path = "github.com/gethinode/hinode"

For some odd reason, the version of the module mod-flexsearch is newer in the exampleSite than in the parent folder:

In this context, it appears that hugo mod get -u works, but adding the recursive flag ./... breaks it. I've created a repository branch to demonstrate the issue - hope it helps in tracking down the issue.

Hugo version

hugo v0.117.0-b2f0696cad918fb61420a6aff173eb36662b406e+extended darwin/arm64 BuildDate=2023-08-07T12:49:48Z VendorInfo=brew

Reproduce the steps

First scenario

git clone https://github.com/gethinode/hinode.git hinode-scenario1 -b hugo-issue-10719 && cd hinode-scenario1
hugo mod get -u ./...
# Update module in [...]/hinode-scenario1/exampleSite
# hugo: downloading modules …
# hugo: collected modules in 2235 ms
hugo mod get github.com/gethinode/mod-flexsearch
# go: upgraded github.com/gethinode/mod-flexsearch v1.2.0 => v1.3.0
cd ..

Second scenario

git clone https://github.com/gethinode/hinode.git hinode-scenario2 -b hugo-issue-10719 && cd hinode-scenario2
hugo mod get -u
# go: upgraded github.com/gethinode/mod-flexsearch v1.2.0 => v1.3.0
jmooring commented 11 months ago

@razonyang Was this resolved with https://github.com/gohugoio/hugo/pull/11573?

razonyang commented 11 months ago

@jmooring thanks for reminding, I forgot this issue.

github-actions[bot] commented 10 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.