diff --git a/src/js/git/commands.js b/src/js/git/commands.js index 2e5c8dad..0b6da0f3 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -22,6 +22,14 @@ var assertIsRef = function(engine, ref) { engine.resolveID(ref); // will throw git error if can't resolve }; +var assertRefNoModifiers = function(ref) { + if (/~|\^/.test(ref)) { + throw new GitError({ + msg: intl.str('git-error-exist', {ref: ref}) + }); + } +} + var validateBranchName = function(engine, name) { return engine.validateBranchName(name); }; @@ -255,6 +263,7 @@ var commandConfig = { if (firstArg && isColonRefspec(firstArg)) { var refspecParts = firstArg.split(':'); source = refspecParts[0]; + assertRefNoModifiers(source); destination = validateBranchNameIfNeeded( engine, crappyUnescape(refspecParts[1]) @@ -264,7 +273,6 @@ var commandConfig = { source = firstArg; assertIsBranch(engine.origin, source); // get o/main locally if main is specified - destination = engine.origin.resolveID(source).getPrefixedID(); } else { // can't be detached if (engine.getDetachedHead()) { @@ -277,8 +285,7 @@ var commandConfig = { var branch = engine.getOneBeforeCommit('HEAD'); var branchName = branch.get('id'); assertBranchIsRemoteTracking(engine, branchName); - destination = branch.getRemoteTrackingBranchID(); - source = destination.replace(ORIGIN_PREFIX, ''); + source = branch.getRemoteTrackingBranchID().replace(ORIGIN_PREFIX, ''); } engine.pull({ @@ -392,6 +399,7 @@ var commandConfig = { if (firstArg && isColonRefspec(firstArg)) { var refspecParts = firstArg.split(':'); source = refspecParts[0]; + assertRefNoModifiers(source); destination = validateBranchNameIfNeeded( engine, crappyUnescape(refspecParts[1]) @@ -405,7 +413,6 @@ var commandConfig = { source = firstArg; assertIsBranch(engine.origin, source); // get o/main locally if main is specified - destination = engine.origin.resolveID(source).getPrefixedID(); } 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 b8fbafea..1e517c56 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -397,11 +397,8 @@ GitEngine.prototype.makeBranchIfNeeded = function(branchName) { if (this.doesRefExist(branchName)) { return; } - var where = this.findCommonAncestorForRemote( - this.getCommitFromRef('HEAD').get('id') - ); - return this.validateAndMakeBranch(branchName, this.getCommitFromRef(where)); + return this.validateAndMakeBranch(branchName, this.rootCommit); }; GitEngine.prototype.makeRemoteBranchForRemote = function(branchName) { @@ -1241,17 +1238,26 @@ GitEngine.prototype.fetch = function(options) { this.getCommitFromRef('HEAD') ); return; - } else if (options.destination && options.source) { + } else if (options.source) { + var sourceDestPairs = []; didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(options.source); - didMakeBranch = didMakeBranch || this.makeBranchIfNeeded(options.destination); - options.didMakeBranch = didMakeBranch; - - return this.fetchCore([{ + var source = this.origin.resolveID(options.source); + if (source.get('type') == 'branch') { + sourceDestPairs.push({ + destination: this.origin.resolveID(options.source).getPrefixedID(), + source: options.source + }); + } + if (options.destination) { + didMakeBranch = didMakeBranch || this.makeBranchIfNeeded(options.destination); + sourceDestPairs.push({ destination: options.destination, source: options.source - }], - options - ); + }); + } + options.didMakeBranch = didMakeBranch; + options.dontThrowOnNoFetch = options.dontThrowOnNoFetch || didMakeBranch; + return this.fetchCore(sourceDestPairs, options); } // get all remote branches and specify the dest / source pairs var allBranchesOnRemote = this.origin.branchCollection.toArray(); @@ -1409,7 +1415,7 @@ GitEngine.prototype.pull = function(options) { return; } - var destBranch = this.resolveID(options.destination); + var destBranch = this.resolveID(options.destination || this.origin.resolveID(options.source).getPrefixedID()); // then either rebase or merge if (options.isRebase) { this.pullFinishWithRebase(pendingFetch, localBranch, destBranch);