From 273d9f69a6cb46ce632b340ebb1191e2e083323b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 27 May 2023 16:07:56 +0200 Subject: [PATCH] commands: Fail the build when no config file or config dir Fixes #11019 --- commands/hugobuilder.go | 4 ++++ testscripts/commands/hugo__configdir.txt | 6 ++++++ testscripts/commands/hugo__flags.txt | 2 ++ testscripts/commands/hugo__noconfig.txt | 4 ++++ 4 files changed, 16 insertions(+) create mode 100644 testscripts/commands/hugo__configdir.txt create mode 100644 testscripts/commands/hugo__noconfig.txt diff --git a/commands/hugobuilder.go b/commands/hugobuilder.go index fa194e000..95dbb1ca8 100644 --- a/commands/hugobuilder.go +++ b/commands/hugobuilder.go @@ -1019,6 +1019,10 @@ func (c *hugoBuilder) loadConfig(cd *simplecobra.Commandeer, running bool) error return err } + if len(conf.configs.LoadingInfo.ConfigFiles) == 0 { + return errors.New("Unable to locate config file or config directory. Perhaps you need to create a new site.\nRun `hugo help new` for details.") + } + c.conf = conf if c.onConfigLoaded != nil { if err := c.onConfigLoaded(false); err != nil { diff --git a/testscripts/commands/hugo__configdir.txt b/testscripts/commands/hugo__configdir.txt new file mode 100644 index 000000000..4da62ade5 --- /dev/null +++ b/testscripts/commands/hugo__configdir.txt @@ -0,0 +1,6 @@ + +hugo +! stderr . + +-- config/_default/hugo.toml -- +baseURL = "https://example.com/" \ No newline at end of file diff --git a/testscripts/commands/hugo__flags.txt b/testscripts/commands/hugo__flags.txt index c2ea92c95..ad4591322 100644 --- a/testscripts/commands/hugo__flags.txt +++ b/testscripts/commands/hugo__flags.txt @@ -11,6 +11,8 @@ grep 'Home' newpublic/index.html hugo --quiet ! stdout . +-- hugo.toml -- +title = "Hugo Test" -- myconfig.toml -- baseURL = "http://example.org/" disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"] diff --git a/testscripts/commands/hugo__noconfig.txt b/testscripts/commands/hugo__noconfig.txt new file mode 100644 index 000000000..c3a6f6588 --- /dev/null +++ b/testscripts/commands/hugo__noconfig.txt @@ -0,0 +1,4 @@ + +! hugo + +stderr 'Unable to locate config file or config directory' \ No newline at end of file