Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path for searching npm-installed binary when in worktree #193

Merged
merged 2 commits into from
May 18, 2021

Conversation

Envek
Copy link
Member

@Envek Envek commented May 17, 2021

Fixes #192

The problem arises when:

  1. using worktrees
  2. lefthook is installed via NPM and isn't available in $PATH
  3. lefthook version in main worktree's package.json is different from version in the current worktree

Then previously used code always return path to main worktree and founds old Lefthook binary there.

Current code will return path to the root of currently used worktree.

In most cases plain pwd -P would be enough but docs for git hooks states that:

Before Git invokes a hook, it changes its working directory to either $GIT_DIR in a bare repository or the root of the working tree in a non-bare repository. An exception are hooks triggered during a push (pre-receive, update, post-receive, post-update, push-to-checkout) which are always executed in $GIT_DIR.

While Lefthook is always used in non-bare repositories, there is still chance that someone would like to use mentioned hooks that triggered during push, so use git rev-parse --show-toplevel helper command instead. Just in case.

Relevant docs:

@Envek Envek merged commit 12ad491 into master May 18, 2021
@Envek Envek deleted the fix/worktree-npm-binary-search branch May 18, 2021 08:25
Envek added a commit that referenced this pull request Jun 2, 2021
* 0-7-stable:
  0.7.6: Fixes for Windows, NPM on 32bit Node, and NPM in worktrees
  Remove rpm from recommendations for DEB and RPM packages
  npm: Use correct arch identifier for 32-bit Intel-based processors
  Fix lefthook binary extension on Windows
  Fix path for searching npm-installed binary when in worktree (#193)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different versions cross git worktree
2 participants