BOOM all tests pass, more progress on git fetch

This commit is contained in:
Peter Cottle 2013-10-17 19:49:17 -07:00
parent b9ebaca62b
commit f11f76bbe8
4 changed files with 20 additions and 8 deletions

View file

@ -1,7 +1,7 @@
var TreeCompare = require('../src/js/git/treeCompare').TreeCompare;
var HeadlessGit = require('../src/js/git/headless').HeadlessGit;
var prompt = require('prompt');
prompt = require('prompt');
prompt.start();

View file

@ -226,5 +226,19 @@ describe('Git Remotes', function() {
);
});
it('validates branch names when fetching', function() {
expectTreeAsync(
'git clone; git fakeTeamwork; git fetch master:HEAD; git fetch master:f<>',
'{"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":"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('fetches only one remote if specified', function() {
expectTreeAsync(
'git clone;gc;git push origin master:banana;git fakeTeamwork banana;git fakeTeamwork master;git fetch origin banana',
'{"branches":{"master":{"target":"C2","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C1","id":"o/master","remoteTrackingBranchID":null},"o/banana":{"target":"C3","id":"o/banana","remoteTrackingBranchID":null},"banana":{"target":"C2","id":"banana","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C2"],"id":"C3"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C4","id":"master","remoteTrackingBranchID":null},"banana":{"target":"C3","id":"banana","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C2"],"id":"C3"},"C4":{"parents":["C1"],"id":"C4"}},"HEAD":{"target":"master","id":"HEAD"}}}'
);
});
});

View file

@ -270,8 +270,6 @@ var commandConfig = {
var refspecParts = firstArg.split(':');
source = refspecParts[0];
destination = validateBranchName(engine, refspecParts[1]);
// destination will be created by fetch, but check source
} else if (firstArg) {
// here is the deal -- its JUST like git push. the first arg
// is used as both the destination and the source, so we need
@ -279,8 +277,6 @@ var commandConfig = {
// the destination will be created locally
source = firstArg;
destination = firstArg;
//var tracking = assertBranchIsRemoteTracking(engine, firstArg);
//options.branches = [engine.refs[tracking]];
}
if (source) { // empty string fails this check
assertIsRef(engine.origin, source);

View file

@ -374,7 +374,7 @@ GitEngine.prototype.makeOrigin = function(treeString) {
GitEngine.prototype.makeRemoteBranchForRemote = function(branchName) {
var target = this.origin.refs[branchName].get('target');
var originTarget = this.findCommonAncestorWithRemote(
target.get('id');
target.get('id')
);
return this.makeBranch(
ORIGIN_PREFIX + branchName,
@ -1037,7 +1037,7 @@ GitEngine.prototype.fetch = function(options) {
// ok this is just like git push -- if the destination does not exist,
// we need to make it
if (options.destination) {
if (options.destination && !this.refs[options.destination]) {
// its just like creating a branch, we will merge (if pulling) later
this.validateAndMakeBranch(
options.destination,
@ -1051,9 +1051,11 @@ GitEngine.prototype.fetch = function(options) {
if (options.source) {
// gah -- first we have to check that we even have a remote branch
// for this source (we know its on the remote based on validation)
if (!this.refs[ORIGIN_PREFX + options.source]) {
if (!this.refs[ORIGIN_PREFIX + options.source]) {
this.makeRemoteBranchForRemote(options.source);
}
// now just specify branches to fetch based on this source
branchesToFetch = [this.refs[ORIGIN_PREFIX + options.source]];
} else {
branchesToFetch = this.branchCollection.filter(function(branch) {
return branch.getIsRemote();