-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --gemfile
flag to bundle init
to configure gemfile name to generate
#6046
Add --gemfile
flag to bundle init
to configure gemfile name to generate
#6046
Conversation
Thank you @gustavothecoder! Any opinions on what the behavior should be if the |
You mean when the user sets the |
Any opinions on what the behavior should be if the BUNDLE_GEMFILE set already exists? Should we keep the current behavior with a warning in that case? @dentarg what do you think?
I think we should exit with error saying the file already exists, like we do today
|
Some environments have a fixed I'm afraid this may break That's why I was suggesting a warning if |
So |
Yes, in these simple examples feeding |
68cb7b0
to
21115ad
Compare
Just to confirm if I understand correctly. When |
@gustavothecoder Yes, that's my suggestion. |
@deivid-rodriguez I think it's working fine now: demo.mp4 |
Looks good! I was also thinking that warnings should be actionable, so we should clearly explain to users how to fix the warning. The solution would be to pass Or maybe this is all a bit overkill and I'm overthinking this. I'd like to hear opinions from other maintainers. |
That makes sense to me. I have actually looked for it, and I almost thought I found it 😆 but then I noticed that it said |
That makes sense for me too, but, are we going to support both @deivid-rodriguez what do you think of this message?: "Bundler will name the gemfile "Gemfile" because foo already exists at /some/dir/foo. To silence this warning, run |
@gustavothecoder Sorry for the lack of feedback. Based on the discussion, I think the easiest approach here may be to add a |
51f820c
to
32a046f
Compare
That make sense. I'll change the fix. |
1470d3b
to
4907bc2
Compare
@deivid-rodriguez do you think we can improve the implementation? |
Sorry for the lack of feedback here @gustavothecoder, I'll try to review this soon. |
4907bc2
to
f06fcfe
Compare
0948852
to
0785efe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly ready, just one more comment.
Thanks for your infinite patience here, I think it was this long discussion because this approach finally seems the simplest way to go to me!
bundle init
should respect BUNDLE_GEMFILE
--gemfile
flag to bundle init
to configure gemfile name to generate
0785efe
to
d09a1db
Compare
bundler/lib/bundler/cli/init.rb
Outdated
@@ -32,7 +32,7 @@ def run | |||
file << spec.to_gemfile | |||
end | |||
else | |||
File.open(File.expand_path("../templates/#{gemfile}", __dir__), "r") do |template| | |||
File.open(File.expand_path(template_path, __dir__), "r") do |template| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently have two gemfile templates: gems.rb
and Gemfile
, but they have the same content. I think we can use ../templates/Gemfile
unconditionally here and remove the gems.rb
template and the template_path
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can. I'll do it.
6d0092e
to
c3d9073
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, just one more small comment but I'll fix it myself when rebasing this! Thanks so much @gustavothecoder!
c3d9073
to
99a4124
Compare
…ig-key Add `--gemfile` flag to `bundle init` to configure gemfile name to generate (cherry picked from commit c91f6ef)
What was the end-user or developer problem that led to this PR?
When running
bundle init
withBUNDLE_GEMFILE
, the gemfile name is still the original (Gemfile
) instead of the custom defined inBUNDLE_GEMFILE
.For more details, see the issue #6016.
What is your fix for the problem, implemented in this PR?
The main problem here is that
Bundler#preferred_gemfile_name
doesn't consider theBUNDLE_GEMFILE
config, so my first change was adjust this method to use theBUNDLE_GEMFILE
when necessary. I changed the method to give priority to theinit_gems_rb
config, so if user uses bothinit_gems_rb
andBUNDLE_GEMFILE
, the first one will be used. I decide to make this way to preserve the original behavior, but I'm not sure if this approach is ideal and I would like to know what you guys think. I think that we'll need to update the docs with this behavior, by the way.The second change I made was to adjusting the
init
command to use some template whenBUNDLE_GEMFILE
is used. This was necessary because the template is chosen based on the gemfile name and the current implementation doesn't consider the case where the gemfile has a custom name. I noticed that all available templates has the same content, is it feasible to merge them into a single template? Because that would simplify the code a bit.Make sure the following tasks are checked