Skip to content

Commit a8c72e1

Browse files
committed
Load YAML configuration file with aliases: true
Gracefully handle breaking behavior in upstream Psych gem to support YAML aliases.
1 parent f7b52fa commit a8c72e1

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Overcommit Changelog
22

3+
## master (unreleased)
4+
5+
* Gracefully handle breaking behavior in upstream Psych gem to support YAML aliases.
6+
37
## 0.57.0
48

59
* Fix `CommitMsg` hooks to be able to call `modified_lines_in_file`.

lib/overcommit/configuration_loader.rb

+8-5
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ def default_configuration
2424
# @option logger [Overcommit::Logger]
2525
# @return [Overcommit::Configuration]
2626
def load_from_file(file, options = {})
27-
hash =
28-
if yaml = YAML.load_file(file)
29-
yaml.to_hash
30-
else
31-
{}
27+
# Psych 4 introduced breaking behavior that doesn't support aliases by
28+
# default. Explicitly enable aliases if the option is available.
29+
yaml =
30+
begin
31+
YAML.load_file(file, aliases: true)
32+
rescue ArgumentError
33+
YAML.load_file(file)
3234
end
3335

36+
hash = yaml ? yaml.to_hash : {}
3437
Overcommit::Configuration.new(hash, options)
3538
end
3639
end

0 commit comments

Comments
 (0)