diff --git a/src/__tests__/__fixtures__/workdirs/.gitignore b/src/__tests__/__fixtures__/workdirs/.gitignore new file mode 100644 index 000000000..a38050893 --- /dev/null +++ b/src/__tests__/__fixtures__/workdirs/.gitignore @@ -0,0 +1,2 @@ +workdirs +repo diff --git a/src/__tests__/__fixtures__/workdirs/cleanup.sh b/src/__tests__/__fixtures__/workdirs/cleanup.sh new file mode 100755 index 000000000..337bfbc44 --- /dev/null +++ b/src/__tests__/__fixtures__/workdirs/cleanup.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +set -e +set -x + +rm -rf repo workdirs diff --git a/src/__tests__/__fixtures__/workdirs/package.json b/src/__tests__/__fixtures__/workdirs/package.json new file mode 100644 index 000000000..9fd36b680 --- /dev/null +++ b/src/__tests__/__fixtures__/workdirs/package.json @@ -0,0 +1,20 @@ +{ + "name": "husky-workdir-repro", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "husky": "^3.0.8" + }, + "husky": { + "hooks": { + "pre-commit": "node -p 'require(\"husky/package.json\").version'" + } + } +} diff --git a/src/__tests__/__fixtures__/workdirs/run.sh b/src/__tests__/__fixtures__/workdirs/run.sh new file mode 100755 index 000000000..f0c75335e --- /dev/null +++ b/src/__tests__/__fixtures__/workdirs/run.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +set -e +set -x + +mkdir -p repos/repo +cd repos/repo +git init +git config user.name 'Test User' +git config user.email 'test@example.org' +cp ../package.json . +npm i +git add package.json +[ -f package-lock.json ] && git add package-lock.json +git commit -m 'init' + +mkdir -p ../workdirs +git worktree add ../workdirs/workdir +# Preparing worktree (new branch 'workdir') +# HEAD is now at 6b8dab8 init +# Can't find Husky, skipping post-checkout hook +# You can reinstall it using 'npm install husky --save-dev' or delete this hook +cd ../workdirs/workdir +npm i +cd - # back to "repo" folder +echo 'node_modules' >> .gitignore +git add .gitignore + +# I expected this to error on the hook, but it didn't +git commit -m 'add gitignore'