[FeatureRequest] git push --force beta Resolves #185

This commit is contained in:
Peter Cottle 2014-11-29 17:34:34 -08:00
parent cb776e1b4e
commit 7fc33541cc
3 changed files with 22 additions and 8 deletions

View file

@ -381,5 +381,12 @@ describe('Git Remotes', function() {
); );
}); });
it('uses git force to bypass upstream check', function() {
expectTreeAsync(
'git clone; git commit; git push; go C1; git branch -f master C1; go master; git commit; git commit; go C1; git checkout -b side; git commit; go master; git merge side; git push --force',
'{"branches":{"master":{"target":"C6","id":"master","remoteTrackingBranchID":"o/master"},"o/master":{"target":"C6","id":"o/master","remoteTrackingBranchID":null},"side":{"target":"C5","id":"side","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C3":{"parents":["C1"],"id":"C3"},"C4":{"parents":["C3"],"id":"C4"},"C5":{"parents":["C1"],"id":"C5"},"C6":{"parents":["C4","C5"],"id":"C6"}},"tags":{},"HEAD":{"target":"master","id":"HEAD"},"originTree":{"branches":{"master":{"target":"C6","id":"master","remoteTrackingBranchID":null}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"},"C5":{"parents":["C1"],"id":"C5"},"C3":{"parents":["C1"],"id":"C3"},"C4":{"parents":["C3"],"id":"C4"},"C6":{"parents":["C4","C5"],"id":"C6"}},"tags":{},"HEAD":{"target":"master","id":"HEAD"}}}'
);
});
}); });

View file

@ -674,6 +674,9 @@ var commandConfig = {
push: { push: {
regex: /^git +push($|\s)/, regex: /^git +push($|\s)/,
options: [
'--force'
],
execute: function(engine, command) { execute: function(engine, command) {
if (!engine.hasOrigin()) { if (!engine.hasOrigin()) {
throw new GitError({ throw new GitError({
@ -685,6 +688,7 @@ var commandConfig = {
var destination; var destination;
var source; var source;
var sourceObj; var sourceObj;
var commandOptions = command.getOptionsMap();
// git push is pretty complex in terms of // git push is pretty complex in terms of
// the arguments it wants as well... get ready! // the arguments it wants as well... get ready!
@ -737,7 +741,8 @@ var commandConfig = {
// NOTE -- very important! destination and source here // NOTE -- very important! destination and source here
// 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']
}); });
} }
}, },

View file

@ -1062,13 +1062,15 @@ GitEngine.prototype.push = function(options) {
var sourceLocation = this.resolveID(options.source || 'HEAD'); var sourceLocation = this.resolveID(options.source || 'HEAD');
// first check if this is even allowed by checking the sync between // first check if this is even allowed by checking the sync between
this.checkUpstreamOfSource( if (!options.force) {
this, this.checkUpstreamOfSource(
this.origin, this,
branchOnRemote, this.origin,
sourceLocation, branchOnRemote,
intl.str('git-error-origin-push-no-ff') sourceLocation,
); intl.str('git-error-origin-push-no-ff')
);
}
var commitsToMake = this.getTargetGraphDifference( var commitsToMake = this.getTargetGraphDifference(
this.origin, this.origin,