lib/gitlab_git/attributes.rb in gitlab_git-10.6.1 vs lib/gitlab_git/attributes.rb in gitlab_git-10.6.2
- old
+ new
@@ -16,22 +16,24 @@
#
# attributes.attributes('README.md') # => { "eol" => "lf }
class Attributes
# path - The path to the Git repository.
def initialize(path)
- @path = path
+ @path = File.expand_path(path)
@patterns = nil
end
# Returns all the Git attributes for the given path.
#
# path - A path to a file for which to get the attributes.
#
# Returns a Hash.
def attributes(path)
+ full_path = File.join(@path, path)
+
patterns.each do |pattern, attrs|
- return attrs if File.fnmatch(pattern, path)
+ return attrs if File.fnmatch?(pattern, full_path)
end
{}
end
@@ -105,10 +107,10 @@
each_line do |line|
next if line.start_with?(comment) || line.empty?
pattern, attrs = line.split(/\s+/, 2)
- pairs << [pattern, parse_attributes(attrs)]
+ pairs << [File.join(@path, pattern), parse_attributes(attrs)]
end
# Newer entries take precedence over older entries.
pairs.reverse.to_h
end