mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 15:38:33 +02:00
big command factoring
This commit is contained in:
parent
af3d440874
commit
5ec8a2916f
9 changed files with 351 additions and 127 deletions
174
build/bundle.js
174
build/bundle.js
|
@ -7143,6 +7143,9 @@ var GitError = Errors.GitError;
|
||||||
var CommandResult = Errors.CommandResult;
|
var CommandResult = Errors.CommandResult;
|
||||||
var EventBaton = require('../util/eventBaton').EventBaton;
|
var EventBaton = require('../util/eventBaton').EventBaton;
|
||||||
|
|
||||||
|
// REFACTOR in progress
|
||||||
|
var Commands = {};
|
||||||
|
|
||||||
function GitEngine(options) {
|
function GitEngine(options) {
|
||||||
this.rootCommit = null;
|
this.rootCommit = null;
|
||||||
this.refs = {};
|
this.refs = {};
|
||||||
|
@ -8337,9 +8340,15 @@ GitEngine.prototype.cherrypick = function(commit) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.commitStarter = function() {
|
GitEngine.prototype.commitStarter = function() {
|
||||||
this.acceptNoGeneralArgs();
|
Commands.commit(this, this.command, this.commandOptions);
|
||||||
if (this.commandOptions['-am'] && (
|
};
|
||||||
this.commandOptions['-a'] || this.commandOptions['-m'])) {
|
|
||||||
|
Commands.commit = function(engine, command) {
|
||||||
|
var commandOptions = command.getSupportedMap();
|
||||||
|
command.acceptNoGeneralArgs();
|
||||||
|
|
||||||
|
if (commandOptions['-am'] && (
|
||||||
|
commandOptions['-a'] || commandOptions['-m'])) {
|
||||||
throw new GitError({
|
throw new GitError({
|
||||||
msg: intl.str('git-error-options')
|
msg: intl.str('git-error-options')
|
||||||
});
|
});
|
||||||
|
@ -8347,23 +8356,23 @@ GitEngine.prototype.commitStarter = function() {
|
||||||
|
|
||||||
var msg = null;
|
var msg = null;
|
||||||
var args = null;
|
var args = null;
|
||||||
if (this.commandOptions['-a']) {
|
if (commandOptions['-a']) {
|
||||||
this.command.addWarning(intl.str('git-warning-add'));
|
command.addWarning(intl.str('git-warning-add'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.commandOptions['-am']) {
|
if (commandOptions['-am']) {
|
||||||
args = this.commandOptions['-am'];
|
args = commandOptions['-am'];
|
||||||
this.validateArgBounds(args, 1, 1, '-am');
|
engine.validateArgBounds(args, 1, 1, '-am');
|
||||||
msg = args[0];
|
msg = args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.commandOptions['-m']) {
|
if (commandOptions['-m']) {
|
||||||
args = this.commandOptions['-m'];
|
args = commandOptions['-m'];
|
||||||
this.validateArgBounds(args, 1, 1, '-m');
|
engine.validateArgBounds(args, 1, 1, '-m');
|
||||||
msg = args[0];
|
msg = args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
var newCommit = this.commit();
|
var newCommit = engine.commit();
|
||||||
if (msg) {
|
if (msg) {
|
||||||
msg = msg
|
msg = msg
|
||||||
.replace(/"/g, '"')
|
.replace(/"/g, '"')
|
||||||
|
@ -8373,11 +8382,11 @@ GitEngine.prototype.commitStarter = function() {
|
||||||
newCommit.set('commitMessage', msg);
|
newCommit.set('commitMessage', msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
var promise = this.animationFactory.playCommitBirthPromiseAnimation(
|
var promise = engine.animationFactory.playCommitBirthPromiseAnimation(
|
||||||
newCommit,
|
newCommit,
|
||||||
this.gitVisuals
|
engine.gitVisuals
|
||||||
);
|
);
|
||||||
this.animationQueue.thenFinish(promise);
|
engine.animationQueue.thenFinish(promise);
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.commit = function() {
|
GitEngine.prototype.commit = function() {
|
||||||
|
@ -13664,6 +13673,7 @@ var GitCommands = require('../git/commands');
|
||||||
var GitOptionParser = GitCommands.GitOptionParser;
|
var GitOptionParser = GitCommands.GitOptionParser;
|
||||||
|
|
||||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||||
|
var intl = require('../intl');
|
||||||
|
|
||||||
var CommandProcessError = Errors.CommandProcessError;
|
var CommandProcessError = Errors.CommandProcessError;
|
||||||
var GitError = Errors.GitError;
|
var GitError = Errors.GitError;
|
||||||
|
@ -13709,6 +13719,53 @@ var Command = Backbone.Model.extend({
|
||||||
this.set('warnings', []);
|
this.set('warnings', []);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getGeneralArgs: function() {
|
||||||
|
return this.get('generalArgs');
|
||||||
|
},
|
||||||
|
|
||||||
|
getSupportedMap: function() {
|
||||||
|
return this.get('supportedMap');
|
||||||
|
},
|
||||||
|
|
||||||
|
acceptNoGeneralArgs: function() {
|
||||||
|
if (this.getGeneralArgs().length) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str('git-error-no-general-args')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// this is a little utility class to help arg validation that happens over and over again
|
||||||
|
validateArgBounds: function(args, lower, upper, option) {
|
||||||
|
var what = (option === undefined) ?
|
||||||
|
'git ' + this.get('method') :
|
||||||
|
this.get('method') + ' ' + option + ' ';
|
||||||
|
what = 'with ' + what;
|
||||||
|
|
||||||
|
if (args.length < lower) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str(
|
||||||
|
'git-error-args-few',
|
||||||
|
{
|
||||||
|
lower: String(lower),
|
||||||
|
what: what
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (args.length > upper) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str(
|
||||||
|
'git-error-args-many',
|
||||||
|
{
|
||||||
|
upper: String(upper),
|
||||||
|
what: what
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
validateAtInit: function() {
|
validateAtInit: function() {
|
||||||
if (this.get('rawStr') === null) {
|
if (this.get('rawStr') === null) {
|
||||||
throw new Error('Give me a string!');
|
throw new Error('Give me a string!');
|
||||||
|
@ -23885,6 +23942,9 @@ var GitError = Errors.GitError;
|
||||||
var CommandResult = Errors.CommandResult;
|
var CommandResult = Errors.CommandResult;
|
||||||
var EventBaton = require('../util/eventBaton').EventBaton;
|
var EventBaton = require('../util/eventBaton').EventBaton;
|
||||||
|
|
||||||
|
// REFACTOR in progress
|
||||||
|
var Commands = {};
|
||||||
|
|
||||||
function GitEngine(options) {
|
function GitEngine(options) {
|
||||||
this.rootCommit = null;
|
this.rootCommit = null;
|
||||||
this.refs = {};
|
this.refs = {};
|
||||||
|
@ -25079,9 +25139,15 @@ GitEngine.prototype.cherrypick = function(commit) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.commitStarter = function() {
|
GitEngine.prototype.commitStarter = function() {
|
||||||
this.acceptNoGeneralArgs();
|
Commands.commit(this, this.command, this.commandOptions);
|
||||||
if (this.commandOptions['-am'] && (
|
};
|
||||||
this.commandOptions['-a'] || this.commandOptions['-m'])) {
|
|
||||||
|
Commands.commit = function(engine, command) {
|
||||||
|
var commandOptions = command.getSupportedMap();
|
||||||
|
command.acceptNoGeneralArgs();
|
||||||
|
|
||||||
|
if (commandOptions['-am'] && (
|
||||||
|
commandOptions['-a'] || commandOptions['-m'])) {
|
||||||
throw new GitError({
|
throw new GitError({
|
||||||
msg: intl.str('git-error-options')
|
msg: intl.str('git-error-options')
|
||||||
});
|
});
|
||||||
|
@ -25089,23 +25155,23 @@ GitEngine.prototype.commitStarter = function() {
|
||||||
|
|
||||||
var msg = null;
|
var msg = null;
|
||||||
var args = null;
|
var args = null;
|
||||||
if (this.commandOptions['-a']) {
|
if (commandOptions['-a']) {
|
||||||
this.command.addWarning(intl.str('git-warning-add'));
|
command.addWarning(intl.str('git-warning-add'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.commandOptions['-am']) {
|
if (commandOptions['-am']) {
|
||||||
args = this.commandOptions['-am'];
|
args = commandOptions['-am'];
|
||||||
this.validateArgBounds(args, 1, 1, '-am');
|
engine.validateArgBounds(args, 1, 1, '-am');
|
||||||
msg = args[0];
|
msg = args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.commandOptions['-m']) {
|
if (commandOptions['-m']) {
|
||||||
args = this.commandOptions['-m'];
|
args = commandOptions['-m'];
|
||||||
this.validateArgBounds(args, 1, 1, '-m');
|
engine.validateArgBounds(args, 1, 1, '-m');
|
||||||
msg = args[0];
|
msg = args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
var newCommit = this.commit();
|
var newCommit = engine.commit();
|
||||||
if (msg) {
|
if (msg) {
|
||||||
msg = msg
|
msg = msg
|
||||||
.replace(/"/g, '"')
|
.replace(/"/g, '"')
|
||||||
|
@ -25115,11 +25181,11 @@ GitEngine.prototype.commitStarter = function() {
|
||||||
newCommit.set('commitMessage', msg);
|
newCommit.set('commitMessage', msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
var promise = this.animationFactory.playCommitBirthPromiseAnimation(
|
var promise = engine.animationFactory.playCommitBirthPromiseAnimation(
|
||||||
newCommit,
|
newCommit,
|
||||||
this.gitVisuals
|
engine.gitVisuals
|
||||||
);
|
);
|
||||||
this.animationQueue.thenFinish(promise);
|
engine.animationQueue.thenFinish(promise);
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.commit = function() {
|
GitEngine.prototype.commit = function() {
|
||||||
|
@ -29359,6 +29425,7 @@ var GitCommands = require('../git/commands');
|
||||||
var GitOptionParser = GitCommands.GitOptionParser;
|
var GitOptionParser = GitCommands.GitOptionParser;
|
||||||
|
|
||||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||||
|
var intl = require('../intl');
|
||||||
|
|
||||||
var CommandProcessError = Errors.CommandProcessError;
|
var CommandProcessError = Errors.CommandProcessError;
|
||||||
var GitError = Errors.GitError;
|
var GitError = Errors.GitError;
|
||||||
|
@ -29404,6 +29471,53 @@ var Command = Backbone.Model.extend({
|
||||||
this.set('warnings', []);
|
this.set('warnings', []);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getGeneralArgs: function() {
|
||||||
|
return this.get('generalArgs');
|
||||||
|
},
|
||||||
|
|
||||||
|
getSupportedMap: function() {
|
||||||
|
return this.get('supportedMap');
|
||||||
|
},
|
||||||
|
|
||||||
|
acceptNoGeneralArgs: function() {
|
||||||
|
if (this.getGeneralArgs().length) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str('git-error-no-general-args')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// this is a little utility class to help arg validation that happens over and over again
|
||||||
|
validateArgBounds: function(args, lower, upper, option) {
|
||||||
|
var what = (option === undefined) ?
|
||||||
|
'git ' + this.get('method') :
|
||||||
|
this.get('method') + ' ' + option + ' ';
|
||||||
|
what = 'with ' + what;
|
||||||
|
|
||||||
|
if (args.length < lower) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str(
|
||||||
|
'git-error-args-few',
|
||||||
|
{
|
||||||
|
lower: String(lower),
|
||||||
|
what: what
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (args.length > upper) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str(
|
||||||
|
'git-error-args-many',
|
||||||
|
{
|
||||||
|
upper: String(upper),
|
||||||
|
what: what
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
validateAtInit: function() {
|
validateAtInit: function() {
|
||||||
if (this.get('rawStr') === null) {
|
if (this.get('rawStr') === null) {
|
||||||
throw new Error('Give me a string!');
|
throw new Error('Give me a string!');
|
||||||
|
|
File diff suppressed because one or more lines are too long
1
build/bundle.min.js
vendored
1
build/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -439,7 +439,7 @@
|
||||||
For a much easier time perusing the source, see the individual files at:
|
For a much easier time perusing the source, see the individual files at:
|
||||||
https://github.com/pcottle/learnGitBranching
|
https://github.com/pcottle/learnGitBranching
|
||||||
-->
|
-->
|
||||||
<script src="build/bundle.min.681df2a8.js"></script>
|
<script src="build/bundle.js"></script>
|
||||||
|
|
||||||
<!-- The advantage of github pages: super-easy, simple, slick static hostic.
|
<!-- The advantage of github pages: super-easy, simple, slick static hostic.
|
||||||
The downside? No raw logs to parse for analytics, so I have to include
|
The downside? No raw logs to parse for analytics, so I have to include
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
var HeadlessGit = require('../src/js/git/headless').HeadlessGit;
|
var HeadlessGit = require('../src/js/git/headless').HeadlessGit;
|
||||||
var TreeCompare = require('../src/js/git/treeCompare').TreeCompare;
|
var TreeCompare = require('../src/js/git/treeCompare').TreeCompare;
|
||||||
|
|
||||||
|
var TIME = 150;
|
||||||
|
// useful for throwing garbage and then expecting one commit
|
||||||
|
var oneCommit = '{"branches":{"master":{"target":"C2","id":"master"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}';
|
||||||
|
|
||||||
var loadTree = function(json) {
|
var loadTree = function(json) {
|
||||||
return JSON.parse(unescape(json));
|
return JSON.parse(unescape(json));
|
||||||
};
|
};
|
||||||
|
@ -14,12 +18,21 @@ var compareAnswer = function(headless, expectedJSON) {
|
||||||
|
|
||||||
var expectTreeAsync = function(command, expectedJSON) {
|
var expectTreeAsync = function(command, expectedJSON) {
|
||||||
var headless = new HeadlessGit();
|
var headless = new HeadlessGit();
|
||||||
|
var start = Date.now();
|
||||||
|
var haveReported = false;
|
||||||
|
|
||||||
runs(function() {
|
runs(function() {
|
||||||
headless.sendCommand(command);
|
headless.sendCommand(command);
|
||||||
});
|
});
|
||||||
waitsFor(function() {
|
waitsFor(function() {
|
||||||
|
var diff = (Date.now() - start);
|
||||||
|
if (diff > TIME - 50 && !haveReported) {
|
||||||
|
haveReported = true;
|
||||||
|
console.log('not going to match', command);
|
||||||
|
console.log('expected', loadTree(expectedJSON), 'actual', headless.gitEngine.exportTree());
|
||||||
|
}
|
||||||
return compareAnswer(headless, expectedJSON);
|
return compareAnswer(headless, expectedJSON);
|
||||||
}, 'trees should be equal', 750);
|
}, 'trees should be equal', 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('GitEngine', function() {
|
describe('GitEngine', function() {
|
||||||
|
@ -30,6 +43,20 @@ describe('GitEngine', function() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles commit options', function() {
|
||||||
|
expectTreeAsync(
|
||||||
|
'git commit; git commit --amend;',
|
||||||
|
'%7B%22branches%22%3A%7B%22master%22%3A%7B%22target%22%3A%22C2%27%22%2C%22id%22%3A%22master%22%7D%7D%2C%22commits%22%3A%7B%22C0%22%3A%7B%22parents%22%3A%5B%5D%2C%22id%22%3A%22C0%22%2C%22rootCommit%22%3Atrue%7D%2C%22C1%22%3A%7B%22parents%22%3A%5B%22C0%22%5D%2C%22id%22%3A%22C1%22%7D%2C%22C2%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%22%7D%2C%22C2%27%22%3A%7B%22parents%22%3A%5B%22C1%22%5D%2C%22id%22%3A%22C2%27%22%7D%7D%2C%22HEAD%22%3A%7B%22target%22%3A%22master%22%2C%22id%22%3A%22HEAD%22%7D%7D'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws with bad arg options', function() {
|
||||||
|
expectTreeAsync(
|
||||||
|
'git commit foo; git commit -am -m; git commit -am -a; git commit -am "hi" "ho"; git commit',
|
||||||
|
oneCommit
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('Checkouts', function() {
|
it('Checkouts', function() {
|
||||||
expectTreeAsync(
|
expectTreeAsync(
|
||||||
'git checkout -b side',
|
'git checkout -b side',
|
||||||
|
|
|
@ -2,6 +2,7 @@ var HeadlessGit = require('../src/js/git/headless').HeadlessGit;
|
||||||
var TreeCompare = require('../src/js/git/treeCompare').TreeCompare;
|
var TreeCompare = require('../src/js/git/treeCompare').TreeCompare;
|
||||||
|
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
|
var TIME = 150;
|
||||||
|
|
||||||
var loadTree = function(json) {
|
var loadTree = function(json) {
|
||||||
return JSON.parse(unescape(json));
|
return JSON.parse(unescape(json));
|
||||||
|
@ -25,7 +26,7 @@ var expectTreeAsync = function(headless, levelBlob) {
|
||||||
});
|
});
|
||||||
waitsFor(function() {
|
waitsFor(function() {
|
||||||
var diff = (Date.now() - start);
|
var diff = (Date.now() - start);
|
||||||
if (diff > 700) {
|
if (diff > TIME - 50) {
|
||||||
console.log('not going to match', command);
|
console.log('not going to match', command);
|
||||||
}
|
}
|
||||||
var result = compareLevelTree(headless, levelBlob);
|
var result = compareLevelTree(headless, levelBlob);
|
||||||
|
@ -33,7 +34,7 @@ var expectTreeAsync = function(headless, levelBlob) {
|
||||||
console.log('solved level ' + levelBlob.name.en_US);
|
console.log('solved level ' + levelBlob.name.en_US);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}, 'trees should be equal', 750);
|
}, 'trees should be equal', TIME);
|
||||||
};
|
};
|
||||||
|
|
||||||
var expectLevelSolved = function(levelBlob) {
|
var expectLevelSolved = function(levelBlob) {
|
||||||
|
|
108
src/js/commands/index.js
Normal file
108
src/js/commands/index.js
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
var _ = require('underscore');
|
||||||
|
var Q = require('q');
|
||||||
|
|
||||||
|
var intl = require('../intl');
|
||||||
|
|
||||||
|
var Errors = require('../util/errors');
|
||||||
|
var GitError = Errors.GitError;
|
||||||
|
var CommandResult = Errors.CommandResult;
|
||||||
|
|
||||||
|
var Commands = {
|
||||||
|
commit: function(engine, command) {
|
||||||
|
var commandOptions = command.getSupportedMap();
|
||||||
|
command.acceptNoGeneralArgs();
|
||||||
|
|
||||||
|
if (commandOptions['-am'] && (
|
||||||
|
commandOptions['-a'] || commandOptions['-m'])) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str('git-error-options')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var msg = null;
|
||||||
|
var args = null;
|
||||||
|
if (commandOptions['-a']) {
|
||||||
|
command.addWarning(intl.str('git-warning-add'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandOptions['-am']) {
|
||||||
|
args = commandOptions['-am'];
|
||||||
|
command.validateArgBounds(args, 1, 1, '-am');
|
||||||
|
msg = args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandOptions['-m']) {
|
||||||
|
args = commandOptions['-m'];
|
||||||
|
command.validateArgBounds(args, 1, 1, '-m');
|
||||||
|
msg = args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
var newCommit = engine.commit();
|
||||||
|
if (msg) {
|
||||||
|
msg = msg
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/^"/g, '')
|
||||||
|
.replace(/"$/g, '');
|
||||||
|
|
||||||
|
newCommit.set('commitMessage', msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
var promise = engine.animationFactory.playCommitBirthPromiseAnimation(
|
||||||
|
newCommit,
|
||||||
|
engine.gitVisuals
|
||||||
|
);
|
||||||
|
engine.animationQueue.thenFinish(promise);
|
||||||
|
},
|
||||||
|
|
||||||
|
checkout: function(engine, command) {
|
||||||
|
var commandOptions = command.getSupportedMap();
|
||||||
|
var generalArgs = command.getGeneralArgs();
|
||||||
|
|
||||||
|
var args = null;
|
||||||
|
if (commandOptions['-b']) {
|
||||||
|
if (generalArgs.length) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str('git-error-options')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// the user is really trying to just make a branch and then switch to it. so first:
|
||||||
|
args = commandOptions['-b'];
|
||||||
|
command.twoArgsImpliedHead(args, '-b');
|
||||||
|
|
||||||
|
var validId = engine.validateBranchName(args[0]);
|
||||||
|
engine.branch(validId, args[1]);
|
||||||
|
engine.checkout(validId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandOptions['-']) {
|
||||||
|
// get the heads last location
|
||||||
|
var lastPlace = engine.HEAD.get('lastLastTarget');
|
||||||
|
if (!lastPlace) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str('git-result-nothing')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
engine.HEAD.set('target', lastPlace);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandOptions['-B']) {
|
||||||
|
args = commandOptions['-B'];
|
||||||
|
command.twoArgsImpliedHead(args, '-B');
|
||||||
|
|
||||||
|
engine.forceBranch(args[0], args[1]);
|
||||||
|
engine.checkout(args[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
command.validateArgBounds(generalArgs, 1, 1);
|
||||||
|
|
||||||
|
engine.checkout(engine.crappyUnescape(generalArgs[0]));
|
||||||
|
},
|
||||||
|
|
||||||
|
noComma: 123
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Commands;
|
|
@ -14,6 +14,8 @@ var GitError = Errors.GitError;
|
||||||
var CommandResult = Errors.CommandResult;
|
var CommandResult = Errors.CommandResult;
|
||||||
var EventBaton = require('../util/eventBaton').EventBaton;
|
var EventBaton = require('../util/eventBaton').EventBaton;
|
||||||
|
|
||||||
|
var Commands = require('../commands');
|
||||||
|
|
||||||
function GitEngine(options) {
|
function GitEngine(options) {
|
||||||
this.rootCommit = null;
|
this.rootCommit = null;
|
||||||
this.refs = {};
|
this.refs = {};
|
||||||
|
@ -1207,50 +1209,6 @@ GitEngine.prototype.cherrypick = function(commit) {
|
||||||
return newCommit;
|
return newCommit;
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.commitStarter = function() {
|
|
||||||
this.acceptNoGeneralArgs();
|
|
||||||
if (this.commandOptions['-am'] && (
|
|
||||||
this.commandOptions['-a'] || this.commandOptions['-m'])) {
|
|
||||||
throw new GitError({
|
|
||||||
msg: intl.str('git-error-options')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var msg = null;
|
|
||||||
var args = null;
|
|
||||||
if (this.commandOptions['-a']) {
|
|
||||||
this.command.addWarning(intl.str('git-warning-add'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.commandOptions['-am']) {
|
|
||||||
args = this.commandOptions['-am'];
|
|
||||||
this.validateArgBounds(args, 1, 1, '-am');
|
|
||||||
msg = args[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.commandOptions['-m']) {
|
|
||||||
args = this.commandOptions['-m'];
|
|
||||||
this.validateArgBounds(args, 1, 1, '-m');
|
|
||||||
msg = args[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
var newCommit = this.commit();
|
|
||||||
if (msg) {
|
|
||||||
msg = msg
|
|
||||||
.replace(/"/g, '"')
|
|
||||||
.replace(/^"/g, '')
|
|
||||||
.replace(/"$/g, '');
|
|
||||||
|
|
||||||
newCommit.set('commitMessage', msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
var promise = this.animationFactory.playCommitBirthPromiseAnimation(
|
|
||||||
newCommit,
|
|
||||||
this.gitVisuals
|
|
||||||
);
|
|
||||||
this.animationQueue.thenFinish(promise);
|
|
||||||
};
|
|
||||||
|
|
||||||
GitEngine.prototype.commit = function() {
|
GitEngine.prototype.commit = function() {
|
||||||
var targetCommit = this.getCommitFromRef(this.HEAD);
|
var targetCommit = this.getCommitFromRef(this.HEAD);
|
||||||
var id = null;
|
var id = null;
|
||||||
|
@ -1856,51 +1814,6 @@ GitEngine.prototype.merge = function(targetSource) {
|
||||||
return mergeCommit;
|
return mergeCommit;
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.checkoutStarter = function() {
|
|
||||||
var args = null;
|
|
||||||
if (this.commandOptions['-b']) {
|
|
||||||
if (this.generalArgs.length) {
|
|
||||||
throw new GitError({
|
|
||||||
msg: intl.str('git-error-options')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// the user is really trying to just make a branch and then switch to it. so first:
|
|
||||||
args = this.commandOptions['-b'];
|
|
||||||
this.twoArgsImpliedHead(args, '-b');
|
|
||||||
|
|
||||||
var validId = this.validateBranchName(args[0]);
|
|
||||||
this.branch(validId, args[1]);
|
|
||||||
this.checkout(validId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.commandOptions['-']) {
|
|
||||||
// get the heads last location
|
|
||||||
var lastPlace = this.HEAD.get('lastLastTarget');
|
|
||||||
if (!lastPlace) {
|
|
||||||
throw new GitError({
|
|
||||||
msg: intl.str('git-result-nothing')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.HEAD.set('target', lastPlace);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.commandOptions['-B']) {
|
|
||||||
args = this.commandOptions['-B'];
|
|
||||||
this.twoArgsImpliedHead(args, '-B');
|
|
||||||
|
|
||||||
this.forceBranch(args[0], args[1]);
|
|
||||||
this.checkout(args[0]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.validateArgBounds(this.generalArgs, 1, 1);
|
|
||||||
|
|
||||||
this.checkout(this.crappyUnescape(this.generalArgs[0]));
|
|
||||||
};
|
|
||||||
|
|
||||||
GitEngine.prototype.checkout = function(idOrTarget) {
|
GitEngine.prototype.checkout = function(idOrTarget) {
|
||||||
var target = this.resolveID(idOrTarget);
|
var target = this.resolveID(idOrTarget);
|
||||||
if (target.get('id') === 'HEAD') {
|
if (target.get('id') === 'HEAD') {
|
||||||
|
@ -2068,8 +1981,14 @@ GitEngine.prototype.dispatch = function(command, deferred) {
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var methodName = command.get('method').replace(/-/g, '') + 'Starter';
|
var methodName = command.get('method').replace(/-/g, '');
|
||||||
this[methodName]();
|
// first check out module
|
||||||
|
if (Commands[methodName]) {
|
||||||
|
Commands[methodName](this, this.command);
|
||||||
|
} else {
|
||||||
|
var startName = methodName + 'Starter';
|
||||||
|
this[startName]();
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.filterError(err);
|
this.filterError(err);
|
||||||
// short circuit animation by just setting error and returning
|
// short circuit animation by just setting error and returning
|
||||||
|
|
|
@ -7,6 +7,7 @@ var GitCommands = require('../git/commands');
|
||||||
var GitOptionParser = GitCommands.GitOptionParser;
|
var GitOptionParser = GitCommands.GitOptionParser;
|
||||||
|
|
||||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||||
|
var intl = require('../intl');
|
||||||
|
|
||||||
var CommandProcessError = Errors.CommandProcessError;
|
var CommandProcessError = Errors.CommandProcessError;
|
||||||
var GitError = Errors.GitError;
|
var GitError = Errors.GitError;
|
||||||
|
@ -52,6 +53,62 @@ var Command = Backbone.Model.extend({
|
||||||
this.set('warnings', []);
|
this.set('warnings', []);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getGeneralArgs: function() {
|
||||||
|
return this.get('generalArgs');
|
||||||
|
},
|
||||||
|
|
||||||
|
getSupportedMap: function() {
|
||||||
|
return this.get('supportedMap');
|
||||||
|
},
|
||||||
|
|
||||||
|
acceptNoGeneralArgs: function() {
|
||||||
|
if (this.getGeneralArgs().length) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str('git-error-no-general-args')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
twoArgsImpliedHead: function(args, option) {
|
||||||
|
// our args we expect to be between 1 and 2
|
||||||
|
this.validateArgBounds(args, 1, 2, option);
|
||||||
|
// and if it's one, add a HEAD to the back
|
||||||
|
if (args.length == 1) {
|
||||||
|
args.push('HEAD');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// this is a little utility class to help arg validation that happens over and over again
|
||||||
|
validateArgBounds: function(args, lower, upper, option) {
|
||||||
|
var what = (option === undefined) ?
|
||||||
|
'git ' + this.get('method') :
|
||||||
|
this.get('method') + ' ' + option + ' ';
|
||||||
|
what = 'with ' + what;
|
||||||
|
|
||||||
|
if (args.length < lower) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str(
|
||||||
|
'git-error-args-few',
|
||||||
|
{
|
||||||
|
lower: String(lower),
|
||||||
|
what: what
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (args.length > upper) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: intl.str(
|
||||||
|
'git-error-args-many',
|
||||||
|
{
|
||||||
|
upper: String(upper),
|
||||||
|
what: what
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
validateAtInit: function() {
|
validateAtInit: function() {
|
||||||
if (this.get('rawStr') === null) {
|
if (this.get('rawStr') === null) {
|
||||||
throw new Error('Give me a string!');
|
throw new Error('Give me a string!');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue