diff --git a/spec/remote.spec.js b/spec/remote.spec.js index ce670389..101707cf 100644 --- a/spec/remote.spec.js +++ b/spec/remote.spec.js @@ -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"}}}' + ); + }); + }); diff --git a/src/js/commands/index.js b/src/js/commands/index.js index 41ddefeb..fbe26316 100644 --- a/src/js/commands/index.js +++ b/src/js/commands/index.js @@ -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 diff --git a/src/js/git/commands.js b/src/js/git/commands.js index 1a6b9ad2..911b1ab8 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -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]);