awesome have part of git push working

This commit is contained in:
Peter Cottle 2013-06-11 09:28:14 -07:00
parent 84f180e6a8
commit c7da989845
8 changed files with 336 additions and 42 deletions

View file

@ -730,21 +730,12 @@ GitEngine.prototype.cherrypickStarter = function() {
* Origin stuff!
************************************/
GitEngine.prototype.fetchStarter = function() {
if (!this.hasOrigin()) {
throw new GitError({
msg: intl.str('git-error-origin-required')
});
}
this.acceptNoGeneralArgs();
this.fetch();
};
GitEngine.prototype.checkUpstreamOfSource = function(
target,
source,
targetBranch,
sourceBranch
sourceBranch,
errorMsg
) {
// here we are downloading some X number of commits from source onto
// target. Hence target should be strictly upstream of source
@ -755,7 +746,7 @@ GitEngine.prototype.checkUpstreamOfSource = function(
var targetLocationID = target.getCommitFromRef(targetBranch).get('id');
if (!upstream[targetLocationID]) {
throw new GitError({
msg: intl.str('git-error-origin-fetch-no-ff')
msg: errorMsg || intl.str('git-error-origin-fetch-no-ff')
});
}
};
@ -774,7 +765,7 @@ GitEngine.prototype.getTargetGraphDifference = function(
var sourceTree = source.exportTree();
var sourceStartCommitJSON = sourceTree.commits[sourceStartCommit.get('id')];
if (this.refs[sourceStartCommitJSON.id]) {
if (target.refs[sourceStartCommitJSON.id]) {
throw new GitError({
msg: intl.str('git-error-origin-fetch-uptodate')
});
@ -809,6 +800,107 @@ GitEngine.prototype.getTargetGraphDifference = function(
});
};
GitEngine.prototype.pushStarter = function(options) {
if (!this.hasOrigin()) {
throw new GitError({
msg: intl.str('git-error-origin-required')
});
}
this.acceptNoGeneralArgs();
this.push();
};
GitEngine.prototype.push = function(options) {
options = options || {};
var localBranch = this.refs['master'];
var remoteBranch = this.origin.refs['master'];
// first check if this is even allowed by checking the sync between
this.checkUpstreamOfSource(
this,
this.origin,
remoteBranch,
localBranch,
intl.str('git-error-origin-push-no-ff')
);
var commitsToMake = this.getTargetGraphDifference(
this.origin,
this,
remoteBranch,
localBranch
);
var makeCommit = _.bind(function(id, parentIDs) {
// need to get the parents first. since we order by depth, we know
// the dependencies are there already
var parents = _.map(parentIDs, function(parentID) {
return this.origin.refs[parentID];
}, this);
return this.origin.makeCommit(parents, id);
}, this);
// now make the promise chain to make each commit
var chainStep = _.bind(function(id, parents) {
var newCommit = makeCommit(id, parents);
return AnimationFactory.playCommitBirthPromiseAnimation(
newCommit,
this.origin.gitVisuals
);
}, this);
var deferred = Q.defer();
var chain = deferred.promise;
_.each(commitsToMake, function(commitJSON) {
chain = chain.then(_.bind(function() {
return AnimationFactory.playHighlightPromiseAnimation(
this.refs[commitJSON.id],
remoteBranch
);
}, this));
chain = chain.then(function() {
return chainStep(
commitJSON.id,
commitJSON.parents
);
});
}, this);
chain = chain.then(_.bind(function() {
var localLocationID = localBranch.get('target').get('id');
var remoteCommit = this.origin.refs[localLocationID];
this.origin.setTargetLocation(remoteBranch, remoteCommit);
// unhighlight local
AnimationFactory.playRefreshAnimation(this.gitVisuals);
return AnimationFactory.playRefreshAnimation(this.origin.gitVisuals);
}, this));
// HAX HAX update o/master
chain = chain.then(_.bind(function() {
var localLocationID = localBranch.get('target').get('id');
var localCommit = this.refs[localLocationID];
// HAX HAX
this.setTargetLocation(this.refs['o/master'], localCommit);
return AnimationFactory.playRefreshAnimation(this.gitVisuals);
}, this));
if (!options.dontResolvePromise) {
this.animationQueue.thenFinish(chain, deferred);
}
};
GitEngine.prototype.fetchStarter = function() {
if (!this.hasOrigin()) {
throw new GitError({
msg: intl.str('git-error-origin-required')
});
}
this.acceptNoGeneralArgs();
this.fetch();
};
GitEngine.prototype.fetch = function(options) {
options = options || {};
var localBranch = this.refs['o/master'];