mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-28 00:40:07 +02:00
Fixed many fetch/pull issues on #1138
This commit is contained in:
parent
03a82ce78f
commit
5322fd6605
2 changed files with 30 additions and 17 deletions
|
@ -22,6 +22,14 @@ var assertIsRef = function(engine, ref) {
|
||||||
engine.resolveID(ref); // will throw git error if can't resolve
|
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) {
|
var validateBranchName = function(engine, name) {
|
||||||
return engine.validateBranchName(name);
|
return engine.validateBranchName(name);
|
||||||
};
|
};
|
||||||
|
@ -255,6 +263,7 @@ var commandConfig = {
|
||||||
if (firstArg && isColonRefspec(firstArg)) {
|
if (firstArg && isColonRefspec(firstArg)) {
|
||||||
var refspecParts = firstArg.split(':');
|
var refspecParts = firstArg.split(':');
|
||||||
source = refspecParts[0];
|
source = refspecParts[0];
|
||||||
|
assertRefNoModifiers(source);
|
||||||
destination = validateBranchNameIfNeeded(
|
destination = validateBranchNameIfNeeded(
|
||||||
engine,
|
engine,
|
||||||
crappyUnescape(refspecParts[1])
|
crappyUnescape(refspecParts[1])
|
||||||
|
@ -264,7 +273,6 @@ var commandConfig = {
|
||||||
source = firstArg;
|
source = firstArg;
|
||||||
assertIsBranch(engine.origin, source);
|
assertIsBranch(engine.origin, source);
|
||||||
// get o/main locally if main is specified
|
// get o/main locally if main is specified
|
||||||
destination = engine.origin.resolveID(source).getPrefixedID();
|
|
||||||
} else {
|
} else {
|
||||||
// can't be detached
|
// can't be detached
|
||||||
if (engine.getDetachedHead()) {
|
if (engine.getDetachedHead()) {
|
||||||
|
@ -277,8 +285,7 @@ var commandConfig = {
|
||||||
var branch = engine.getOneBeforeCommit('HEAD');
|
var branch = engine.getOneBeforeCommit('HEAD');
|
||||||
var branchName = branch.get('id');
|
var branchName = branch.get('id');
|
||||||
assertBranchIsRemoteTracking(engine, branchName);
|
assertBranchIsRemoteTracking(engine, branchName);
|
||||||
destination = branch.getRemoteTrackingBranchID();
|
source = branch.getRemoteTrackingBranchID().replace(ORIGIN_PREFIX, '');
|
||||||
source = destination.replace(ORIGIN_PREFIX, '');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.pull({
|
engine.pull({
|
||||||
|
@ -392,6 +399,7 @@ var commandConfig = {
|
||||||
if (firstArg && isColonRefspec(firstArg)) {
|
if (firstArg && isColonRefspec(firstArg)) {
|
||||||
var refspecParts = firstArg.split(':');
|
var refspecParts = firstArg.split(':');
|
||||||
source = refspecParts[0];
|
source = refspecParts[0];
|
||||||
|
assertRefNoModifiers(source);
|
||||||
destination = validateBranchNameIfNeeded(
|
destination = validateBranchNameIfNeeded(
|
||||||
engine,
|
engine,
|
||||||
crappyUnescape(refspecParts[1])
|
crappyUnescape(refspecParts[1])
|
||||||
|
@ -405,7 +413,6 @@ var commandConfig = {
|
||||||
source = firstArg;
|
source = firstArg;
|
||||||
assertIsBranch(engine.origin, source);
|
assertIsBranch(engine.origin, source);
|
||||||
// get o/main locally if main is specified
|
// get o/main locally if main is specified
|
||||||
destination = engine.origin.resolveID(source).getPrefixedID();
|
|
||||||
}
|
}
|
||||||
if (source) { // empty string fails this check
|
if (source) { // empty string fails this check
|
||||||
assertIsRef(engine.origin, source);
|
assertIsRef(engine.origin, source);
|
||||||
|
|
|
@ -397,11 +397,8 @@ GitEngine.prototype.makeBranchIfNeeded = function(branchName) {
|
||||||
if (this.doesRefExist(branchName)) {
|
if (this.doesRefExist(branchName)) {
|
||||||
return;
|
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) {
|
GitEngine.prototype.makeRemoteBranchForRemote = function(branchName) {
|
||||||
|
@ -1241,17 +1238,26 @@ GitEngine.prototype.fetch = function(options) {
|
||||||
this.getCommitFromRef('HEAD')
|
this.getCommitFromRef('HEAD')
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} else if (options.destination && options.source) {
|
} else if (options.source) {
|
||||||
|
var sourceDestPairs = [];
|
||||||
didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(options.source);
|
didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(options.source);
|
||||||
didMakeBranch = didMakeBranch || this.makeBranchIfNeeded(options.destination);
|
var source = this.origin.resolveID(options.source);
|
||||||
options.didMakeBranch = didMakeBranch;
|
if (source.get('type') == 'branch') {
|
||||||
|
sourceDestPairs.push({
|
||||||
return this.fetchCore([{
|
destination: this.origin.resolveID(options.source).getPrefixedID(),
|
||||||
|
source: options.source
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (options.destination) {
|
||||||
|
didMakeBranch = didMakeBranch || this.makeBranchIfNeeded(options.destination);
|
||||||
|
sourceDestPairs.push({
|
||||||
destination: options.destination,
|
destination: options.destination,
|
||||||
source: options.source
|
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
|
// get all remote branches and specify the dest / source pairs
|
||||||
var allBranchesOnRemote = this.origin.branchCollection.toArray();
|
var allBranchesOnRemote = this.origin.branchCollection.toArray();
|
||||||
|
@ -1409,7 +1415,7 @@ GitEngine.prototype.pull = function(options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var destBranch = this.resolveID(options.destination);
|
var destBranch = this.resolveID(options.destination || this.origin.resolveID(options.source).getPrefixedID());
|
||||||
// then either rebase or merge
|
// then either rebase or merge
|
||||||
if (options.isRebase) {
|
if (options.isRebase) {
|
||||||
this.pullFinishWithRebase(pendingFetch, localBranch, destBranch);
|
this.pullFinishWithRebase(pendingFetch, localBranch, destBranch);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue