yay command option parsing makes more sense

This commit is contained in:
Peter Cottle 2013-11-18 10:22:53 -08:00
parent 6d58c928ae
commit 1ba46f7705
3 changed files with 19 additions and 19 deletions

View file

@ -339,5 +339,12 @@ describe('Git Remotes', function() {
);
});
it('tracks remote with -u', function() {
expectTreeAsync(
'git clone; git branch foo; git branch -u o/master foo',
'{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null},"foo":{"target":"C1","id":"foo","remoteTrackingBranchID":"o/master"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"tags":{},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"tags":{},"HEAD":{"target":"master","id":"HEAD"}}}'
);
});
});

View file

@ -187,16 +187,14 @@ CommandOptionParser.prototype.explodeAndSet = function() {
});
}
// go through and include all the next args until we hit another option or the end
var next = exploded[i + 1];
var optionArgs = [];
var next = i + 1;
while (next < exploded.length && exploded[next].slice(0,1) != '-') {
optionArgs.push(exploded[next]);
next += 1;
if (next && next.slice(0,1) !== '-') {
// only store the next argument as this
// option value if its not another option
i++;
optionArgs = [next];
}
i = next - 1;
// **phew** we are done grabbing those. theseArgs is truthy even with an empty array
this.supportedMap[part] = optionArgs;
} else {
// must be a general arg

View file

@ -387,6 +387,7 @@ var commandConfig = {
// handle deletion first
if (commandOptions['-d'] || commandOptions['-D']) {
var names = commandOptions['-d'] || commandOptions['-D'];
names = names.concat(generalArgs);
command.validateArgBounds(names, 1, Number.MAX_VALUE, '-d');
_.each(names, function(name) {
@ -396,8 +397,7 @@ var commandConfig = {
}
if (commandOptions['-u']) {
command.acceptNoGeneralArgs();
args = commandOptions['-u'];
args = commandOptions['-u'].concat(generalArgs);
command.validateArgBounds(args, 1, 2, '-u');
var remoteBranch = crappyUnescape(args[0]);
var branch = args[1] || engine.getOneBeforeCommit('HEAD').get('id');
@ -420,7 +420,7 @@ var commandConfig = {
}
if (commandOptions['-f']) {
args = commandOptions['-f'];
args = commandOptions['-f'].concat(generalArgs);
command.twoArgsImpliedHead(args, '-f');
// we want to force a branch somewhere
@ -620,14 +620,9 @@ var commandConfig = {
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'];
// the user is really trying to just make a
// branch and then switch to it. so first:
args = commandOptions['-b'].concat(generalArgs);
command.twoArgsImpliedHead(args, '-b');
var validId = engine.validateBranchName(args[0]);