Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed many fetch/pull issues on #1138 #1141

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions __tests__/remote.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
Loading
Loading