Skip to content

Commit

Permalink
Correct work with worktrees (#114)
Browse files Browse the repository at this point in the history
Worktree's `.git` file contains absolute path to repository.
`path.join` incorrectly concatenates `/path/to/worktree`
with `/path/to/real/.git/worktrees/worktree` to
`/path/to/worktree/path/to/real/.git/worktrees/worktree`
instead of simple `/path/to/real/...`

Using `path.resolve` instead of `path.join` resolves this problem
while relative paths of submodules still works correctly.
  • Loading branch information
alexeyten authored and typicode committed Jun 13, 2017
1 parent 4378d18 commit 333ca98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function findHooksDir (dirname) {
.split(':')[1]
.trim()

return path.join(dir, gitDir, 'hooks')
return path.resolve(dir, gitDir, 'hooks')
}

return path.join(gitDir, 'hooks')
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ describe('husky', function () {
expect(exists('hooks/pre-push')).toBeFalsy()
})

it('should support git worktrees', function () {
mock({
'/.git/worktrees/B': {},
'/A/B/.git': 'git: /.git/worktrees/B',
'/A/B/node_modules/husky': {}
})

husky.installFrom('/A/B/node_modules/husky')
var hook = readHook('worktrees/B/hooks/pre-commit')

expect(hook).toInclude('cd .')

husky.uninstallFrom('/A/B/node_modules/husky')
expect(exists('hooks/pre-commit')).toBeFalsy()
})

it('should not modify user hooks', function () {
mock({
'/.git/hooks': {},
Expand Down

0 comments on commit 333ca98

Please sign in to comment.