Skip to content

Commit

Permalink
commands: Fail the build when no config file or config dir
Browse files Browse the repository at this point in the history
Fixes #11019
  • Loading branch information
bep committed May 27, 2023
1 parent a6257d8 commit 273d9f6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions commands/hugobuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions testscripts/commands/hugo__configdir.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

hugo
! stderr .

-- config/_default/hugo.toml --
baseURL = "https://example.com/"
2 changes: 2 additions & 0 deletions testscripts/commands/hugo__flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ grep '<body>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"]
Expand Down
4 changes: 4 additions & 0 deletions testscripts/commands/hugo__noconfig.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

! hugo

stderr 'Unable to locate config file or config directory'

0 comments on commit 273d9f6

Please sign in to comment.