fetch fixes

This commit is contained in:
Peter Cottle 2013-10-26 12:04:33 -07:00
parent 67d2352fa2
commit db14af2fa7

View file

@ -381,6 +381,12 @@ GitEngine.prototype.makeRemoteBranchIfNeeded = function(branchName) {
if (this.refs[ORIGIN_PREFIX + branchName]) { if (this.refs[ORIGIN_PREFIX + branchName]) {
return; return;
} }
// if its not a branch on origin then bounce
var source = this.origin.resolveID(branchName);
if (source.get('type') !== 'branch') {
return;
}
return this.makeRemoteBranchForRemote(branchName); return this.makeRemoteBranchForRemote(branchName);
}; };
@ -388,6 +394,7 @@ GitEngine.prototype.makeBranchIfNeeded = function(branchName) {
if (this.refs[branchName]) { if (this.refs[branchName]) {
return; return;
} }
return this.validateAndMakeBranch(branchName, this.getCommitFromRef('HEAD')); return this.validateAndMakeBranch(branchName, this.getCommitFromRef('HEAD'));
}; };
@ -913,7 +920,6 @@ GitEngine.prototype.descendSortDepth = function(objects) {
GitEngine.prototype.push = function(options) { GitEngine.prototype.push = function(options) {
options = options || {}; options = options || {};
var didMakeBranch;
if (options.source === "") { if (options.source === "") {
// delete case // delete case
@ -926,11 +932,15 @@ GitEngine.prototype.push = function(options) {
var sourceBranch = this.refs[options.source]; var sourceBranch = this.refs[options.source];
if (!this.origin.refs[options.destination]) { if (!this.origin.refs[options.destination]) {
didMakeBranch = true;
this.makeBranchOnOriginAndTrack( this.makeBranchOnOriginAndTrack(
options.destination, options.destination,
'HEAD' 'HEAD'
); );
// play an animation now since we might not have to fast forward
// anything... this is weird because we are punting an animation
// and not resolving the promise but whatever
this.animationFactory.playRefreshAnimation(this.origin.gitVisuals);
this.animationFactory.playRefreshAnimation(this.gitVisuals);
} }
var branchOnRemote = this.origin.refs[options.destination]; var branchOnRemote = this.origin.refs[options.destination];
var sourceLocation = this.resolveID(options.source || 'HEAD'); var sourceLocation = this.resolveID(options.source || 'HEAD');
@ -980,14 +990,6 @@ GitEngine.prototype.push = function(options) {
var deferred = Q.defer(); var deferred = Q.defer();
var chain = deferred.promise; var chain = deferred.promise;
if (didMakeBranch) {
chain = chain.then(_.bind(function() {
// play something for both
this.animationFactory.playRefreshAnimation(this.origin.gitVisuals);
return this.animationFactory.playRefreshAnimation(this.gitVisuals);
}, this));
}
_.each(commitsToMake, function(commitJSON) { _.each(commitsToMake, function(commitJSON) {
chain = chain.then(_.bind(function() { chain = chain.then(_.bind(function() {
return this.animationFactory.playHighlightPromiseAnimation( return this.animationFactory.playHighlightPromiseAnimation(
@ -1054,6 +1056,7 @@ GitEngine.prototype.pushDeleteRemoteBranch = function(
GitEngine.prototype.fetch = function(options) { GitEngine.prototype.fetch = function(options) {
options = options || {}; options = options || {};
var didMakeBranch;
// first check for super stupid case where we are just making // first check for super stupid case where we are just making
// a branch with fetch... // a branch with fetch...
@ -1064,8 +1067,9 @@ GitEngine.prototype.fetch = function(options) {
); );
return; return;
} else if (options.destination && options.source) { } else if (options.destination && options.source) {
this.makeRemoteBranchIfNeeded(options.source); didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(options.source);
this.makeBranchIfNeeded(options.destination); didMakeBranch = didMakeBranch || this.makeBranchIfNeeded(options.destination);
options.didMakeBranch = didMakeBranch;
return this.fetchCore([{ return this.fetchCore([{
destination: options.destination, destination: options.destination,
@ -1078,13 +1082,14 @@ GitEngine.prototype.fetch = function(options) {
var allBranchesOnRemote = this.origin.branchCollection.toArray(); var allBranchesOnRemote = this.origin.branchCollection.toArray();
var sourceDestPairs = _.map(allBranchesOnRemote, function(branch) { var sourceDestPairs = _.map(allBranchesOnRemote, function(branch) {
var branchName = branch.get('id'); var branchName = branch.get('id');
this.makeRemoteBranchIfNeeded(branchName); didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(branchName);
return { return {
destination: branch.getPrefixedID(), destination: branch.getPrefixedID(),
source: branchName source: branchName
}; };
}, this); }, this);
options.didMakeBranch = didMakeBranch;
return this.fetchCore(sourceDestPairs, options); return this.fetchCore(sourceDestPairs, options);
}; };
@ -1162,6 +1167,12 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
var deferred = Q.defer(); var deferred = Q.defer();
var chain = deferred.promise; var chain = deferred.promise;
if (options.didMakeBranch) {
chain = chain.then(_.bind(function() {
this.animationFactory.playRefreshAnimation(this.origin.gitVisuals);
return this.animationFactory.playRefreshAnimation(this.gitVisuals);
}, this));
}
var originBranchSet = this.origin.getUpstreamBranchSet(); var originBranchSet = this.origin.getUpstreamBranchSet();
_.each(commitsToMake, function(commitJSON) { _.each(commitsToMake, function(commitJSON) {
@ -1189,8 +1200,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
// update all the destinations // update all the destinations
_.each(sourceDestPairs, function(pair) { _.each(sourceDestPairs, function(pair) {
var ours = this.refs[pair.destination]; var ours = this.refs[pair.destination];
var theirs = this.origin.refs[pair.source]; var theirCommitID = this.origin.getCommitFromRef(pair.source).get('id');
var theirCommitID = theirs.get('target').get('id');
// by definition we just made the commit with this id, // by definition we just made the commit with this id,
// so we can grab it now // so we can grab it now
var localCommit = this.refs[theirCommitID]; var localCommit = this.refs[theirCommitID];