How to point to a specific commit in my fork of a Hugo module?


I forked this repository to contribute to it:
In my fork, I have added this commit on a branch:

I have a project with this snippet in config/_default/module.yaml:

- path: ""
  disable: false
  ignoreConfig: false
  ignoreImports: false

replacements: " ->"

But I can’t get it to point to my exact commit in my forked repo:

$ hugo mod get
WARN 2021/11/23 21:59:05 module "" not found; either add it as a Hugo Module or store it in "/Users/ringods/Projects/personal/blog/themes".: module does not exist

Is there any way I can point the module to use my specific commit while my pull request is pending merge upstream?


This should do the trick:

go get

go get can probably be replaced with hugo mod get.

Be careful with hugo mod get -u ./... after that. It might move you to the latest commit.

The Golang docs about modules are at Written very technical, but the more often I read them the more I understand :wink:

Edit: This introduction is probably better reading material.

1 Like

My expectation on the replacements directive in a module.yaml file is that it was an exact passthrough to the replace directive in a go.mod. It seems I’m wrong on that. I eventually got it working by removing the replacements from my module.yaml file.

My module.yaml file only contains this:

- path: ""
  disable: false
  ignoreConfig: false
  ignoreImports: false

In my go.mod, I put this replace directive:

replace => v0.0.0-20211118211528-55c73149b546

I now get better results:

$ hugo mod get
hugo: downloading modules …
go: downloading v0.0.0-20211118161839-c32869986fd2
go: downloading v0.0.0-20211118211528-55c73149b546
go get: added v0.0.0-00010101000000-000000000000
hugo: collected modules in 5286 ms
Time: 0h:00m:10s

It’s not. It’s a replacement of any path defined in any config.toml in your dependency tree (if I remember correctly). I do agree that is a limitation, but I have limited control over how Go Modules behaves.

So, if you want to change a version, you need to do so in go.mod – on your module. You can of course add a replacement in go.mod too, of course, but I don’t think the replacement directive there supports versioning.

Well, I thought I had it, but I’m not there yet. The module, where I include the fork is my theme module, which in itself is also included in my blog module. At that level, it doesn’t work as the module in my fork is non-existent yet in the upstream repo:

$ hugo mod get -u
go mod download: invalid version: unknown revision 55c73149b546
An unknown revision most likely means that someone has deleted the remote ref (e.g. with a force push to GitHub).
To resolve this, you need to manually edit your go.mod file and replace the version for the module in question with a valid ref.

The easiest is to just enter a valid branch name there, e.g. master, which would be what you put in place of 'v0.5.1' in the example below.

require v0.5.1

If you then run 'hugo mod graph' it should resolve itself to the most recent version (or commit if no semver versions are available).
hugo: collected modules in 1062 ms
WARN 2021/11/24 21:55:21 failed to download modules: go command failed: go mod download: invalid version: unknown revision 55c73149b546

At my blog level, the replace directive in my theme module is not picked up it seems.