merge main

This commit is contained in:
Peter Cottle 2024-04-28 09:11:49 -07:00
commit 1247189b3e
3 changed files with 58 additions and 19 deletions

View file

@ -89,6 +89,13 @@ describe('Git Remotes', function() {
);
});
it('can fetch with --force where otherwise it would error', function() {
return expectTreeAsync(
'git clone; git fakeTeamwork; git commit; git checkout C1; git fetch origin main:main --force;',
'{"branches":{"main":{"target":"C2","id":"main","remoteTrackingBranchID":"o/main"},"o/main":{"target":"C2","id":"o/main","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C3":{"parents":["C1"],"id":"C3"},"C2":{"parents":["C1"],"id":"C2"}},"tags":{},"HEAD":{"target":"C1","id":"HEAD"},"originTree":{"branches":{"main":{"target":"C2","id":"main","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"tags":{},"HEAD":{"target":"main","id":"HEAD"}}}',
);
});
it('checks all branches for fetching', function() {
return expectTreeAsync(
'git branch bugFix; git clone; git fakeTeamwork; git fetch',
@ -164,7 +171,7 @@ describe('Git Remotes', function() {
'git branch foo; git clone; git push origin --delete',
'{"branches":{"main":{"target":"C1","id":"main","remoteTrackingBranchID":"o/main"},"foo":{"target":"C1","id":"foo","remoteTrackingBranchID":"o/foo"},"o/main":{"target":"C1","id":"o/main","remoteTrackingBranchID":null},"o/foo":{"target":"C1","id":"o/foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"tags":{},"HEAD":{"target":"main","id":"HEAD"},"originTree":{"branches":{"main":{"target":"C1","id":"main","remoteTrackingBranchID":null},"foo":{"target":"C1","id":"foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"tags":{},"HEAD":{"target":"main","id":"HEAD"}}}'
);
expectTreeAsync(
'git branch foo; git clone; git push origin --delete main:foo',
'{"branches":{"main":{"target":"C1","id":"main","remoteTrackingBranchID":"o/main"},"foo":{"target":"C1","id":"foo","remoteTrackingBranchID":"o/foo"},"o/main":{"target":"C1","id":"o/main","remoteTrackingBranchID":null},"o/foo":{"target":"C1","id":"o/foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"tags":{},"HEAD":{"target":"main","id":"HEAD"},"originTree":{"branches":{"main":{"target":"C1","id":"main","remoteTrackingBranchID":null},"foo":{"target":"C1","id":"foo","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"tags":{},"HEAD":{"target":"main","id":"HEAD"}}}'

View file

@ -227,6 +227,7 @@ var commandConfig = {
pull: {
regex: /^git +pull($|\s)/,
options: [
'--force',
'--rebase'
],
execute: function(engine, command) {
@ -237,6 +238,7 @@ var commandConfig = {
}
var commandOptions = command.getOptionsMap();
var force = !!commandOptions['--force'];
var generalArgs = command.getGeneralArgs();
if (commandOptions['--rebase']) {
generalArgs = commandOptions['--rebase'].concat(generalArgs);
@ -261,6 +263,10 @@ var commandConfig = {
var firstArg = generalArgs[1];
// COPY PASTA validation code from fetch. maybe fix this?
if (firstArg && isColonRefspec(firstArg)) {
if (firstArg[0] == '+') {
force = true;
firstArg = firstArg.substr(1);
}
var refspecParts = firstArg.split(':');
source = refspecParts[0];
assertRefNoModifiers(source);
@ -291,6 +297,7 @@ var commandConfig = {
engine.pull({
source: source,
destination: destination,
force: force,
isRebase: !!commandOptions['--rebase']
});
}
@ -382,6 +389,9 @@ var commandConfig = {
fetch: {
regex: /^git +fetch($|\s)/,
options: [
'--force',
],
execute: function(engine, command) {
if (!engine.hasOrigin()) {
throw new GitError({
@ -391,12 +401,18 @@ var commandConfig = {
var source;
var destination;
var commandOptions = command.getOptionsMap();
var force = !!commandOptions['--force'];
var generalArgs = command.getGeneralArgs();
command.twoArgsForOrigin(generalArgs);
assertOriginSpecified(generalArgs);
var firstArg = generalArgs[1];
if (firstArg && isColonRefspec(firstArg)) {
if (firstArg[0] == '+') {
force = true;
firstArg = firstArg.substr(1);
}
var refspecParts = firstArg.split(':');
source = refspecParts[0];
assertRefNoModifiers(source);
@ -420,7 +436,8 @@ var commandConfig = {
engine.fetch({
source: source,
destination: destination
destination: destination,
force: force
});
}
},
@ -808,6 +825,7 @@ var commandConfig = {
var source;
var sourceObj;
var commandOptions = command.getOptionsMap();
var force = !!commandOptions['--force'];
var isDelete = commandOptions['-d'] || commandOptions['--delete'];
// git push is pretty complex in terms of
@ -849,6 +867,10 @@ var commandConfig = {
}
if (firstArg && isColonRefspec(firstArg)) {
if (firstArg[0] == '+') {
force = true;
firstArg = firstArg.substr(1);
}
var refspecParts = firstArg.split(':');
source = refspecParts[0];
destination = validateBranchName(engine, refspecParts[1]);
@ -893,7 +915,7 @@ var commandConfig = {
// are always, always strings. very important :D
destination: destination,
source: source,
force: !!commandOptions['--force']
force: force
});
}
},

View file

@ -393,12 +393,12 @@ GitEngine.prototype.makeRemoteBranchIfNeeded = function(branchName) {
return this.makeRemoteBranchForRemote(branchName);
};
GitEngine.prototype.makeBranchIfNeeded = function(branchName) {
GitEngine.prototype.makeBranchIfNeeded = function(branchName, originName) {
if (this.doesRefExist(branchName)) {
return;
}
return this.validateAndMakeBranch(branchName, this.rootCommit);
var originTarget = this.findCommonAncestorWithRemote(this.origin.getCommitFromRef(originName).get('id'));
return this.validateAndMakeBranch(branchName, this.getCommitFromRef(originTarget));
};
GitEngine.prototype.makeRemoteBranchForRemote = function(branchName) {
@ -1240,7 +1240,7 @@ GitEngine.prototype.fetch = function(options) {
return;
} else if (options.source) {
var sourceDestPairs = [];
didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(options.source);
didMakeBranch = this.makeRemoteBranchIfNeeded(options.source);
var source = this.origin.resolveID(options.source);
if (source.get('type') == 'branch') {
sourceDestPairs.push({
@ -1249,7 +1249,7 @@ GitEngine.prototype.fetch = function(options) {
});
}
if (options.destination) {
didMakeBranch = didMakeBranch || this.makeBranchIfNeeded(options.destination);
didMakeBranch = this.makeBranchIfNeeded(options.destination, options.source) || didMakeBranch;
sourceDestPairs.push({
destination: options.destination,
source: options.source
@ -1278,14 +1278,16 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
// 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)
sourceDestPairs.forEach(function (pair) {
this.checkUpstreamOfSource(
this,
this.origin,
pair.destination,
pair.source
);
}, this);
if (!options.force) {
sourceDestPairs.forEach(function (pair) {
this.checkUpstreamOfSource(
this,
this.origin,
pair.destination,
pair.source
);
}, this);
}
// then we get the difference in commits between these two graphs
var commitsToMake = [];
@ -1304,9 +1306,16 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
}, this);
if (!commitsToMake.length && !options.dontThrowOnNoFetch) {
throw new GitError({
msg: intl.str('git-error-origin-fetch-uptodate')
});
var ge = this;
if (!options.force || !sourceDestPairs.some(function(pair) {
var sourceCommit = ge.getCommitFromRef(ge.origin.resolveID(pair.source));
var destinationCommit = ge.getCommitFromRef(ge.resolveID(pair.destination));
return sourceCommit.id !== destinationCommit.id;
})) {
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
@ -1406,6 +1415,7 @@ GitEngine.prototype.pull = function(options) {
var pendingFetch = this.fetch({
dontResolvePromise: true,
dontThrowOnNoFetch: true,
force: options.force,
source: options.source,
destination: options.destination
});