Skip to content

Commit ca72bba

Browse files
committed
Fix install-hooks script for git worktree compatibility
- Add support for git worktrees (Conductor environments) - Properly detect git directory location - Handle both regular repos and worktrees - Install pre-commit hooks successfully
1 parent 2306795 commit ca72bba

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

bin/install-hooks

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,35 @@
33

44
require 'fileutils'
55

6-
# Check if we're in a git repository
7-
unless File.exist?(File.expand_path('../.git', __dir__))
6+
# Find the git directory (could be .git file in worktree or .git directory)
7+
git_dir = nil
8+
current = File.expand_path('..', __dir__)
9+
10+
while current != '/'
11+
git_path = File.join(current, '.git')
12+
if File.exist?(git_path)
13+
if File.file?(git_path)
14+
# It's a worktree, read the actual git dir
15+
git_dir_line = File.read(git_path).lines.find { |l| l.start_with?('gitdir:') }
16+
if git_dir_line
17+
relative_path = git_dir_line.sub('gitdir:', '').strip
18+
git_dir = File.expand_path(relative_path, current)
19+
break
20+
end
21+
else
22+
git_dir = git_path
23+
break
24+
end
25+
end
26+
current = File.dirname(current)
27+
end
28+
29+
unless git_dir && File.exist?(git_dir)
830
puts '❌ Error: Not in a git repository. Please run this from the project root.'
931
exit 1
1032
end
1133

12-
hooks_dir = File.expand_path('../.git/hooks', __dir__)
34+
hooks_dir = File.join(git_dir, 'hooks')
1335
pre_commit_hook = File.join(hooks_dir, 'pre-commit')
1436

1537
# Create pre-commit hook content

0 commit comments

Comments
 (0)