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: {
|
||||
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
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue