File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change 33
44require '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
1032end
1133
12- hooks_dir = File . expand_path ( '../.git/ hooks', __dir__ )
34+ hooks_dir = File . join ( git_dir , ' hooks')
1335pre_commit_hook = File . join ( hooks_dir , 'pre-commit' )
1436
1537# Create pre-commit hook content
You can’t perform that action at this time.
0 commit comments