awesome nailed down the actual args and stuff

This commit is contained in:
Peter Cottle 2013-10-15 17:25:55 -07:00
parent bf48e54bbe
commit e99b6d7c61
4 changed files with 49 additions and 15 deletions

View file

@ -52,7 +52,7 @@ var expectTreeAsync = function(command, expectedJSON) {
}); });
waitsFor(function() { waitsFor(function() {
var diff = (Date.now() - start); var diff = (Date.now() - start);
if (diff > TIME - 50 && !haveReported) { if (diff > TIME - 20 && !haveReported) {
haveReported = true; haveReported = true;
console.log('not going to match', command); console.log('not going to match', command);
console.log('expected\n>>>>>>>>\n', loadTree(expectedJSON)); console.log('expected\n>>>>>>>>\n', loadTree(expectedJSON));

View file

@ -9,7 +9,10 @@ prompt.get(['command'], function(err, result) {
var headless = new HeadlessGit(); var headless = new HeadlessGit();
headless.sendCommand(result.command); headless.sendCommand(result.command);
setTimeout(function() { setTimeout(function() {
console.log(headless.gitEngine.printTree()); console.log('expectTreeAsync(');
console.log(" \t'" + result.command + "',");
console.log(" \t'" + headless.gitEngine.printTree() + "'");
console.log(');');
}, 100); }, 100);
}); });

View file

@ -109,7 +109,7 @@ describe('Git Remotes', function() {
it('pushes to another remote', function() { it('pushes to another remote', function() {
expectTreeAsync( expectTreeAsync(
'git branch side; git clone;git commit; git push origin side', 'git branch side; git clone;git commit; git push origin HEAD:side',
'{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":"o/master"},"side":{"target":"C1","id":"side","remoteTrackingBranchID":"o/side"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null,"localBranchesThatTrackThis":["master"]},"o/side":{"target":"C2","id":"o/side","remoteTrackingBranchID":null,"localBranchesThatTrackThis":["side"]}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":null},"side":{"target":"C2","id":"side","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}}' '{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":"o/master"},"side":{"target":"C1","id":"side","remoteTrackingBranchID":"o/side"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null,"localBranchesThatTrackThis":["master"]},"o/side":{"target":"C2","id":"o/side","remoteTrackingBranchID":null,"localBranchesThatTrackThis":["side"]}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":null},"side":{"target":"C2","id":"side","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}}'
); );
}); });
@ -117,7 +117,7 @@ describe('Git Remotes', function() {
it('pushes to tracking remote', function() { it('pushes to tracking remote', function() {
expectTreeAsync( expectTreeAsync(
'git branch side; git clone;git commit;git push; go side; git commit; git push', 'git branch side; git clone;git commit;git push; go side; git commit; git push',
'{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":"o/master"},"side":{"target":"C3","id":"side","remoteTrackingBranchID":"o/side"},"o/master":{"target":"C2","id":"o/master","remoteTrackingBranchID":null,"localBranchesThatTrackThis":["master"]},"o/side":{"target":"C3","id":"o/side","remoteTrackingBranchID":null,"localBranchesThatTrackThis":["side"]}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C1"],"id":"C3"}},"HEAD":{"target":"side","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":null},"side":{"target":"C3","id":"side","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C1"],"id":"C3"}},"HEAD":{"target":"master","id":"HEAD"}}}' '{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":"o/master"},"side":{"target":"C3","id":"side","remoteTrackingBranchID":"o/side"},"o/master":{"target":"C2","id":"o/master","remoteTrackingBranchID":null},"o/side":{"target":"C3","id":"o/side","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C1"],"id":"C3"}},"HEAD":{"target":"side","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":null},"side":{"target":"C3","id":"side","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C1"],"id":"C3"}},"HEAD":{"target":"master","id":"HEAD"}}}'
); );
}); });
@ -151,7 +151,7 @@ describe('Git Remotes', function() {
it('pushes new branch onto server', function() { it('pushes new branch onto server', function() {
expectTreeAsync( expectTreeAsync(
'git clone; git commit; git push origin foo', 'git clone; git commit; git push origin master:foo',
'{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null},"o/foo":{"target":"C2","id":"o/foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":null},"foo":{"target":"C2","id":"foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}}' '{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null},"o/foo":{"target":"C2","id":"o/foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":null},"foo":{"target":"C2","id":"foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}}'
); );
}); });
@ -184,5 +184,26 @@ describe('Git Remotes', function() {
); );
}); });
it('will not push to a remote if the local ref does not exist', function() {
expectTreeAsync(
'git clone; git push origin foo',
'{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"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"}},"HEAD":{"target":"master","id":"HEAD"}}}'
);
});
it('will push to the remote branch IF IT has tracking', function() {
expectTreeAsync(
'git clone; git checkout -b foo o/master; git commit; git push',
'{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C2","id":"o/master","remoteTrackingBranchID":null},"foo":{"target":"C2","id":"foo","remoteTrackingBranchID":"o/master"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"foo","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}}'
);
});
it('will push to a new remote branch if no tracking is set up', function() {
expectTreeAsync(
'git clone; git checkout -b foo; git commit; git push',
'{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null},"foo":{"target":"C2","id":"foo","remoteTrackingBranchID":"o/foo"},"o/foo":{"target":"C2","id":"o/foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"foo","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C1","id":"master","remoteTrackingBranchID":null},"foo":{"target":"C2","id":"foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}}'
);
});
}); });

View file

@ -19,7 +19,7 @@ var assertIsRef = function(engine, ref) {
engine.resolveID(ref); // will throw giterror if cant resolve engine.resolveID(ref); // will throw giterror if cant resolve
}; };
var validateAndAssertBranchName = function(engine, name) { var validateBranchName = function(engine, name) {
return engine.validateBranchName(name); return engine.validateBranchName(name);
}; };
@ -576,19 +576,29 @@ var commandConfig = {
if (isColonRefspec(firstArg)) { if (isColonRefspec(firstArg)) {
var refspecParts = firstArg.split(':'); var refspecParts = firstArg.split(':');
source = refspecParts[0]; source = refspecParts[0];
destination = validateAndAssertBranchName(engine, refspecParts[1]); destination = validateBranchName(engine, refspecParts[1]);
} else { } else {
// we are using this arg as destination -- source is one before head // we are using this arg as destination AND source. the dest branch
destination = firstArg; // can be created on demand but we at least need this to be a source
source = engine.getOneBeforeCommit('HEAD').get('id'); // locally otherwise we will fail
source = destination = firstArg;
} }
} else { } else {
// since they have not specified a source or destination, then // since they have not specified a source or destination, then
// we source from the branch we are on (or HEAD) and push to // we source from the branch we are on (or HEAD)
// the branch we are on var sourceObj = engine.getOneBeforeCommit('HEAD');
source = engine.getOneBeforeCommit('HEAD').get('id'); source = sourceObj.get('id');
destination = source;
assertBranchIsRemoteTracking(engine, source); // HOWEVER we push to either the remote tracking branch we have
// OR a new named branch if we aren't tracking anything
if (sourceObj.getRemoteTrackingBranchID &&
sourceObj.getRemoteTrackingBranchID()) {
assertBranchIsRemoteTracking(engine, source);
var remoteBranch = sourceObj.getRemoteTrackingBranchID();
destination = engine.refs[remoteBranch].getBaseID();
} else {
destination = validateBranchName(engine, source);
}
} }
if (source) { if (source) {
assertIsRef(engine, source); assertIsRef(engine, source);