Skip to content

Commit 31c83ce

Browse files
anakinjsds
andauthored
Expand tildes(~) for hooksPath (sds#853)
While installing overcommit git hooks i noticed that tildes are not expanded to home folders for the `hooksPath` config, the result was a tilde folder in the current directory. This PR addresses that by switching `File.absolute_path` to `File.expand_path`. The [underlaying implementation](https://github.com/ruby/ruby/blob/v3_3_4/file.c#L3753) in Ruby is exactly the same just with this difference in how `~` is handled. --------- Co-authored-by: Shane da Silva <shane@dasilva.io>
1 parent 5a3d68e commit 31c83ce

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/overcommit/git_config.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def hooks_path
1717
path = `git config --get core.hooksPath`.chomp
1818
return File.join(Overcommit::Utils.git_dir, 'hooks') if path.empty?
1919

20-
File.absolute_path(path, Dir.pwd)
20+
File.expand_path(path, Dir.pwd)
2121
end
2222
end
2323
end

spec/overcommit/git_config_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,19 @@
7878
expect(subject).to eq File.expand_path('my-hooks')
7979
end
8080
end
81+
82+
context 'when explicitly set to a path starting with a tilde' do
83+
around do |example|
84+
repo do
85+
`git config --local core.hooksPath ~/my-hooks`
86+
example.run
87+
end
88+
end
89+
90+
it 'returns the absolute path to the folder in the users home path' do
91+
expect(subject).to eq File.expand_path('~/my-hooks')
92+
expect(subject).not_to include('~')
93+
end
94+
end
8195
end
8296
end

0 commit comments

Comments
 (0)