diff --git a/spec/create.js b/spec/create.js index 827af467..4e9fa7d0 100644 --- a/spec/create.js +++ b/spec/create.js @@ -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(); diff --git a/spec/remote.spec.js b/spec/remote.spec.js index 35eac439..5ce78013 100644 --- a/spec/remote.spec.js +++ b/spec/remote.spec.js @@ -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"}}}' + ); + }); + }); diff --git a/src/js/git/commands.js b/src/js/git/commands.js index 36f1efa1..fd2b8b9f 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -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); diff --git a/src/js/git/index.js b/src/js/git/index.js index 3874eac6..770a1b37 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -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();