Skip to content

Commit

Permalink
Use File.expand_path to expand tildes to users home folder
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Aug 10, 2024
1 parent 5ff9d5e commit 4b69cdc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/overcommit/git_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def comment_character
def hooks_path
path = `git config --get core.hooksPath`.chomp
return File.join(Overcommit::Utils.git_dir, 'hooks') if path.empty?

File.absolute_path(path, Dir.pwd)
q
File.absolute_path(File.expand_path(path), Dir.pwd)
end
end
end
13 changes: 13 additions & 0 deletions spec/overcommit/git_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,18 @@
expect(subject).to eq File.expand_path('my-hooks')
end
end

context 'when explicitly set to a path starting with a tilde' do
around do |example|
repo do
`git config --local core.hooksPath ~/my-hooks`
example.run
end
end

it 'returns the absolute path to the folder in the users home path' do
expect(subject).to eq File.expand_path('~/my-hooks')
end
end
end
end

0 comments on commit 4b69cdc

Please sign in to comment.