Is it possible to configure Hugo Modules per Git branch in one repository?


This is a follow-up question to the following thread:

I verified that Hugo Modules works as @bep’s answer. (Thanks!)

We are managing multiple content repositories, all with a consistent branch scheme (e.g., alpha/beta/production), and need to build sites with aggregated contents per branch.

Is it possible to configure Hugo Modules for each branch in a single repository, similar to what we can do for build configuration? Otherwise, it seems that we must set up separate sites per branch (e.g., project-alpha, project-beta, project-production) with suitable Hugo Modules configuration for each.

So, you cannot control any versioning from the build configuration. That is stored in go.mod, but If I understand you correctly, that should be OK for you. But I may misunderstand.

  • You can set up the module configuration in /config/production /config/testing etc. (e.g. what modules to import where)
  • Then in each branch (which I assume are Git branches) you can switch versions.
  • Then in each branch (which I assume are Git branches) you can switch versions.

I was wondering if it is feasible to manage go.mod differently for each branch. Is it OK to run hugo mod get with different arguments in each Git branch to set up different versioning per branch? Is the Hugo Modules cache stored per repository or per branch…?

By default there is one module cache** – but you can mix and match versions in your branches as much as you want, they will live happily side by side in the cache.

** Tip: My approach to this is to have HUGO_CACHEDIR environment variable defined to something outside /tmp (which I think is the default), which tends to make it more stable (as in: the cache isn’t removed on reboot).

How can we manage the commits for “diverged” go.mod (and go.sum) in Git branches?

If the situation is like the following:

M: commit on master branch for fetching from master branch of all content repositories
A: commit on alpha branch for fetching from alpha branch of all content repositories
B: commit on beta branch for fetching from beta branch of all content repositories
Cn: Subsequent commits

---- M ----------C1-------C2------
          ---- A -----------------------
          ---- B -----------------------

Can we manage this branching scheme properly without affecting the subsequent commits and merge tasks between branches?

This may be essentially a Git question, but I’d appreciate some word of advice from more experienced users of Hugo.