Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Ensure git is executed inside the gemspec dir #6191

Merged
merged 1 commit into from
Nov 30, 2017

Conversation

elia
Copy link
Contributor

@elia elia commented Nov 28, 2017

What was the end-user problem that led to this PR?

Executables from bundled gems weren't available.

Gem::Exception: can't find executable <EXEC-FILENAME> for gem <GEM-NAME>
  /Users/elia/.rvm/rubies/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/bundler/rubygems_integration.rb:458:in `block in replace_bin_path'
  /Users/elia/.rvm/rubies/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/bundler/rubygems_integration.rb:478:in `block in replace_bin_path'
…

What was your diagnosis of the problem?

When a Gemfile was pointing to a local gem using git to list its files the git command
was executed from within the wrong dir.

What is your fix for the problem, implemented in this PR?

Initially I added -C #{__dir__} to the git ls-files -z command.

Why did you choose this fix out of the possible options?

Realized -C wasn't safe and opted for stuff already available in the corelib, i.e. Dir.chrid instead of, say, escaping with shellwords.


I know the line is long-ish, happy to fix it in the way you want

@ghost
Copy link

ghost commented Nov 28, 2017

Thanks for opening a pull request and helping make Bundler better! Someone from the Bundler team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality.

We use Travis CI to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of Travis CI in the PR status window below.

If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #bundler channel on Slack.

For more information about contributing to the Bundler project feel free to review our CONTRIBUTING guide

@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
"public gem pushes."
end

spec.files = `git ls-files -z`.split("\x0").reject do |f|
spec.files = Dir.chdir(__dir__){`git ls-files -z`}.split("\x0").reject do |f|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use File.expand_path("..", __FILE__) for compatibility, and maybe add some spacing to conform with the style in the rest of the codebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅, also moved the whole line inside the chdir block to make it more readable

When a Gemfile was pointing to a local gem using git to list its files the git command
was executed from within the wrong dir. This fixes the issue without:

1. introducing new dependencies (e.g. `shellwords`)
2. any risks with non-trivial paths (e.g. paths containing spaces)
@colby-swandale
Copy link
Member

@bundlerbot r+

@bundlerbot
Copy link
Collaborator

📌 Commit 107772e has been approved by colby-swandale

@bundlerbot
Copy link
Collaborator

⌛ Testing commit 107772e with merge 5e49f42...

bundlerbot added a commit that referenced this pull request Nov 30, 2017
Ensure git is executed inside the gemspec dir

### What was the end-user problem that led to this PR?

Executables from bundled gems weren't available.

```
Gem::Exception: can't find executable <EXEC-FILENAME> for gem <GEM-NAME>
  /Users/elia/.rvm/rubies/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/bundler/rubygems_integration.rb:458:in `block in replace_bin_path'
  /Users/elia/.rvm/rubies/ruby-2.3.4/lib/ruby/site_ruby/2.3.0/bundler/rubygems_integration.rb:478:in `block in replace_bin_path'
…
```

### What was your diagnosis of the problem?

When a Gemfile was pointing to a local gem using git to list its files the git command
was executed from within the wrong dir.

### What is your fix for the problem, implemented in this PR?

Initially I added `-C #{__dir__}` to the `git ls-files -z` command.

### Why did you choose this fix out of the possible options?

Realized `-C` wasn't safe and opted for stuff already available in the corelib, i.e. `Dir.chrid` instead of, say, escaping with `shellwords`.

---

I know the line is long-ish, happy to fix it in the way you want
@bundlerbot
Copy link
Collaborator

☀️ Test successful - status-travis
Approved by: colby-swandale
Pushing 5e49f42 to master...

@bundlerbot bundlerbot merged commit 107772e into rubygems:master Nov 30, 2017
@colby-swandale colby-swandale added this to the 1.17.1 milestone Sep 24, 2018
@colby-swandale colby-swandale removed this from the 1.16.6 milestone Oct 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants