yay got multiple remotes fetching working

This commit is contained in:
Peter Cottle 2013-10-06 18:09:38 -07:00
parent a16204fea3
commit 9fa8c1383d
8 changed files with 203 additions and 27 deletions

View file

@ -7,6 +7,10 @@ var GitError = Errors.GitError;
var Warning = Errors.Warning;
var CommandResult = Errors.CommandResult;
var crappyUnescape = function(str) {
return str.replace(/'/g, "'").replace(///g, "/");
};
var commandConfig = {
commit: {
sc: /^(gc|git ci)($|\s)/,
@ -171,21 +175,50 @@ var commandConfig = {
},
fetch: {
regex: /^git +fetch *?$/,
regex: /^git +fetch($|\s)/,
execute: function(engine, command) {
var options = {};
if (!engine.hasOrigin()) {
throw new GitError({
msg: intl.str('git-error-origin-required')
});
}
var generalArgs = command.getGeneralArgs();
command.oneArgImpliedOrigin(generalArgs);
command.twoArgsImpliedOrigin(generalArgs);
if (generalArgs[0] !== 'origin') {
throw new GitError({
msg: intl.str('git-error-options')
msg: intl.todo(
generalArgs[0] + ' is not a remote in your repository! try origin'
)
});
}
engine.fetch();
if (generalArgs[1]) {
var branchName = crappyUnescape(generalArgs[1]);
if (!engine.refs[branchName]) {
throw new GitError({
msg: intl.todo(branchName + ' is not a branch!')
});
}
var branch = engine.resolveID(branchName);
if (branch.get('type') !== 'branch') {
throw new GitError({
msg: intl.todo(branchName + ' is not a branch!')
});
}
var tracking = branch.getRemoteTrackingBranchID();
if (!tracking) {
throw new GitError({
msg: intl.todo(branchName + ' is not a remote tracking branch!')
});
}
options.branches = [engine.refs[tracking]];
}
engine.fetch(options);
}
},

View file

@ -334,6 +334,7 @@ GitEngine.prototype.makeOrigin = function(treeString) {
originVis.customEvents.on('gitEngineReady', function() {
this.origin = originVis.gitEngine;
originVis.gitEngine.assignLocalRepo(this);
this.syncRemoteBranchFills();
// and then here is the crazy part -- we need the ORIGIN to refresh
// itself in a separate animation. @_____@
this.origin.externalRefresh();
@ -943,15 +944,16 @@ GitEngine.prototype.push = function(options) {
GitEngine.prototype.fetch = function(options) {
options = options || {};
// fetch all local branches
// get all remotes
var allRemotes = this.branchCollection.filter(function(branch) {
return branch.getIsRemote();
});
var branchesToFetch = options.branches || allRemotes;
// first check if our local remote branch is upstream of the origin branch set.
// this check essentially pretends the local remote branch is in origin and
// could be fast forwarded (basic sanity check)
_.each(allRemotes, function(localRemoteBranch) {
_.each(branchesToFetch, function(localRemoteBranch) {
this.checkUpstreamOfSource(
this,
this.origin,
@ -962,7 +964,8 @@ GitEngine.prototype.fetch = function(options) {
// then we get the difference in commits between these two graphs
var commitsToMake = [];
_.each(allRemotes, function(localRemoteBranch) {
_.each(branchesToFetch, function(localRemoteBranch) {
options.dontThrowOnNoFetch = true;
commitsToMake = commitsToMake.concat(this.getTargetGraphDifference(
this,
this.origin,
@ -971,6 +974,12 @@ GitEngine.prototype.fetch = function(options) {
options
));
}, this);
if (!commitsToMake.length) {
throw new GitError({
msg: intl.str('git-error-origin-fetch-uptodate')
});
}
// we did this for each remote branch, but we still need to reduce to unique
// and sort. in this particular app we can never have unfected remote
// commits that are upstream of multiple branches (since the fakeTeamwork
@ -1035,7 +1044,7 @@ GitEngine.prototype.fetch = function(options) {
chain = chain.then(_.bind(function() {
// update all the remote branches
_.each(allRemotes, function(localRemoteBranch) {
_.each(branchesToFetch, function(localRemoteBranch) {
var remoteBranch = this.origin.refs[localRemoteBranch.getBaseID()];
var remoteLocationID = remoteBranch.get('target').get('id');
// by definition we just made the commit with this id,
@ -1376,6 +1385,17 @@ GitEngine.prototype.updateAllBranchesForHg = function() {
return this.updateBranchesForHg(branchList);
};
GitEngine.prototype.syncRemoteBranchFills = function() {
this.branchCollection.each(function(branch) {
if (!branch.getIsRemote()) {
return;
}
var originBranch = this.origin.refs[branch.getBaseID()];
var originFill = originBranch.get('visBranch').get('fill');
branch.get('visBranch').set('fill', originFill);
}, this);
};
GitEngine.prototype.updateBranchesForHg = function(branchList) {
var hasUpdated = false;
_.each(branchList, function(branchID) {