@automattic/jetpack-cli 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/jp.js +15 -3
  2. package/package.json +1 -1
package/bin/jp.js CHANGED
@@ -150,10 +150,22 @@ const huskyHookExists = ( monorepoRoot, hookName ) => {
150
150
  * @throws {Error} If hook installation fails
151
151
  */
152
152
  const initHooks = monorepoRoot => {
153
- const hooksDir = resolve( monorepoRoot, '.git/hooks' );
153
+ // Use git rev-parse --git-common-dir to find the hooks directory.
154
+ // In a regular repo this returns ".git"; in a worktree it returns the
155
+ // main repo's .git path. Hooks are shared across all worktrees.
156
+ const gitCommonDirResult = spawnSync( 'git', [ 'rev-parse', '--git-common-dir' ], {
157
+ cwd: monorepoRoot,
158
+ encoding: 'utf8',
159
+ } );
160
+
161
+ if ( gitCommonDirResult.status !== 0 || ! gitCommonDirResult.stdout.trim() ) {
162
+ throw new Error( 'Could not determine git directory. Is this a git repository?' );
163
+ }
164
+
165
+ const hooksDir = resolve( monorepoRoot, gitCommonDirResult.stdout.trim(), 'hooks' );
154
166
 
155
167
  if ( ! fs.existsSync( hooksDir ) ) {
156
- throw new Error( 'Git hooks directory not found. Is this a git repository?' );
168
+ fs.mkdirSync( hooksDir, { recursive: true } );
157
169
  }
158
170
 
159
171
  console.log( chalk.blue( 'Setting up jp git hooks...' ) );
@@ -167,7 +179,7 @@ const initHooks = monorepoRoot => {
167
179
  if ( hooksPathResult.stdout && hooksPathResult.stdout.trim() ) {
168
180
  const currentHooksPath = hooksPathResult.stdout.trim();
169
181
  console.log( chalk.yellow( ` Detected custom git hooks path: ${ currentHooksPath }` ) );
170
- console.log( chalk.yellow( ' Resetting to use .git/hooks/ for jp hooks' ) );
182
+ console.log( chalk.yellow( ` Resetting to use ${ hooksDir } for jp hooks` ) );
171
183
 
172
184
  const unsetResult = spawnSync( 'git', [ 'config', '--unset', 'core.hooksPath' ], {
173
185
  cwd: monorepoRoot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/jetpack-cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Docker-based CLI for Jetpack development",
5
5
  "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/jetpack-cli/#readme",
6
6
  "bugs": {