mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-12 15:44:25 +02:00
Merge pull request #1142 from juanmv94/main
Implemented --force for fetch/pull. Force using +src:dest
This commit is contained in:
commit
2749d9c59d
2 changed files with 50 additions and 18 deletions
|
@ -227,6 +227,7 @@ var commandConfig = {
|
||||||
pull: {
|
pull: {
|
||||||
regex: /^git +pull($|\s)/,
|
regex: /^git +pull($|\s)/,
|
||||||
options: [
|
options: [
|
||||||
|
'--force',
|
||||||
'--rebase'
|
'--rebase'
|
||||||
],
|
],
|
||||||
execute: function(engine, command) {
|
execute: function(engine, command) {
|
||||||
|
@ -237,6 +238,7 @@ var commandConfig = {
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandOptions = command.getOptionsMap();
|
var commandOptions = command.getOptionsMap();
|
||||||
|
var force = !!commandOptions['--force'];
|
||||||
var generalArgs = command.getGeneralArgs();
|
var generalArgs = command.getGeneralArgs();
|
||||||
if (commandOptions['--rebase']) {
|
if (commandOptions['--rebase']) {
|
||||||
generalArgs = commandOptions['--rebase'].concat(generalArgs);
|
generalArgs = commandOptions['--rebase'].concat(generalArgs);
|
||||||
|
@ -261,6 +263,10 @@ var commandConfig = {
|
||||||
var firstArg = generalArgs[1];
|
var firstArg = generalArgs[1];
|
||||||
// COPY PASTA validation code from fetch. maybe fix this?
|
// COPY PASTA validation code from fetch. maybe fix this?
|
||||||
if (firstArg && isColonRefspec(firstArg)) {
|
if (firstArg && isColonRefspec(firstArg)) {
|
||||||
|
if (firstArg[0] == '+') {
|
||||||
|
force = true;
|
||||||
|
firstArg = firstArg.substr(1);
|
||||||
|
}
|
||||||
var refspecParts = firstArg.split(':');
|
var refspecParts = firstArg.split(':');
|
||||||
source = refspecParts[0];
|
source = refspecParts[0];
|
||||||
assertRefNoModifiers(source);
|
assertRefNoModifiers(source);
|
||||||
|
@ -291,6 +297,7 @@ var commandConfig = {
|
||||||
engine.pull({
|
engine.pull({
|
||||||
source: source,
|
source: source,
|
||||||
destination: destination,
|
destination: destination,
|
||||||
|
force: force,
|
||||||
isRebase: !!commandOptions['--rebase']
|
isRebase: !!commandOptions['--rebase']
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -382,6 +389,9 @@ var commandConfig = {
|
||||||
|
|
||||||
fetch: {
|
fetch: {
|
||||||
regex: /^git +fetch($|\s)/,
|
regex: /^git +fetch($|\s)/,
|
||||||
|
options: [
|
||||||
|
'--force',
|
||||||
|
],
|
||||||
execute: function(engine, command) {
|
execute: function(engine, command) {
|
||||||
if (!engine.hasOrigin()) {
|
if (!engine.hasOrigin()) {
|
||||||
throw new GitError({
|
throw new GitError({
|
||||||
|
@ -391,12 +401,18 @@ var commandConfig = {
|
||||||
|
|
||||||
var source;
|
var source;
|
||||||
var destination;
|
var destination;
|
||||||
|
var commandOptions = command.getOptionsMap();
|
||||||
|
var force = !!commandOptions['--force'];
|
||||||
var generalArgs = command.getGeneralArgs();
|
var generalArgs = command.getGeneralArgs();
|
||||||
command.twoArgsForOrigin(generalArgs);
|
command.twoArgsForOrigin(generalArgs);
|
||||||
assertOriginSpecified(generalArgs);
|
assertOriginSpecified(generalArgs);
|
||||||
|
|
||||||
var firstArg = generalArgs[1];
|
var firstArg = generalArgs[1];
|
||||||
if (firstArg && isColonRefspec(firstArg)) {
|
if (firstArg && isColonRefspec(firstArg)) {
|
||||||
|
if (firstArg[0] == '+') {
|
||||||
|
force = true;
|
||||||
|
firstArg = firstArg.substr(1);
|
||||||
|
}
|
||||||
var refspecParts = firstArg.split(':');
|
var refspecParts = firstArg.split(':');
|
||||||
source = refspecParts[0];
|
source = refspecParts[0];
|
||||||
assertRefNoModifiers(source);
|
assertRefNoModifiers(source);
|
||||||
|
@ -420,7 +436,8 @@ var commandConfig = {
|
||||||
|
|
||||||
engine.fetch({
|
engine.fetch({
|
||||||
source: source,
|
source: source,
|
||||||
destination: destination
|
destination: destination,
|
||||||
|
force: force
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -808,6 +825,7 @@ var commandConfig = {
|
||||||
var source;
|
var source;
|
||||||
var sourceObj;
|
var sourceObj;
|
||||||
var commandOptions = command.getOptionsMap();
|
var commandOptions = command.getOptionsMap();
|
||||||
|
var force = !!commandOptions['--force'];
|
||||||
var isDelete = commandOptions['-d'] || commandOptions['--delete'];
|
var isDelete = commandOptions['-d'] || commandOptions['--delete'];
|
||||||
|
|
||||||
// git push is pretty complex in terms of
|
// git push is pretty complex in terms of
|
||||||
|
@ -849,6 +867,10 @@ var commandConfig = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstArg && isColonRefspec(firstArg)) {
|
if (firstArg && isColonRefspec(firstArg)) {
|
||||||
|
if (firstArg[0] == '+') {
|
||||||
|
force = true;
|
||||||
|
firstArg = firstArg.substr(1);
|
||||||
|
}
|
||||||
var refspecParts = firstArg.split(':');
|
var refspecParts = firstArg.split(':');
|
||||||
source = refspecParts[0];
|
source = refspecParts[0];
|
||||||
destination = validateBranchName(engine, refspecParts[1]);
|
destination = validateBranchName(engine, refspecParts[1]);
|
||||||
|
@ -893,7 +915,7 @@ var commandConfig = {
|
||||||
// are always, always strings. very important :D
|
// are always, always strings. very important :D
|
||||||
destination: destination,
|
destination: destination,
|
||||||
source: source,
|
source: source,
|
||||||
force: !!commandOptions['--force']
|
force: force
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -393,12 +393,12 @@ GitEngine.prototype.makeRemoteBranchIfNeeded = function(branchName) {
|
||||||
return this.makeRemoteBranchForRemote(branchName);
|
return this.makeRemoteBranchForRemote(branchName);
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.makeBranchIfNeeded = function(branchName) {
|
GitEngine.prototype.makeBranchIfNeeded = function(branchName, originName) {
|
||||||
if (this.doesRefExist(branchName)) {
|
if (this.doesRefExist(branchName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var originTarget = this.findCommonAncestorWithRemote(this.origin.getCommitFromRef(originName).get('id'));
|
||||||
return this.validateAndMakeBranch(branchName, this.rootCommit);
|
return this.validateAndMakeBranch(branchName, this.getCommitFromRef(originTarget));
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.makeRemoteBranchForRemote = function(branchName) {
|
GitEngine.prototype.makeRemoteBranchForRemote = function(branchName) {
|
||||||
|
@ -1240,7 +1240,7 @@ GitEngine.prototype.fetch = function(options) {
|
||||||
return;
|
return;
|
||||||
} else if (options.source) {
|
} else if (options.source) {
|
||||||
var sourceDestPairs = [];
|
var sourceDestPairs = [];
|
||||||
didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(options.source);
|
didMakeBranch = this.makeRemoteBranchIfNeeded(options.source);
|
||||||
var source = this.origin.resolveID(options.source);
|
var source = this.origin.resolveID(options.source);
|
||||||
if (source.get('type') == 'branch') {
|
if (source.get('type') == 'branch') {
|
||||||
sourceDestPairs.push({
|
sourceDestPairs.push({
|
||||||
|
@ -1249,7 +1249,7 @@ GitEngine.prototype.fetch = function(options) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (options.destination) {
|
if (options.destination) {
|
||||||
didMakeBranch = didMakeBranch || this.makeBranchIfNeeded(options.destination);
|
didMakeBranch = this.makeBranchIfNeeded(options.destination, options.source) || didMakeBranch;
|
||||||
sourceDestPairs.push({
|
sourceDestPairs.push({
|
||||||
destination: options.destination,
|
destination: options.destination,
|
||||||
source: options.source
|
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.
|
// 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
|
// this check essentially pretends the local remote branch is in origin and
|
||||||
// could be fast forwarded (basic sanity check)
|
// could be fast forwarded (basic sanity check)
|
||||||
sourceDestPairs.forEach(function (pair) {
|
if (!options.force) {
|
||||||
this.checkUpstreamOfSource(
|
sourceDestPairs.forEach(function (pair) {
|
||||||
this,
|
this.checkUpstreamOfSource(
|
||||||
this.origin,
|
this,
|
||||||
pair.destination,
|
this.origin,
|
||||||
pair.source
|
pair.destination,
|
||||||
);
|
pair.source
|
||||||
}, this);
|
);
|
||||||
|
}, this);
|
||||||
|
}
|
||||||
|
|
||||||
// then we get the difference in commits between these two graphs
|
// then we get the difference in commits between these two graphs
|
||||||
var commitsToMake = [];
|
var commitsToMake = [];
|
||||||
|
@ -1304,9 +1306,16 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
if (!commitsToMake.length && !options.dontThrowOnNoFetch) {
|
if (!commitsToMake.length && !options.dontThrowOnNoFetch) {
|
||||||
throw new GitError({
|
var ge = this;
|
||||||
msg: intl.str('git-error-origin-fetch-uptodate')
|
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
|
// 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({
|
var pendingFetch = this.fetch({
|
||||||
dontResolvePromise: true,
|
dontResolvePromise: true,
|
||||||
dontThrowOnNoFetch: true,
|
dontThrowOnNoFetch: true,
|
||||||
|
force: options.force,
|
||||||
source: options.source,
|
source: options.source,
|
||||||
destination: options.destination
|
destination: options.destination
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue