Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions lib/tasks/git-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const Promise = RSVP.Promise;
class GitInitTask extends Task {
run(_commandOptions) {
let commandOptions = _commandOptions || {};
const template = require('lodash.template');
const chalk = require('chalk');
let ui = this.ui;

Expand All @@ -26,11 +25,7 @@ class GitInitTask extends Task {

return this._gitInit()
.then(() => this._gitAdd())
.then(() => {
let commitTemplate = fs.readFileSync(path.join(__dirname, '../utilities/COMMIT_MESSAGE.txt'));
let commitMessage = template(commitTemplate)(pkg);
return this._gitCommit(commitMessage);
})
.then(() => this._gitCommit())
.then(() => ui.writeLine(chalk.green('Successfully initialized git.')));
})
.catch(error => {
Expand All @@ -53,8 +48,19 @@ class GitInitTask extends Task {
return execa('git', ['add', '.']);
}

_gitCommit(commitMessage) {
return execa('git', ['commit', '-m', commitMessage], { env: this.buildGitEnvironment() });
_gitCommit() {
const template = require('lodash.template');
let commitTemplate = fs.readFileSync(path.join(__dirname, '../utilities/COMMIT_MESSAGE.txt'));
let commitMessage = template(commitTemplate)(pkg);
let env = this.buildGitEnvironment();
return execa('git', ['commit', '-m', commitMessage], { env })
.catch(error => {
if (error && error.message && error.message.indexOf('git config --global user') > -1) {
env.GIT_COMMITTER_NAME = 'Tomster';
env.GIT_COMMITTER_EMAIL = 'tomster@emberjs.com';
return execa('git', ['commit', '-m', commitMessage], { env });
}
Copy link
Member

Choose a reason for hiding this comment

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

since we're not rethrowing error here the error will be swallowed now, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

oops your are right, we should re-throw....

Copy link
Contributor

Choose a reason for hiding this comment

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

PR inbound

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'm so frustrated I didn't handle this properly in the first place... Thanks for fixing the PR!

});
}

buildGitEnvironment() {
Expand All @@ -63,8 +69,6 @@ class GitInitTask extends Task {
return Object.assign({}, process.env, {
GIT_AUTHOR_NAME: 'Tomster',
GIT_AUTHOR_EMAIL: 'tomster@emberjs.com',
GIT_COMMITTER_NAME: 'Tomster',
GIT_COMMITTER_EMAIL: 'tomster@emberjs.com',
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/tasks/git-init-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ describe('git-init', function() {
td.when(task._gitVersion()).thenResolve();
td.when(task._gitInit()).thenResolve();
td.when(task._gitAdd()).thenResolve();
td.when(task._gitCommit(td.matchers.anything())).thenResolve();
td.when(task._gitCommit()).thenResolve();

return task.run().then(function() {
td.verify(task._gitVersion());
td.verify(task._gitInit());
td.verify(task._gitAdd());
td.verify(task._gitCommit(td.matchers.anything()));
td.verify(task._gitCommit());

expect(task.ui.output).to.contain('Successfully initialized git.');
expect(task.ui.errors).to.equal('');
Expand Down