From 4b69cdcd543c06a25eb9567b11241c045becf5b5 Mon Sep 17 00:00:00 2001 From: Joakim Antman Date: Sat, 10 Aug 2024 16:19:16 +0300 Subject: [PATCH] Use File.expand_path to expand tildes to users home folder --- lib/overcommit/git_config.rb | 4 ++-- spec/overcommit/git_config_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/overcommit/git_config.rb b/lib/overcommit/git_config.rb index 392dd9da..91b4e8e0 100644 --- a/lib/overcommit/git_config.rb +++ b/lib/overcommit/git_config.rb @@ -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 diff --git a/spec/overcommit/git_config_spec.rb b/spec/overcommit/git_config_spec.rb index 22ad7c02..4ff2951b 100644 --- a/spec/overcommit/git_config_spec.rb +++ b/spec/overcommit/git_config_spec.rb @@ -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