Skip to content

Commit 13dd0c0

Browse files
committed
Fix GitRepo.list_files on Windows platforms
We broke the implementation for Windows platforms in 7e8e6f2 since the `Shellwords` module is specific to the Bourne shell. Adjust the implementation to work on Windows.
1 parent e982b0b commit 13dd0c0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/overcommit/git_repo.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,14 @@ def modified_files(options)
109109
# @return [Array<String>] list of absolute file paths
110110
def list_files(paths = [], options = {})
111111
ref = options[:ref] || 'HEAD'
112-
`git ls-tree --name-only #{ref} #{paths.shelljoin}`.
112+
path_list =
113+
if OS.windows?
114+
paths = paths.map { |path| path.gsub('"', '""') }
115+
paths.empty? ? '' : "\"#{paths.join('" "')}\""
116+
else
117+
paths.shelljoin
118+
end
119+
`git ls-tree --name-only #{ref} #{path_list}`.
113120
split(/\n/).
114121
map { |relative_file| File.expand_path(relative_file) }.
115122
reject { |file| File.directory?(file) } # Exclude submodule directories

0 commit comments

Comments
 (0)