"Arguments to path.resolve must be strings" when calling 'gitbook build' from a Git hook

1k views Asked by At

I am trying to run gitbook build within a post-receive Git hook on my (Gitlab, Debian 7, virtual private) server.

Basically I want to:

  • checkout the bare repository to a temporary dir
  • run gitbook build in that temporary dir
  • sync with the webspace through rsync

The post-receive script runs something like:

git --work-tree=/home/git/temp-checkout /
--git-dir=/home/git/repositories/my/repo.git checkout -f

gitbook build /home/git/temp-checkout

rsync ...

Running these commands from the server's command line works perfectly.
Running the script from the server's command line works well too.
But when the script is invoked from the Git hook the gitbook call produces the following error:

remote: path.js:439
remote:       throw new TypeError('Arguments to path.resolve must be strings');
remote:             ^
remote: TypeError: Arguments to path.resolve must be strings
remote:     at Object.posix.resolve (path.js:439:13)
remote:     at Object.<anonymous> (/usr/lib/node_modules/gitbook-cli/lib/config.js:5:24)
remote:     at Module._compile (module.js:460:26)
remote:     at Object.Module._extensions..js (module.js:478:10)
remote:     at Module.load (module.js:355:32)
remote:     at Function.Module._load (module.js:310:12)
remote:     at Module.require (module.js:365:17)
remote:     at require (module.js:384:17)
remote:     at Object.<anonymous> (/usr/lib/node_modules/gitbook-cli/bin/gitbook.js:11:14)
remote:     at Module._compile (module.js:460:26)

Searching for that error message seems to point to Grunt, but I just have no idea what is happening here. I suspected something about invocation/permissions, but neither the user (in both cases whoami returns the git user) nor the working directory seem to make a difference.

But in any case gitbook behaves differently when invoked "locally" (i.e. from the server's command line) or from the Git hook.

1

There are 1 answers

0
uli_1973 On BEST ANSWER

Some further consideration brought me to the right direction: Invoking a Git hook has a different login context than working on the server's command line. So running set > some-file in both contexts revealed significant differences in environment variables.

Some experiments turned out that it was

export HOME=/home/git

that had to be included in the script. So obviously gitbook choked on not having the environment variable set.