Skip to content

Commit 353ed05

Browse files
justin808claude
andcommitted
Fix RuboCop BlockNesting violation in install-hooks
Refactor git directory detection loop to use early next/break instead of deeply nested conditionals, reducing nesting from 4 levels to 3. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c6a126a commit 353ed05

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

bin/install-hooks

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ current = File.expand_path('..', __dir__)
99

1010
while current != '/'
1111
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
12+
unless File.exist?(git_path)
13+
current = File.dirname(current)
14+
next
2515
end
26-
current = File.dirname(current)
16+
17+
unless File.file?(git_path)
18+
git_dir = git_path
19+
break
20+
end
21+
22+
# It's a worktree, read the actual git dir
23+
git_dir_line = File.read(git_path).lines.find { |l| l.start_with?('gitdir:') }
24+
if git_dir_line
25+
relative_path = git_dir_line.sub('gitdir:', '').strip
26+
git_dir = File.expand_path(relative_path, current)
27+
end
28+
break
2729
end
2830

2931
unless git_dir && File.exist?(git_dir)

0 commit comments

Comments
 (0)