Initalize git repo when creatin new rails app #27632

Merged
merged 1 commit into from Jan 18, 2017

Projects

None yet

9 participants

@dixpac
Contributor
dixpac commented Jan 10, 2017 edited

Since Rails is already generating .gitignore, and in 90% of cases when creating new rails app user initialise git repo. Now Rails automatically initialises new git repo on rails new command If --skip-git is not specified.

I've added this as new "step" in generator called version_control in case someone wants to override this when creating custom app builder (maybe not using git as version_control but something else)

@sgrif sgrif was assigned by rails-bot Jan 10, 2017
@rails-bot

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@zachweed

There's a large difference between creating a single, small file, and initializing an empty git repository automatically. Also, where is the source indicating that 90% of rails applications use git?

That aside.. If this does get approved then I would highly recommend that we flip the --skip-git to a flag like --with-git so that we assume nothing about what the engineer might be using for version control and allow them to opt-in, if they so choose. In addition to that, it would make sense if you were to also include changes to only create .gitignore when a flag is specified (or not specified).

@dixpac
Contributor
dixpac commented Jan 10, 2017 edited

@zachweed thanks for the comment :)
Sure there is the huge difference(56k to be exact :)), but since rails generator is already generating .gitignore that means that assumption is made you are going to use git. If that is the case why not to initialize the git repo ?

That being said, I like your idea about using --with-git instead of --skip-git (that was also my initial idea), but since there is already --skip-git, I push this solution to see the reactions about adding this kind of feature to the generator :).

Also, I feel that using --skip is more Rails way then --with in this use case

@zachweed

@dixpac I completely agree. I personally don't agree with the .gitignore being created either, which is why I was slightly implying removal of that as well by using something with --with-git. Feel free to ping me if you need any help with any of it :)

@georgeclaghorn
Contributor

“Assume nothing“ isn’t really Rails’s modus operandi.

@rafaelfranca
Member

Thank you for the pull request but doing this by default means that users now need to have git installed to generated a rails application otherwise it will fail. Can we check if git is present in the machine before running the command?

@rafaelfranca rafaelfranca assigned rafaelfranca and unassigned sgrif Jan 10, 2017
@dixpac
Contributor
dixpac commented Jan 11, 2017 edited

@rafaelfranca we can check if git is present, but not sure do we have to because run "git init" command will return false if git is not present and nothing will happen (execution will not fail), new rails app will be initialized normally(without git)

@zachweed

@dixpac it may be a good idea to return a message indicating we intended to create an empty git repo but were unable to due to it not being installed.

@@ -205,6 +211,7 @@ def create_root_files
build(:configru)
build(:gitignore) unless options[:skip_git]
build(:gemfile) unless options[:skip_gemfile]
+ build(:version_control)
@PritiKumr
PritiKumr Jan 11, 2017

Why not check the options[:skip_git] flag here like how its been done for :gitignore?

@dixpac
dixpac Jan 11, 2017 Contributor

Since other developers can create custom AppBuilder templates by overriding rails AppBuilder methods, adding options[:skip_git] here would add more complexity if someone wants to use other version_control system in their templates :)

@rafaelfranca

Could you add a CHANGELOG entry?

@dixpac
Contributor
dixpac commented Jan 11, 2017

@rafaelfranca sure I added CHANGELOG and rebased from master :)

@dixpac dixpac Initalize git repo when creatin new rails app
* If `--skip-git` is not specified initalize git repo
 when creating new rails app
8989a50
@dixpac
Contributor
dixpac commented Jan 12, 2017

@rafaelfranca I'm not sure why tests are red after I rebased from master :(

@maclover7
Member

@dixpac restarted the randomly failing build, all green now

@welkie
welkie commented Jan 12, 2017

I actually like this idea. At first I was thinking "wow, that assumes a lot about the developer's intentions" but then I realized... Yes, and that's probably a good thing in the context of Rails development. Rails is opinionated. Most developers use version control and most developers using version control use Git for it. So I think it is logical to implicitly create a new Git repo during the creation of a new Rails app.

@rafaelfranca rafaelfranca merged commit 8989a50 into rails:master Jan 18, 2017

2 checks passed

codeclimate no new or fixed issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@maclover7 maclover7 removed the needs work label Jan 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment