Skip to content
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

Merged
merged 1 commit into from
Jul 21, 2014

Conversation

rondale-sc
Copy link
Contributor

No description provided.

@rondale-sc
Copy link
Contributor Author

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.

  • I'm pretty sure the commit message could contain more information, but I'm not sure what.
  • I'm not sure about whether this should be opt-out (as it is currently implemented) or opt in
  • I'm not sure why tmp isn't being cleared on SIGINT

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'));
Copy link
Member

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).

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

then

@rondale-sc
Copy link
Contributor Author

@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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation is incorrect

@stefanpenner
Copy link
Contributor

should this detect if git is available and automatically "skip" if for some reason it is not?

@ccoenen
Copy link
Contributor

ccoenen commented Jul 14, 2014

Yes, that would be preferable. It might also not be on everybody's path. Especially MSysGit doesn't do this by default (which i think is a bad default, but that's besides the point).

edit: Damn, you people are fast :D

@rondale-sc
Copy link
Contributor Author

@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();
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was my thought as well @ccoenen. I was kinda hoping that people programming on windows might use mysysgit which comes with a bash emulator. But you're right there is probably a non trivial segment using cmd.exe or powershell. Eitherway, git --version should do the trick in this case.

@rwjblue
Copy link
Member

rwjblue commented Jul 16, 2014

Looks good, only made a small suggestion. Also, have we tested this when git is not available (likely kinda hard), but tweaking the git --version call to use xgit --version locally for testing would do the trick)? I just want to ensure that it does not go boom...

@rondale-sc
Copy link
Contributor Author

@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! :)))

@bcardarella
Copy link
Contributor

@stefanpenner what about an opt-in setting in the rc file?

@rwjblue
Copy link
Member

rwjblue commented Jul 16, 2014

I don't think that the .ember-cli file works at the moment.

@rwjblue
Copy link
Member

rwjblue commented Jul 16, 2014

@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.

@rondale-sc
Copy link
Contributor Author

@rjackson I think I was able to get decent coverage with this. I tested on maverics, windows 7, and linux (ubuntu). I think this could become more robust if we encounter other systems/shells that aren't currently covered.

thoughts?

@rwjblue
Copy link
Member

rwjblue commented Jul 16, 2014

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
];
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@ccoenen
Copy link
Contributor

ccoenen commented Jul 16, 2014

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, git status --porcelain)

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:

Der Befehl "git" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

@rwjblue
Copy link
Member

rwjblue commented Jul 16, 2014

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.

@rondale-sc
Copy link
Contributor Author

@rjackson How do we do that without swallowing errors elsewhere?

@rwjblue
Copy link
Member

rwjblue commented Jul 17, 2014

@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 git functionality (which IMHO is completely convenience and not 100% required). Those errors should just be swallowed.

@rondale-sc
Copy link
Contributor Author

@rjackson done! :)

@rwjblue
Copy link
Member

rwjblue commented Jul 17, 2014

Looks like we need a rebase here.

@rondale-sc
Copy link
Contributor Author

@rjackson good to go

var path = require('path');
var pkg = require('../../package.json');
var fs = require('fs');
var _ = require('lodash-node');
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

^^ is still important

@rwjblue
Copy link
Member

rwjblue commented Jul 19, 2014

Stef left some comments, will also need a rebase.

@benlesh
Copy link

benlesh commented Jul 21, 2014

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:

  • "Can you have it automagically add an initial commit?"
  • "Can you integrate a version bump?"
  • "... with a commit?"
  • "... and a push?"
  • "Can you add support for SVN? TFS? Hg?"

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".

@jdjkelly
Copy link
Contributor

@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.

stefanpenner added a commit that referenced this pull request Jul 21, 2014
@stefanpenner stefanpenner merged commit 2e53f90 into ember-cli:master Jul 21, 2014
@benlesh
Copy link

benlesh commented Jul 21, 2014

@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.

@stefanpenner
Copy link
Contributor

For people not using git. Nothing happens

@rwjblue
Copy link
Member

rwjblue commented Jul 21, 2014

Ember CLI is essentially a curated bag of best practices. This is simple to opt-out of, and if you don't have git it silently continues.

@rondale-sc - Would you please submit a PR to the documentation to mention how to opt-out of this via --skip-git? It can't be merged until 0.0.40 is shipped, but it will make this easier once we release.

@mehulkar
Copy link
Contributor

dat initial commit msg...

@joostdevries
Copy link
Member

@stefanpenner Any reason we're always showing Could not find watchman, falling back to NodeWatcher for file system events but we're not showing Could not find git, no repository initialized here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants