Skip to content

Commit ac5bab8

Browse files
committed
Use IO.popen to list files
- Redirect `git ls-files` without shelling out. - When building by `gem`, `__FILE__` is the path name given in the command line, or the gemspec file name in the current directory. In that case, comparison it and expanded path never equal. Compare listed file names with the base name of `__FILE__` instead.
1 parent 4705278 commit ac5bab8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tempfile.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ Gem::Specification.new do |spec|
2222

2323
# Specify which files should be added to the gem when it is released.
2424
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25-
spec.files = Dir.chdir(__dir__) do
26-
`git ls-files -z 2>#{IO::NULL}`.split("\x0").reject do |f|
27-
(File.expand_path(f) == __FILE__) ||
25+
gemspec = File.basename(__FILE__)
26+
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
27+
ls.readlines("\x0", chomp: true).reject do |f|
28+
(f == gemspec) ||
2829
f.start_with?(*%w[bin/ test/ spec/ features/ .git Gemfile])
2930
end
3031
end

0 commit comments

Comments
 (0)