yay all tests pass and big git pull update

This commit is contained in:
Peter Cottle 2013-10-22 10:56:35 -07:00
parent 99bf9bacd3
commit b8cf7f75c0
3 changed files with 57 additions and 18 deletions

View file

@ -263,8 +263,8 @@ describe('Git Remotes', function() {
it('doesnt fetch if out of sync, but will update explicit dest if specified', function() { it('doesnt fetch if out of sync, but will update explicit dest if specified', function() {
expectTreeAsync( expectTreeAsync(
'git clone; git fakeTeamwork; git fetch origin master:master;gc;git fakeTeamwork;git fetch origin master:master', 'git clone; git fakeTeamwork; go HEAD~1; git fetch origin master:master;go master; gc; go HEAD~1; git fakeTeamwork;git fetch origin master:master',
'{"branches":{"master":{"target":"C3","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"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C2"],"id":"C3"}},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C4","id":"master","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C4":{"parents":["C2"],"id":"C4"}},"HEAD":{"target":"master","id":"HEAD"}}}' '{"branches":{"master":{"target":"C3","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"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C2"],"id":"C3"}},"HEAD":{"target":"C2","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C4","id":"master","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C4":{"parents":["C2"],"id":"C4"}},"HEAD":{"target":"master","id":"HEAD"}}}'
); );
}); });

View file

@ -7,6 +7,8 @@ var GitError = Errors.GitError;
var Warning = Errors.Warning; var Warning = Errors.Warning;
var CommandResult = Errors.CommandResult; var CommandResult = Errors.CommandResult;
var ORIGIN_PREFIX = 'o/';
var crappyUnescape = function(str) { var crappyUnescape = function(str) {
return str.replace(/'/g, "'").replace(///g, "/"); return str.replace(/'/g, "'").replace(///g, "/");
}; };
@ -30,6 +32,19 @@ var validateBranchNameIfNeeded = function(engine, name) {
return validateBranchName(engine, name); return validateBranchName(engine, name);
}; };
var assertNotCheckedOut = function(engine, ref) {
if (!engine.refs[ref]) {
return;
}
if (engine.HEAD.get('target') === engine.refs[ref]) {
throw new GitError({
msg: intl.todo(
'cannot fetch to ' + ref + ' when checked out on ' + ref
)
});
}
};
var assertIsBranch = function(engine, ref) { var assertIsBranch = function(engine, ref) {
assertIsRef(engine, ref); assertIsRef(engine, ref);
var obj = engine.refs[ref]; var obj = engine.refs[ref];
@ -191,6 +206,10 @@ var commandConfig = {
}); });
} }
var commandOptions = command.getOptionsMap();
var generalArgs = command.getGeneralArgs();
command.twoArgsImpliedOrigin(generalArgs);
assertOriginSpecified(generalArgs);
// here is the deal -- git pull is pretty complex with // here is the deal -- git pull is pretty complex with
// the arguments it wants. You can // the arguments it wants. You can
// A) specify the remote branch you want to // A) specify the remote branch you want to
@ -201,17 +220,27 @@ var commandConfig = {
// the branch to fetch from the remote tracking // the branch to fetch from the remote tracking
// and merges those in, or // and merges those in, or
// //
// C) specify the colon refspec like fetch (where it // C) specify the colon refspec like fetch, where it does
// so lets switch on A/B here // the fetch and then just merges the dest
var commandOptions = command.getOptionsMap(); var source;
var generalArgs = command.getGeneralArgs(); var destination;
command.twoArgsImpliedOrigin(generalArgs); var firstArg = generalArgs[1];
assertOriginSpecified(generalArgs); // COPY PASTA validation code from fetch. maybe fix this?
if (firstArg && isColonRefspec(firstArg)) {
var tracking;
if (generalArgs[1]) {
tracking = assertBranchIsRemoteTracking(engine, generalArgs[1]); tracking = assertBranchIsRemoteTracking(engine, generalArgs[1]);
var refspecParts = firstArg.split(':');
source = refspecParts[0];
destination = validateBranchNameIfNeeded(
engine,
crappyUnescape(refspecParts[1])
);
assertNotCheckedOut(engine, destination);
} else if (firstArg) {
source = firstArg;
assertIsBranch(engine.origin, source);
// get o/master locally if master is specified
destination = engine.origin.refs[source].getPrefixedID();
} else { } else {
// cant be detached // cant be detached
if (engine.getDetachedHead()) { if (engine.getDetachedHead()) {
@ -219,12 +248,18 @@ var commandConfig = {
msg: intl.todo('Git pull can not be executed in detached HEAD mode if no remote branch specified!') msg: intl.todo('Git pull can not be executed in detached HEAD mode if no remote branch specified!')
}); });
} }
var oneBefore = engine.getOneBeforeCommit('HEAD'); // ok we need to get our currently checked out branch
tracking = assertBranchIsRemoteTracking(engine, oneBefore.get('id')); // and then specify source and dest
var branch = engine.getOneBeforeCommit('HEAD');
var branchName = branch.get('id');
assertBranchIsRemoteTracking(engine, branchName);
destination = branch.getRemoteTrackingBranchID();
source = destination.replace(ORIGIN_PREFIX, '');
} }
engine.pull({ engine.pull({
source: tracking, source: source,
destination: destination,
isRebase: commandOptions['--rebase'] isRebase: commandOptions['--rebase']
}); });
} }
@ -308,6 +343,7 @@ var commandConfig = {
engine, engine,
crappyUnescape(refspecParts[1]) crappyUnescape(refspecParts[1])
); );
assertNotCheckedOut(engine, destination);
} else if (firstArg) { } else if (firstArg) {
// here is the deal -- its JUST like git push. the first arg // here is the deal -- its JUST like git push. the first arg
// is used as both the destination and the source, so we need // is used as both the destination and the source, so we need

View file

@ -1214,18 +1214,21 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
GitEngine.prototype.pull = function(options) { GitEngine.prototype.pull = function(options) {
options = options || {}; options = options || {};
var localBranch = this.getOneBeforeCommit('HEAD'); var localBranch = this.getOneBeforeCommit('HEAD');
var remoteBranch = this.refs[options.source];
// no matter what fetch // no matter what fetch
var pendingFetch = this.fetch({ var pendingFetch = this.fetch({
dontResolvePromise: true, dontResolvePromise: true,
dontThrowOnNoFetch: true dontThrowOnNoFetch: true,
source: options.source,
destination: options.destination
}); });
var destBranch = this.refs[options.destination];
// then either rebase or merge // then either rebase or merge
if (options.isRebase) { if (options.isRebase) {
this.pullFinishWithRebase(pendingFetch, localBranch, remoteBranch); this.pullFinishWithRebase(pendingFetch, localBranch, destBranch);
} else { } else {
this.pullFinishWithMerge(pendingFetch, localBranch, remoteBranch); this.pullFinishWithMerge(pendingFetch, localBranch, destBranch);
} }
}; };