-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 git init to ember new
#1369
Add git init to ember new
#1369
Conversation
This is still slightly a work in progress, I'm having an issue with this throwing an error. But I wanted to get some peoples thoughts on what I have so far.
Any thoughts would be great! :)) |
}).then(noop, function(){ | ||
ui.write(chalk.yellow('Something went wrong with git commit')); | ||
}).finally(function(){ | ||
ui.write(chalk.green('Sucessfully initialized git')); |
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.
Finally happens for both resolve and reject cases, so this message is misleading (as it may not have been successful).
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.
Ah, since that is the case what is used for success. I know catch is used for errors.
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.
then
@jakecraige Thanks for taking such a thorough look through this! I really appreciate it :)))) |
if(commandOptions.skipGit) { return Promise.resolve(); } | ||
|
||
return exec('git init') | ||
.then(function() { |
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.
indentation is incorrect
should this detect if git is available and automatically "skip" if for some reason it is not? |
Yes, that would be preferable. It might also not be on everybody's edit: Damn, you people are fast :D |
@ccoenen Does rondale-sc@9abcdb1 look like it will do the trick in regard to if git isn't present? The build isn't passing atm, but that'll be fixed sometime early this week (ideally. :) |
|
||
return exec('git --version') | ||
.catch(function(){ | ||
return Promise.resolve(); |
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.
You can leave out return Promise.resolve();
just leave an empty function.
That being said, can we check the error to be the one we expect, if it is "handle it" otherwise rethrow it
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.
Absolutely. I think exec of git --version
will just return non-zero if it isn't on the system. I'm going to investigate to see if this the best way to detect git. Pretty sure it isn't which git
but I'll check again just to be sure.
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.
which
is not installed by default on Window's boxes. So I think git --version
is your best bet.
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.
I think git --version
is the way to go.
Alternatively, I could use the bash/zsh builtin command -v git
which will return the string "git" or nothing depending on availability. That should work for most people on windows and bash/zsh, but I'm not sure it's availability would be wide enough for people with other setups.
If we do go with git --version
from exec the fact that it doesn't error should be enough (/cc @stefanpenner). I'm not sure we could get more specific with the error handling. But maybe I'm missing something obvious.
I think this is close to needing a rebase to clean it up some.
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.
command -v won't work on a "plain" windows commandline (cmd.exe shell, which is, sadly, probably the most widely used shell).
Banging against git
itself and seeing what happens is really probably the best option cross platform.
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 good, only made a small suggestion. Also, have we tested this when git is not available (likely kinda hard), but tweaking the |
@rjackson I tested with xgit and talked to stefan. It now appropriately does the check, and if the check fails doesn't continue. I'm doing some regex matching now to determine if it fails in the way we expect, and if it fails in a different way it will throw the original error. I think this is ready Oh and I added tomster! :))) |
@stefanpenner what about an opt-in setting in the rc file? |
I don't think that the .ember-cli file works at the moment. |
@rondale-sc - I don't think you will be able to do a meaningful regex, as it is completely dependent on system type, shell, whatever else. |
I generally disagree that you can ever be comprehensive. You would have to handle every shell combination on every supported platform to be certain. I am completely opposed to an error caused here having the ability (if the error is not caught) to cause ember new to fail. |
/command not found/, // *nix | ||
/not recognized as an internal or external command/, // cmd.exe | ||
/not recognized as the name of a cmdlet, function, script file, or operable program/ // Powershell | ||
]; |
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.
these will break for other languages for sure. here's what i get from a non-existent command:
C:\Users\.....\workspace>blarg
Der Befehl "blarg" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
I don't think we should include regexes.
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.
@ccoenen What error code does it throw? I think on mac I get 127. Maybe that will be more reliable?
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.
%errorlevel%
for various commands.
C:\Users\...\workspace>blarg
Der Befehl "blarg" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
C:\Users\---\workspace>echo %errorlevel%
9009
C:\Users\---\workspace>git status
fatal: Not a git repository (or any of the parent directories): .git
C:\Users\---\workspace>echo %errorlevel%
128
C:\Users\---\workspace>git version
git version 1.9.0.msysgit.0
C:\Users\---\workspace>echo %errorlevel%
0
Other than the 9009, it looks pretty standard. I wasn't able to find any authorative source or documentation on this, though. But to be honest, i haven't been doing much work shelling out on windows.
I commented in code, but wanted to make sure that it's not overlooked. Regex-Matching the response really is a recipe for desaster. We should absolutely not do that, unless it's well-defined output from, say, The simple reason is, that there's just too many systems out there. It will break for any number of reasons. In my case, the reason will be: I am on a german system. My error messages read like this:
|
IMHO, if git --version fails we should just abort the git init task. This is a wonderful convenience, but should not prevent usage in the case that we cannot handle all possible scenarios. |
@rjackson How do we do that without swallowing errors elsewhere? |
@rondale-sc - If you just change the catch that you have currently implemented (the one that matches patterns) to: .catch(function() {
// if git is not found or an error was thrown during the `git`
// init process just swallow any errors here
}); That catch would only be catching errors related to the |
@rjackson done! :) |
Looks like we need a rebase here. |
@rjackson good to go |
var path = require('path'); | ||
var pkg = require('../../package.json'); | ||
var fs = require('fs'); | ||
var _ = require('lodash-node'); |
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.
can you explicitly require the subset of lodash you are using like we do: https://github.com/stefanpenner/ember-cli/blob/45ab16638ae21225febdebc1e50cef62f4747eca/lib/utilities/parse-options.js#L3
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.
^^ is still important
Stef left some comments, will also need a rebase. |
Maybe I'm misunderstanding the intent here. But it sounds like you're adding a feature to Ember-Cli that is unrelated to anything Ember-Cli is concerned with. There are large organizations I've worked for that don't use Git and/or don't want to use Git. Food for thought. I also foresee evil:
The node prerequisite is one thing, because it's completely necessary. But I think I can type "git init" all on my own. If you must, you must... but at least this should probably be an "opt-in" rather than an "opt-out". |
@Blesh by the same token - it's really easy to remove a git repository. I think this comes down to being a smart default - one that's easily removed without having to know really anything about ember-cli. |
Add git init to `ember new`
@jdjkelly "smart defaults" are used to justify junkware on customer electronics. Having an "opinionated" framework like Ember, and an "opinionated" build tool like Ember-CLI is an amazing boon... However, "opinionated" crosses the line when it's dealing with things that really aren't its concern. Ember-CLI shouldn't tell me what VCS I should use. I personally always use Git. But there is still a very large portion of the population that does not. This being GitHub, which means near 100% of the people reading this are Git users, I'm sure I'm the only voice of dissent on this issue... but I think this is a really bad idea. I'm willing to be convinced otherwise. |
For people not using git. Nothing happens |
Ember CLI is essentially a curated bag of best practices. This is simple to opt-out of, and if you don't have @rondale-sc - Would you please submit a PR to the documentation to mention how to opt-out of this via |
dat initial commit msg... |
@stefanpenner Any reason we're always showing |
No description provided.