Skip to content

Commit c923b6f

Browse files
committed
fixup! Get submodules working
1 parent 29c0719 commit c923b6f

16 files changed

+422
-277
lines changed

lib/path_list.rb

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,39 +40,57 @@ def initialize
4040
end
4141

4242
def gitignore(root: nil, config: true)
43-
new_and_matcher(Gitignore.build(root: root, config: config))
43+
new_with_matcher(Matcher::All.build([
44+
@matcher,
45+
Gitignore.build(root: root, config: config),
46+
Gitignore.ignore_dot_git_matcher
47+
]))
4448
end
4549

4650
def ignore(*patterns, patterns_from_file: nil, format: :gitignore, root: nil)
47-
new_and_matcher(
51+
new_with_matcher(Matcher::All.build([
52+
@matcher,
4853
PatternParser.build(
49-
patterns: patterns, patterns_from_file: patterns_from_file, format: format, root: root, polarity: :ignore
54+
patterns: patterns,
55+
patterns_from_file: patterns_from_file,
56+
format: format,
57+
root: root,
58+
polarity: :ignore
5059
)
51-
)
60+
]))
5261
end
5362

5463
def only(*patterns, patterns_from_file: nil, format: :gitignore, root: nil)
55-
new_and_matcher(
64+
new_with_matcher(Matcher::All.build([
65+
@matcher,
5666
PatternParser.build(
57-
patterns: patterns, patterns_from_file: patterns_from_file, format: format, root: root, polarity: :allow
67+
patterns: patterns,
68+
patterns_from_file: patterns_from_file,
69+
format: format,
70+
root: root,
71+
polarity: :allow
5872
)
59-
)
73+
]))
6074
end
6175

6276
def union(path_list, *path_lists)
63-
new_with_matcher(
64-
Matcher::Any.build([@matcher, path_list.matcher, *path_lists.map { |l| l.matcher }]) # rubocop:disable Style/SymbolProc
65-
)
77+
new_with_matcher(Matcher::Any.build([
78+
@matcher,
79+
path_list.matcher,
80+
*path_lists.map { |l| l.matcher } # rubocop:disable Style/SymbolProc
81+
]))
6682
end
6783

6884
def |(other)
6985
union(other)
7086
end
7187

7288
def intersection(path_list, *path_lists)
73-
new_with_matcher(
74-
Matcher::All.build([@matcher, path_list.matcher, path_lists.map { |l| l.matcher }]) # rubocop:disable Style/SymbolProc
75-
)
89+
new_with_matcher(Matcher::All.build([
90+
@matcher,
91+
path_list.matcher,
92+
path_lists.map { |l| l.matcher } # rubocop:disable Style/SymbolProc
93+
]))
7694
end
7795

7896
def &(other)
@@ -156,10 +174,6 @@ def new_with_matcher(matcher)
156174
path_list
157175
end
158176

159-
def new_and_matcher(matcher)
160-
new_with_matcher(Matcher::All.build([@matcher, matcher]))
161-
end
162-
163177
def dir_matcher
164178
@dir_matcher ||= @matcher.dir_matcher
165179
end

lib/path_list/candidate.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def child_candidates
5050
def children
5151
@children ||= begin
5252
::Dir.children(@full_path)
53-
rescue ::SystemCallError
53+
rescue ::IOError, ::SystemCallError
5454
[]
5555
end
5656
end
@@ -118,7 +118,7 @@ def ftype
118118
else
119119
::File.ftype(@full_path)
120120
end
121-
rescue ::SystemCallError
121+
rescue ::IOError, ::SystemCallError
122122
@ftype = 'error'
123123
end
124124
# :nocov:
@@ -128,7 +128,7 @@ def ftype
128128
return @ftype if @ftype
129129

130130
@ftype = ::File.ftype(@full_path)
131-
rescue ::SystemCallError
131+
rescue ::IOError, ::SystemCallError
132132
@ftype = 'error'
133133
end
134134
end

lib/path_list/gitconfig/core_excludesfile.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ module Gitconfig
66
# Find the configured git core.excludesFile
77
module CoreExcludesfile
88
class << self
9-
# @param repo_root [String]
9+
# @param git_dir [String]
1010
# @return [String, nil]
11-
def path(repo_root:)
12-
ignore_path = gitconfigs_core_excludesfile_path(repo_root) ||
11+
def path(git_dir:)
12+
ignore_path = gitconfigs_core_excludesfile_path(git_dir) ||
1313
default_core_excludesfile_path
1414

1515
ignore_path unless ignore_path.empty?
1616
end
1717

1818
private
1919

20-
def gitconfigs_core_excludesfile_path(repo_root)
21-
gitconfig_core_excludesfile_path(repo_config_path(repo_root)) ||
22-
gitconfig_core_excludesfile_path(global_config_path) ||
23-
gitconfig_core_excludesfile_path(default_user_config_path) ||
24-
gitconfig_core_excludesfile_path(system_config_path)
20+
def gitconfigs_core_excludesfile_path(git_dir)
21+
gitconfig_core_excludesfile_path(repo_config_path(git_dir), git_dir) ||
22+
gitconfig_core_excludesfile_path(global_config_path, git_dir) ||
23+
gitconfig_core_excludesfile_path(default_user_config_path, git_dir) ||
24+
gitconfig_core_excludesfile_path(system_config_path, git_dir)
2525
rescue ParseError => e
2626
::Warning.warn("PathList gitconfig parser failed\n" + e.message)
2727

2828
''
2929
end
3030

31-
def gitconfig_core_excludesfile_path(config_path)
31+
def gitconfig_core_excludesfile_path(config_path, git_dir)
3232
return unless config_path
3333
return unless ::File.readable?(config_path)
3434

35-
ignore_path = FileParser.parse(config_path).excludesfile
35+
ignore_path = FileParser.parse(config_path, git_dir: git_dir).excludesfile
3636
return unless ignore_path
3737

3838
ignore_path.strip!
@@ -51,8 +51,8 @@ def default_core_excludesfile_path
5151
CanonicalPath.full_path_from('git/ignore', default_config_home)
5252
end
5353

54-
def repo_config_path(root)
55-
CanonicalPath.full_path_from('.git/config', root)
54+
def repo_config_path(git_dir)
55+
CanonicalPath.full_path_from('config', git_dir) if git_dir
5656
end
5757

5858
def global_config_path

lib/path_list/gitconfig/file_parser.rb

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@ module Gitconfig
88
# Parse git config file for the core.excludesFile
99
class FileParser
1010
# @param file [String]
11-
# @param root [String]
11+
# @param git_dir [String]
1212
# @param nesting [Integer]
1313
# @return [String]
1414
# @raise [ParseError]
15-
def self.parse(file, root: Dir.pwd, nesting: 1, find: :'core.excludesFile')
16-
new(file, root: root, nesting: nesting, find: find).parse
15+
def self.parse(file, git_dir: nil, nesting: 1)
16+
new(file, git_dir: git_dir, nesting: nesting).parse
1717
end
1818

1919
# @param file [String]
20-
# @param root [String]
20+
# @param git_dir [String]
2121
# @param nesting [Integer]
22-
def initialize(path, root: Dir.pwd, nesting: 1, find: :'core.excludesFile')
22+
def initialize(path, git_dir: nil, nesting: 1)
2323
@path = path
24-
@root = root
24+
@git_dir = git_dir
2525
@nesting = nesting
26-
@find = find
2726
end
2827

2928
# @return [String]
@@ -42,7 +41,7 @@ def parse
4241

4342
attr_reader :nesting
4443
attr_reader :path
45-
attr_reader :root
44+
attr_reader :git_dir
4645
attr_accessor :within_quotes
4746
attr_accessor :section
4847

@@ -75,7 +74,7 @@ def read_file(path)
7574

7675
result = self.class.parse(
7776
CanonicalPath.full_path_from(include_path, ::File.dirname(path)),
78-
root: root,
77+
git_dir: git_dir,
7978
nesting: nesting + 1
8079
)
8180
self.excludesfile = result.excludesfile if result.excludesfile
@@ -125,22 +124,24 @@ def include_if(file)
125124

126125
def on_branch?(branch_pattern)
127126
branch_pattern += '**' if branch_pattern.end_with?('/')
128-
current_branch = ::File.readable?("#{root}/.git/HEAD") &&
129-
::File.read("#{root}/.git/HEAD").delete_prefix('ref: refs/heads/')
127+
current_branch = ::File.readable?("#{git_dir}/HEAD") &&
128+
::File.read("#{git_dir}/HEAD").delete_prefix('ref: refs/heads/')
130129
return false unless current_branch
131130

132131
# goddamit git what does 'a pattern with standard globbing wildcards' mean
133132
::File.fnmatch(branch_pattern, current_branch, ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH)
134133
end
135134

136-
def gitdir?(gitdir, path:, case_insensitive: false)
137-
gitdir += '**' if gitdir.end_with?('/')
138-
gitdir.sub!(%r{\A~/}, Dir.home + '/')
139-
gitdir.sub!(/\A\./, path + '/')
140-
gitdir = "**/#{gitdir}" unless gitdir.start_with?('/')
135+
def gitdir?(gitdir_value, path:, case_insensitive: false)
136+
return unless git_dir
137+
138+
gitdir_value += '**' if gitdir_value.end_with?('/')
139+
gitdir_value.sub!(%r{\A~/}, Dir.home + '/')
140+
gitdir_value.sub!(/\A\./, path + '/')
141+
gitdir_value = "**/#{gitdir_value}" unless gitdir_value.start_with?('/')
141142
options = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH
142143
options |= ::File::FNM_CASEFOLD if case_insensitive
143-
::File.fnmatch(gitdir, ::File.join(root, '.git'), options)
144+
::File.fnmatch(gitdir_value, git_dir, options)
144145
end
145146

146147
def scan_value(file)

0 commit comments

Comments
 (0)