mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 15:38:33 +02:00
Move commands/index.js to git/commands.js
This commit is contained in:
parent
1372a8eead
commit
ecbe9cb19a
12 changed files with 1646 additions and 1692 deletions
2269
build/bundle.js
2269
build/bundle.js
File diff suppressed because it is too large
Load diff
1
build/bundle.min.771b212d.js
Normal file
1
build/bundle.min.771b212d.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
build/bundle.min.js
vendored
2
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:
|
||||
https://github.com/pcottle/learnGitBranching
|
||||
-->
|
||||
<script src="build/bundle.min.ef737e7b.js"></script>
|
||||
<script src="build/bundle.min.771b212d.js"></script>
|
||||
|
||||
<!-- 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
|
||||
|
|
|
@ -1,522 +0,0 @@
|
|||
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 commandConfig;
|
||||
var Commands = {
|
||||
execute: function(name, engine, commandObj) {
|
||||
if (!commandConfig[name]) {
|
||||
throw new Error('i dont have a command for ' + name);
|
||||
}
|
||||
commandConfig[name].execute.call(this, engine, commandObj);
|
||||
},
|
||||
|
||||
getRegex: function(name) {
|
||||
name = name.replace(/-/g, ''); // ugh cherry-pick @____@
|
||||
if (!commandConfig[name]) {
|
||||
throw new Error('i dont have a regex for ' + name);
|
||||
}
|
||||
return commandConfig[name].regex;
|
||||
},
|
||||
|
||||
isCommandSupported: function(name) {
|
||||
return !!commandConfig[name];
|
||||
},
|
||||
|
||||
getShortcutMap: function() {
|
||||
var map = {};
|
||||
this.loop(function(config, name) {
|
||||
if (!config.sc) {
|
||||
return;
|
||||
}
|
||||
map['git ' + name] = config.sc;
|
||||
}, this);
|
||||
return map;
|
||||
},
|
||||
|
||||
getOptionMap: function() {
|
||||
var optionMap = {};
|
||||
this.loop(function(config, name) {
|
||||
var displayName = config.displayName || name;
|
||||
var thisMap = {};
|
||||
// start all options off as disabled
|
||||
_.each(config.options, function(option) {
|
||||
thisMap[option] = false;
|
||||
});
|
||||
optionMap[displayName] = thisMap;
|
||||
});
|
||||
return optionMap;
|
||||
},
|
||||
|
||||
getRegexMap: function() {
|
||||
var map = {};
|
||||
this.loop(function(config, name) {
|
||||
var displayName = 'git ' + (config.displayName || name);
|
||||
map[displayName] = config.regex;
|
||||
});
|
||||
return map;
|
||||
},
|
||||
|
||||
/**
|
||||
* which commands count for the git golf game
|
||||
*/
|
||||
getCommandsThatCount: function() {
|
||||
var counted = [];
|
||||
this.loop(function(config, name) {
|
||||
if (config.dontCountForGolf) {
|
||||
return;
|
||||
}
|
||||
counted.push(name);
|
||||
});
|
||||
return counted;
|
||||
},
|
||||
|
||||
loop: function(callback, context) {
|
||||
_.each(commandConfig, callback);
|
||||
}
|
||||
};
|
||||
|
||||
commandConfig = {
|
||||
commit: {
|
||||
sc: /^(gc|git ci)($|\s)/,
|
||||
regex: /^git +commit($|\s)/,
|
||||
options: [
|
||||
'--amend',
|
||||
'-a',
|
||||
'-am',
|
||||
'-m'
|
||||
],
|
||||
execute: 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({
|
||||
isAmend: commandOptions['--amend']
|
||||
});
|
||||
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);
|
||||
}
|
||||
},
|
||||
|
||||
cherrypick: {
|
||||
displayName: 'cherry-pick',
|
||||
regex: /^git +cherry-pick($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var commandOptions = command.getSupportedMap();
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
command.validateArgBounds(generalArgs, 1, Number.MAX_VALUE);
|
||||
|
||||
var set = engine.getUpstreamSet('HEAD');
|
||||
// first resolve all the refs (as an error check)
|
||||
var toCherrypick = _.map(generalArgs, function(arg) {
|
||||
var commit = engine.getCommitFromRef(arg);
|
||||
// and check that its not upstream
|
||||
if (set[commit.get('id')]) {
|
||||
throw new GitError({
|
||||
msg: intl.str(
|
||||
'git-error-already-exists',
|
||||
{ commit: commit.get('id') }
|
||||
)
|
||||
});
|
||||
}
|
||||
return commit;
|
||||
}, this);
|
||||
|
||||
engine.setupCherrypickChain(toCherrypick);
|
||||
}
|
||||
},
|
||||
|
||||
pull: {
|
||||
regex: /^git +pull($|\s)/,
|
||||
options: [
|
||||
'--rebase'
|
||||
],
|
||||
execute: function(engine, command) {
|
||||
if (!engine.hasOrigin()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-origin-required')
|
||||
});
|
||||
}
|
||||
|
||||
var commandOptions = command.getSupportedMap();
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.pull({
|
||||
isRebase: commandOptions['--rebase']
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
fakeTeamwork: {
|
||||
regex: /^git +fakeTeamwork($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
if (!engine.hasOrigin()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-origin-required')
|
||||
});
|
||||
}
|
||||
|
||||
command.validateArgBounds(generalArgs, 0, 2);
|
||||
// allow formats of: git Faketeamwork 2 or git Faketeamwork side 3
|
||||
var branch = (engine.origin.refs[generalArgs[0]]) ?
|
||||
generalArgs[0] : 'master';
|
||||
var numToMake = parseInt(generalArgs[0], 10) || generalArgs[1] || 1;
|
||||
|
||||
// make sure its a branch and exists
|
||||
var destBranch = engine.origin.resolveID(branch);
|
||||
if (destBranch.get('type') !== 'branch') {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-options')
|
||||
});
|
||||
}
|
||||
|
||||
engine.fakeTeamwork(numToMake, branch);
|
||||
}
|
||||
},
|
||||
|
||||
clone: {
|
||||
regex: /^git +clone *?$/,
|
||||
execute: function(engine, command) {
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.makeOrigin(engine.printTree());
|
||||
}
|
||||
},
|
||||
|
||||
fetch: {
|
||||
regex: /^git +fetch *?$/,
|
||||
execute: function(engine, command) {
|
||||
if (!engine.hasOrigin()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-origin-required')
|
||||
});
|
||||
}
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.fetch();
|
||||
}
|
||||
},
|
||||
|
||||
branch: {
|
||||
sc: /^(gb|git br)($|\s)/,
|
||||
regex: /^git +branch($|\s)/,
|
||||
options: [
|
||||
'-d',
|
||||
'-D',
|
||||
'-f',
|
||||
'-a',
|
||||
'-r',
|
||||
'--contains'
|
||||
],
|
||||
execute: function(engine, command) {
|
||||
var commandOptions = command.getSupportedMap();
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
var args = null;
|
||||
// handle deletion first
|
||||
if (commandOptions['-d'] || commandOptions['-D']) {
|
||||
var names = commandOptions['-d'] || commandOptions['-D'];
|
||||
command.validateArgBounds(names, 1, Number.MAX_VALUE, '-d');
|
||||
|
||||
_.each(names, function(name) {
|
||||
engine.deleteBranch(name);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (commandOptions['--contains']) {
|
||||
args = commandOptions['--contains'];
|
||||
command.validateArgBounds(args, 1, 1, '--contains');
|
||||
engine.printBranchesWithout(args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (commandOptions['-f']) {
|
||||
args = commandOptions['-f'];
|
||||
command.twoArgsImpliedHead(args, '-f');
|
||||
|
||||
// we want to force a branch somewhere
|
||||
engine.forceBranch(args[0], args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (generalArgs.length === 0) {
|
||||
var branches;
|
||||
if (commandOptions['-a']) {
|
||||
branches = engine.getBranches();
|
||||
} else if (commandOptions['-r']) {
|
||||
branches = engine.getRemoteBranches();
|
||||
} else {
|
||||
branches = engine.getLocalBranches();
|
||||
}
|
||||
engine.printBranches(branches);
|
||||
return;
|
||||
}
|
||||
|
||||
command.twoArgsImpliedHead(generalArgs);
|
||||
engine.branch(generalArgs[0], generalArgs[1]);
|
||||
}
|
||||
},
|
||||
|
||||
add: {
|
||||
dontCountForGolf: true,
|
||||
sc: /^ga($|\s)/,
|
||||
regex: /^git +add($|\s)/,
|
||||
execute: function() {
|
||||
throw new CommandResult({
|
||||
msg: intl.str('git-error-staging')
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
reset: {
|
||||
regex: /^git +reset($|\s)/,
|
||||
options: [
|
||||
'--hard',
|
||||
'--soft'
|
||||
],
|
||||
execute: function(engine, command) {
|
||||
var commandOptions = command.getSupportedMap();
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
if (commandOptions['--soft']) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-staging')
|
||||
});
|
||||
}
|
||||
if (commandOptions['--hard']) {
|
||||
command.addWarning(
|
||||
intl.str('git-warning-hard')
|
||||
);
|
||||
// dont absorb the arg off of --hard
|
||||
generalArgs = generalArgs.concat(commandOptions['--hard']);
|
||||
}
|
||||
|
||||
command.validateArgBounds(generalArgs, 1, 1);
|
||||
|
||||
if (engine.getDetachedHead()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-reset-detached')
|
||||
});
|
||||
}
|
||||
|
||||
engine.reset(generalArgs[0]);
|
||||
}
|
||||
},
|
||||
|
||||
revert: {
|
||||
regex: /^git +revert($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
command.validateArgBounds(generalArgs, 1, Number.MAX_VALUE);
|
||||
engine.revert(generalArgs);
|
||||
}
|
||||
},
|
||||
|
||||
merge: {
|
||||
regex: /^git +merge($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
command.validateArgBounds(generalArgs, 1, 1);
|
||||
|
||||
var newCommit = engine.merge(generalArgs[0]);
|
||||
|
||||
if (newCommit === undefined) {
|
||||
// its just a fast forwrard
|
||||
engine.animationFactory.refreshTree(
|
||||
engine.animationQueue, engine.gitVisuals
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
engine.animationFactory.genCommitBirthAnimation(
|
||||
engine.animationQueue, newCommit, engine.gitVisuals
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
log: {
|
||||
dontCountForGolf: true,
|
||||
regex: /^git +log($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
if (generalArgs.length == 2) {
|
||||
// do fancy git log branchA ^branchB
|
||||
if (generalArgs[1][0] == '^') {
|
||||
engine.logWithout(generalArgs[0], generalArgs[1]);
|
||||
} else {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-options')
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
command.oneArgImpliedHead(generalArgs);
|
||||
engine.log(generalArgs[0]);
|
||||
}
|
||||
},
|
||||
|
||||
show: {
|
||||
dontCountForGolf: true,
|
||||
regex: /^git +show($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
command.oneArgImpliedHead(generalArgs);
|
||||
engine.show(generalArgs[0]);
|
||||
}
|
||||
},
|
||||
|
||||
rebase: {
|
||||
sc: /^gr($|\s)/,
|
||||
options: [
|
||||
'-i',
|
||||
'--aboveAll'
|
||||
],
|
||||
regex: /^git +rebase($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var commandOptions = command.getSupportedMap();
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
if (commandOptions['-i']) {
|
||||
var args = commandOptions['-i'];
|
||||
command.twoArgsImpliedHead(args, ' -i');
|
||||
engine.rebaseInteractive(
|
||||
args[0],
|
||||
args[1], {
|
||||
aboveAll: !!commandOptions['--aboveAll']
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
command.twoArgsImpliedHead(generalArgs);
|
||||
engine.rebase(generalArgs[0], generalArgs[1]);
|
||||
}
|
||||
},
|
||||
|
||||
status: {
|
||||
dontCountForGolf: true,
|
||||
sc: /^(gst|gs|git st)($|\s)/,
|
||||
regex: /^git +status($|\s)/,
|
||||
execute: function(engine) {
|
||||
// no parsing at all
|
||||
engine.status();
|
||||
}
|
||||
},
|
||||
|
||||
checkout: {
|
||||
sc: /^(go|git co)($|\s)/,
|
||||
regex: /^git +checkout($|\s)/,
|
||||
options: [
|
||||
'-b',
|
||||
'-B',
|
||||
'-'
|
||||
],
|
||||
execute: 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]));
|
||||
}
|
||||
},
|
||||
|
||||
push: {
|
||||
regex: /^git +push($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
if (!engine.hasOrigin()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-origin-required')
|
||||
});
|
||||
}
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.push();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Commands;
|
|
@ -1,13 +1,524 @@
|
|||
var _ = require('underscore');
|
||||
var intl = require('../intl');
|
||||
|
||||
var Commands = require('../commands');
|
||||
var Errors = require('../util/errors');
|
||||
var CommandProcessError = Errors.CommandProcessError;
|
||||
var GitError = Errors.GitError;
|
||||
var Warning = Errors.Warning;
|
||||
var CommandResult = Errors.CommandResult;
|
||||
|
||||
var commandConfig;
|
||||
var commands = {
|
||||
execute: function(name, engine, commandObj) {
|
||||
if (!commandConfig[name]) {
|
||||
throw new Error('i dont have a command for ' + name);
|
||||
}
|
||||
commandConfig[name].execute.call(this, engine, commandObj);
|
||||
},
|
||||
|
||||
getRegex: function(name) {
|
||||
name = name.replace(/-/g, ''); // ugh cherry-pick @____@
|
||||
if (!commandConfig[name]) {
|
||||
throw new Error('i dont have a regex for ' + name);
|
||||
}
|
||||
return commandConfig[name].regex;
|
||||
},
|
||||
|
||||
isCommandSupported: function(name) {
|
||||
return !!commandConfig[name];
|
||||
},
|
||||
|
||||
getShortcutMap: function() {
|
||||
var map = {};
|
||||
this.loop(function(config, name) {
|
||||
if (!config.sc) {
|
||||
return;
|
||||
}
|
||||
map['git ' + name] = config.sc;
|
||||
}, this);
|
||||
return map;
|
||||
},
|
||||
|
||||
getOptionMap: function() {
|
||||
var optionMap = {};
|
||||
this.loop(function(config, name) {
|
||||
var displayName = config.displayName || name;
|
||||
var thisMap = {};
|
||||
// start all options off as disabled
|
||||
_.each(config.options, function(option) {
|
||||
thisMap[option] = false;
|
||||
});
|
||||
optionMap[displayName] = thisMap;
|
||||
});
|
||||
return optionMap;
|
||||
},
|
||||
|
||||
getRegexMap: function() {
|
||||
var map = {};
|
||||
this.loop(function(config, name) {
|
||||
var displayName = 'git ' + (config.displayName || name);
|
||||
map[displayName] = config.regex;
|
||||
});
|
||||
return map;
|
||||
},
|
||||
|
||||
/**
|
||||
* which commands count for the git golf game
|
||||
*/
|
||||
getCommandsThatCount: function() {
|
||||
var counted = [];
|
||||
this.loop(function(config, name) {
|
||||
if (config.dontCountForGolf) {
|
||||
return;
|
||||
}
|
||||
counted.push(name);
|
||||
});
|
||||
return counted;
|
||||
},
|
||||
|
||||
loop: function(callback, context) {
|
||||
_.each(commandConfig, callback);
|
||||
}
|
||||
};
|
||||
|
||||
commandConfig = {
|
||||
commit: {
|
||||
sc: /^(gc|git ci)($|\s)/,
|
||||
regex: /^git +commit($|\s)/,
|
||||
options: [
|
||||
'--amend',
|
||||
'-a',
|
||||
'-am',
|
||||
'-m'
|
||||
],
|
||||
execute: 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({
|
||||
isAmend: commandOptions['--amend']
|
||||
});
|
||||
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);
|
||||
}
|
||||
},
|
||||
|
||||
cherrypick: {
|
||||
displayName: 'cherry-pick',
|
||||
regex: /^git +cherry-pick($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var commandOptions = command.getSupportedMap();
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
command.validateArgBounds(generalArgs, 1, Number.MAX_VALUE);
|
||||
|
||||
var set = engine.getUpstreamSet('HEAD');
|
||||
// first resolve all the refs (as an error check)
|
||||
var toCherrypick = _.map(generalArgs, function(arg) {
|
||||
var commit = engine.getCommitFromRef(arg);
|
||||
// and check that its not upstream
|
||||
if (set[commit.get('id')]) {
|
||||
throw new GitError({
|
||||
msg: intl.str(
|
||||
'git-error-already-exists',
|
||||
{ commit: commit.get('id') }
|
||||
)
|
||||
});
|
||||
}
|
||||
return commit;
|
||||
}, this);
|
||||
|
||||
engine.setupCherrypickChain(toCherrypick);
|
||||
}
|
||||
},
|
||||
|
||||
pull: {
|
||||
regex: /^git +pull($|\s)/,
|
||||
options: [
|
||||
'--rebase'
|
||||
],
|
||||
execute: function(engine, command) {
|
||||
if (!engine.hasOrigin()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-origin-required')
|
||||
});
|
||||
}
|
||||
|
||||
var commandOptions = command.getSupportedMap();
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.pull({
|
||||
isRebase: commandOptions['--rebase']
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
fakeTeamwork: {
|
||||
regex: /^git +fakeTeamwork($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
if (!engine.hasOrigin()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-origin-required')
|
||||
});
|
||||
}
|
||||
|
||||
command.validateArgBounds(generalArgs, 0, 2);
|
||||
// allow formats of: git Faketeamwork 2 or git Faketeamwork side 3
|
||||
var branch = (engine.origin.refs[generalArgs[0]]) ?
|
||||
generalArgs[0] : 'master';
|
||||
var numToMake = parseInt(generalArgs[0], 10) || generalArgs[1] || 1;
|
||||
|
||||
// make sure its a branch and exists
|
||||
var destBranch = engine.origin.resolveID(branch);
|
||||
if (destBranch.get('type') !== 'branch') {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-options')
|
||||
});
|
||||
}
|
||||
|
||||
engine.fakeTeamwork(numToMake, branch);
|
||||
}
|
||||
},
|
||||
|
||||
clone: {
|
||||
regex: /^git +clone *?$/,
|
||||
execute: function(engine, command) {
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.makeOrigin(engine.printTree());
|
||||
}
|
||||
},
|
||||
|
||||
fetch: {
|
||||
regex: /^git +fetch *?$/,
|
||||
execute: function(engine, command) {
|
||||
if (!engine.hasOrigin()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-origin-required')
|
||||
});
|
||||
}
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.fetch();
|
||||
}
|
||||
},
|
||||
|
||||
branch: {
|
||||
sc: /^(gb|git br)($|\s)/,
|
||||
regex: /^git +branch($|\s)/,
|
||||
options: [
|
||||
'-d',
|
||||
'-D',
|
||||
'-f',
|
||||
'-a',
|
||||
'-r',
|
||||
'--contains'
|
||||
],
|
||||
execute: function(engine, command) {
|
||||
var commandOptions = command.getSupportedMap();
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
var args = null;
|
||||
// handle deletion first
|
||||
if (commandOptions['-d'] || commandOptions['-D']) {
|
||||
var names = commandOptions['-d'] || commandOptions['-D'];
|
||||
command.validateArgBounds(names, 1, Number.MAX_VALUE, '-d');
|
||||
|
||||
_.each(names, function(name) {
|
||||
engine.deleteBranch(name);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (commandOptions['--contains']) {
|
||||
args = commandOptions['--contains'];
|
||||
command.validateArgBounds(args, 1, 1, '--contains');
|
||||
engine.printBranchesWithout(args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (commandOptions['-f']) {
|
||||
args = commandOptions['-f'];
|
||||
command.twoArgsImpliedHead(args, '-f');
|
||||
|
||||
// we want to force a branch somewhere
|
||||
engine.forceBranch(args[0], args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (generalArgs.length === 0) {
|
||||
var branches;
|
||||
if (commandOptions['-a']) {
|
||||
branches = engine.getBranches();
|
||||
} else if (commandOptions['-r']) {
|
||||
branches = engine.getRemoteBranches();
|
||||
} else {
|
||||
branches = engine.getLocalBranches();
|
||||
}
|
||||
engine.printBranches(branches);
|
||||
return;
|
||||
}
|
||||
|
||||
command.twoArgsImpliedHead(generalArgs);
|
||||
engine.branch(generalArgs[0], generalArgs[1]);
|
||||
}
|
||||
},
|
||||
|
||||
add: {
|
||||
dontCountForGolf: true,
|
||||
sc: /^ga($|\s)/,
|
||||
regex: /^git +add($|\s)/,
|
||||
execute: function() {
|
||||
throw new CommandResult({
|
||||
msg: intl.str('git-error-staging')
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
reset: {
|
||||
regex: /^git +reset($|\s)/,
|
||||
options: [
|
||||
'--hard',
|
||||
'--soft'
|
||||
],
|
||||
execute: function(engine, command) {
|
||||
var commandOptions = command.getSupportedMap();
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
if (commandOptions['--soft']) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-staging')
|
||||
});
|
||||
}
|
||||
if (commandOptions['--hard']) {
|
||||
command.addWarning(
|
||||
intl.str('git-warning-hard')
|
||||
);
|
||||
// dont absorb the arg off of --hard
|
||||
generalArgs = generalArgs.concat(commandOptions['--hard']);
|
||||
}
|
||||
|
||||
command.validateArgBounds(generalArgs, 1, 1);
|
||||
|
||||
if (engine.getDetachedHead()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-reset-detached')
|
||||
});
|
||||
}
|
||||
|
||||
engine.reset(generalArgs[0]);
|
||||
}
|
||||
},
|
||||
|
||||
revert: {
|
||||
regex: /^git +revert($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
command.validateArgBounds(generalArgs, 1, Number.MAX_VALUE);
|
||||
engine.revert(generalArgs);
|
||||
}
|
||||
},
|
||||
|
||||
merge: {
|
||||
regex: /^git +merge($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
command.validateArgBounds(generalArgs, 1, 1);
|
||||
|
||||
var newCommit = engine.merge(generalArgs[0]);
|
||||
|
||||
if (newCommit === undefined) {
|
||||
// its just a fast forwrard
|
||||
engine.animationFactory.refreshTree(
|
||||
engine.animationQueue, engine.gitVisuals
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
engine.animationFactory.genCommitBirthAnimation(
|
||||
engine.animationQueue, newCommit, engine.gitVisuals
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
log: {
|
||||
dontCountForGolf: true,
|
||||
regex: /^git +log($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
if (generalArgs.length == 2) {
|
||||
// do fancy git log branchA ^branchB
|
||||
if (generalArgs[1][0] == '^') {
|
||||
engine.logWithout(generalArgs[0], generalArgs[1]);
|
||||
} else {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-options')
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
command.oneArgImpliedHead(generalArgs);
|
||||
engine.log(generalArgs[0]);
|
||||
}
|
||||
},
|
||||
|
||||
show: {
|
||||
dontCountForGolf: true,
|
||||
regex: /^git +show($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
command.oneArgImpliedHead(generalArgs);
|
||||
engine.show(generalArgs[0]);
|
||||
}
|
||||
},
|
||||
|
||||
rebase: {
|
||||
sc: /^gr($|\s)/,
|
||||
options: [
|
||||
'-i',
|
||||
'--aboveAll'
|
||||
],
|
||||
regex: /^git +rebase($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
var commandOptions = command.getSupportedMap();
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
|
||||
if (commandOptions['-i']) {
|
||||
var args = commandOptions['-i'];
|
||||
command.twoArgsImpliedHead(args, ' -i');
|
||||
engine.rebaseInteractive(
|
||||
args[0],
|
||||
args[1], {
|
||||
aboveAll: !!commandOptions['--aboveAll']
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
command.twoArgsImpliedHead(generalArgs);
|
||||
engine.rebase(generalArgs[0], generalArgs[1]);
|
||||
}
|
||||
},
|
||||
|
||||
status: {
|
||||
dontCountForGolf: true,
|
||||
sc: /^(gst|gs|git st)($|\s)/,
|
||||
regex: /^git +status($|\s)/,
|
||||
execute: function(engine) {
|
||||
// no parsing at all
|
||||
engine.status();
|
||||
}
|
||||
},
|
||||
|
||||
checkout: {
|
||||
sc: /^(go|git co)($|\s)/,
|
||||
regex: /^git +checkout($|\s)/,
|
||||
options: [
|
||||
'-b',
|
||||
'-B',
|
||||
'-'
|
||||
],
|
||||
execute: 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]));
|
||||
}
|
||||
},
|
||||
|
||||
push: {
|
||||
regex: /^git +push($|\s)/,
|
||||
execute: function(engine, command) {
|
||||
if (!engine.hasOrigin()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-origin-required')
|
||||
});
|
||||
}
|
||||
command.acceptNoGeneralArgs();
|
||||
engine.push();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var instantCommands = [
|
||||
[/^(git help($|\s)|git$)/, function() {
|
||||
var lines = [
|
||||
|
@ -19,7 +530,7 @@ var instantCommands = [
|
|||
intl.str('git-supported-commands'),
|
||||
'<br/>'
|
||||
];
|
||||
var commands = Commands.getOptionMap();
|
||||
var commands = commands.getOptionMap();
|
||||
// build up a nice display of what we support
|
||||
_.each(commands, function(commandOptions, command) {
|
||||
lines.push('git ' + command);
|
||||
|
@ -42,7 +553,7 @@ var parse = function(str) {
|
|||
var options;
|
||||
|
||||
// see if we support this particular command
|
||||
_.each(Commands.getRegexMap(), function(regex, thisMethod) {
|
||||
_.each(commands.getRegexMap(), function(regex, thisMethod) {
|
||||
if (regex.exec(str)) {
|
||||
options = str.slice(thisMethod.length + 1);
|
||||
method = thisMethod.slice('git '.length);
|
||||
|
@ -74,7 +585,7 @@ function CommandOptionParser(method, options) {
|
|||
this.method = method;
|
||||
this.rawOptions = options;
|
||||
|
||||
this.supportedMap = Commands.getOptionMap()[method];
|
||||
this.supportedMap = commands.getOptionMap()[method];
|
||||
if (this.supportedMap === undefined) {
|
||||
throw new Error('No option map for ' + method);
|
||||
}
|
||||
|
@ -84,7 +595,7 @@ function CommandOptionParser(method, options) {
|
|||
}
|
||||
|
||||
var optionMap = {};
|
||||
Commands.loop(function(config, name) {
|
||||
commands.loop(function(config, name) {
|
||||
var displayName = config.displayName || name;
|
||||
if (optionMap[displayName] !== undefined) {
|
||||
return;
|
||||
|
@ -133,6 +644,7 @@ CommandOptionParser.prototype.explodeAndSet = function() {
|
|||
}
|
||||
};
|
||||
|
||||
exports.commands = commands;
|
||||
exports.instantCommands = instantCommands;
|
||||
exports.parse = parse;
|
||||
|
||||
|
|
|
@ -10,11 +10,11 @@ var AnimationQueue = require('../visuals/animation').AnimationQueue;
|
|||
var TreeCompare = require('./treeCompare').TreeCompare;
|
||||
|
||||
var Errors = require('../util/errors');
|
||||
var GitCommands = require('../git/commands');
|
||||
var GitError = Errors.GitError;
|
||||
var CommandResult = Errors.CommandResult;
|
||||
var EventBaton = require('../util/eventBaton').EventBaton;
|
||||
|
||||
var Commands = require('../commands');
|
||||
|
||||
function GitEngine(options) {
|
||||
this.rootCommit = null;
|
||||
|
@ -1734,7 +1734,7 @@ GitEngine.prototype.dispatch = function(command, deferred) {
|
|||
|
||||
try {
|
||||
var methodName = command.get('method').replace(/-/g, '');
|
||||
Commands.execute(methodName, this, this.command);
|
||||
GitCommands.commands.execute(methodName, this, this.command);
|
||||
} catch (err) {
|
||||
this.filterError(err);
|
||||
// short circuit animation by just setting error and returning
|
||||
|
|
|
@ -2,7 +2,6 @@ var _ = require('underscore');
|
|||
var intl = require('../intl');
|
||||
|
||||
var GitCommands = require('../git/commands');
|
||||
var Commands = require('../commands');
|
||||
|
||||
var Errors = require('../util/errors');
|
||||
var GitError = Errors.GitError;
|
||||
|
@ -27,7 +26,7 @@ DisabledMap.prototype.getInstantCommands = function() {
|
|||
};
|
||||
|
||||
_.each(this.disabledMap, function(val, disabledCommand) {
|
||||
var gitRegex = Commands.getRegexMap()[disabledCommand];
|
||||
var gitRegex = GitCommands.commands.getRegexMap()[disabledCommand];
|
||||
if (!gitRegex) {
|
||||
throw new Error('wuttttt this disbaled command' + disabledCommand +
|
||||
' has no regex matching');
|
||||
|
|
|
@ -10,7 +10,6 @@ var log = require('../log');
|
|||
var Errors = require('../util/errors');
|
||||
var Sandbox = require('../level/sandbox').Sandbox;
|
||||
var Constants = require('../util/constants');
|
||||
var Commands = require('../commands');
|
||||
|
||||
var Visualization = require('../visuals/visualization').Visualization;
|
||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||
|
@ -310,8 +309,8 @@ var Level = Sandbox.extend({
|
|||
}
|
||||
|
||||
var matched = false;
|
||||
_.each(Commands.getCommandsThatCount(), function(name) {
|
||||
var regex = Commands.getRegex(name);
|
||||
_.each(GitCommands.commands.getCommandsThatCount(), function(name) {
|
||||
var regex = GitCommands.commands.getRegex(name);
|
||||
matched = matched || regex.test(command.get('rawStr'));
|
||||
});
|
||||
if (matched) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
var _ = require('underscore');
|
||||
|
||||
var GitCommands = require('../git/commands');
|
||||
var Commands = require('../commands');
|
||||
var SandboxCommands = require('../level/sandboxCommands');
|
||||
|
||||
// more or less a static class
|
||||
|
@ -9,7 +8,7 @@ var ParseWaterfall = function(options) {
|
|||
options = options || {};
|
||||
this.options = options;
|
||||
this.shortcutWaterfall = options.shortcutWaterfall || [
|
||||
Commands.getShortcutMap()
|
||||
GitCommands.commands.getShortcutMap()
|
||||
];
|
||||
|
||||
this.instantWaterfall = options.instantWaterfall || [
|
||||
|
|
|
@ -4,7 +4,7 @@ var util = require('../util');
|
|||
var constants = require('../util/constants');
|
||||
var intl = require('../intl');
|
||||
|
||||
var Commands = require('../commands');
|
||||
var GitCommands = require('../git/commands');
|
||||
var Errors = require('../util/errors');
|
||||
var CommandProcessError = Errors.CommandProcessError;
|
||||
var GitError = Errors.GitError;
|
||||
|
@ -121,7 +121,7 @@ var getAllCommands = function() {
|
|||
|
||||
var allCommands = _.extend(
|
||||
{},
|
||||
require('../commands').getRegexMap(),
|
||||
GitCommands.commands.getRegexMap(),
|
||||
require('../level').regexMap,
|
||||
regexMap
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue