Skip to content

Commit

Permalink
Fixed many fetch/pull issues on #1138
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmv94 committed Apr 26, 2024
1 parent 03a82ce commit 5322fd6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
15 changes: 11 additions & 4 deletions src/js/git/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ var assertIsRef = function(engine, ref) {
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) {
return engine.validateBranchName(name);
};
Expand Down Expand Up @@ -255,6 +263,7 @@ var commandConfig = {
if (firstArg && isColonRefspec(firstArg)) {
var refspecParts = firstArg.split(':');
source = refspecParts[0];
assertRefNoModifiers(source);
destination = validateBranchNameIfNeeded(
engine,
crappyUnescape(refspecParts[1])
Expand All @@ -264,7 +273,6 @@ var commandConfig = {
source = firstArg;
assertIsBranch(engine.origin, source);
// get o/main locally if main is specified
destination = engine.origin.resolveID(source).getPrefixedID();
} else {
// can't be detached
if (engine.getDetachedHead()) {
Expand All @@ -277,8 +285,7 @@ var commandConfig = {
var branch = engine.getOneBeforeCommit('HEAD');
var branchName = branch.get('id');
assertBranchIsRemoteTracking(engine, branchName);
destination = branch.getRemoteTrackingBranchID();
source = destination.replace(ORIGIN_PREFIX, '');
source = branch.getRemoteTrackingBranchID().replace(ORIGIN_PREFIX, '');
}

engine.pull({
Expand Down Expand Up @@ -392,6 +399,7 @@ var commandConfig = {
if (firstArg && isColonRefspec(firstArg)) {
var refspecParts = firstArg.split(':');
source = refspecParts[0];
assertRefNoModifiers(source);
destination = validateBranchNameIfNeeded(
engine,
crappyUnescape(refspecParts[1])
Expand All @@ -405,7 +413,6 @@ var commandConfig = {
source = firstArg;
assertIsBranch(engine.origin, source);
// get o/main locally if main is specified
destination = engine.origin.resolveID(source).getPrefixedID();
}
if (source) { // empty string fails this check
assertIsRef(engine.origin, source);
Expand Down
32 changes: 19 additions & 13 deletions src/js/git/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,8 @@ GitEngine.prototype.makeBranchIfNeeded = function(branchName) {
if (this.doesRefExist(branchName)) {
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) {
Expand Down Expand Up @@ -1241,17 +1238,26 @@ GitEngine.prototype.fetch = function(options) {
this.getCommitFromRef('HEAD')
);
return;
} else if (options.destination && options.source) {
} else if (options.source) {
var sourceDestPairs = [];
didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(options.source);
didMakeBranch = didMakeBranch || this.makeBranchIfNeeded(options.destination);
options.didMakeBranch = didMakeBranch;

return this.fetchCore([{
var source = this.origin.resolveID(options.source);
if (source.get('type') == 'branch') {
sourceDestPairs.push({
destination: this.origin.resolveID(options.source).getPrefixedID(),
source: options.source
});
}
if (options.destination) {
didMakeBranch = didMakeBranch || this.makeBranchIfNeeded(options.destination);
sourceDestPairs.push({
destination: options.destination,
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
var allBranchesOnRemote = this.origin.branchCollection.toArray();
Expand Down Expand Up @@ -1409,7 +1415,7 @@ GitEngine.prototype.pull = function(options) {
return;
}

var destBranch = this.resolveID(options.destination);
var destBranch = this.resolveID(options.destination || this.origin.resolveID(options.source).getPrefixedID());
// then either rebase or merge
if (options.isRebase) {
this.pullFinishWithRebase(pendingFetch, localBranch, destBranch);
Expand Down

0 comments on commit 5322fd6

Please sign in to comment.