diff --git a/src/commandline.js b/src/commandline.js index 4e2606d4..6556236d 100644 --- a/src/commandline.js +++ b/src/commandline.js @@ -143,7 +143,7 @@ OptionParser.prototype.getMasterOptionMap = function() { return { commit: { '--amend': false, - '-a': false, + '-a': false, // warning '-am': false }, add: {}, @@ -156,6 +156,7 @@ OptionParser.prototype.getMasterOptionMap = function() { }, reset: { '--hard': false, + '--soft': false, // this will raise and error but we catch it in gitEngine }, merge: {}, rebase: {}, diff --git a/src/git.js b/src/git.js index 43d129a2..c1b1abc4 100644 --- a/src/git.js +++ b/src/git.js @@ -135,7 +135,36 @@ GitEngine.prototype.acceptNoGeneralArgs = function() { }; GitEngine.prototype.resetStarter = function() { + if (this.commandOptions['--soft']) { + throw new GitError({ + msg: "You can't use --soft because there is no concept of stashing" + + " changes or staging files, so you will lose your progress." + + " Try using interactive rebasing (or just rebasing) to move commits." + }); + } + if (this.commandOptions['--hard']) { + events.trigger('commandProcessWarn', + 'Nice! You are using --hard. The default behavior is a hard reset in ' + + "this demo, so don't worry about specifying the option explicity" + ); + // dont absorb the arg off of --hard + this.generalArgs = this.generalArgs.concat(this.commandOptions['--hard']); + } + if (this.generalArgs.length !== 1) { + throw new GitError({ + msg: "Specify the commit to reset to (1 argument)" + }); + } + if (this.getDetachedHead()) { + throw new GitError({ + msg: "Cant reset in detached head! Use checkout if you want to move" + }); + } + this.reset(this.generalArgs[0]); +}; +GitEngine.prototype.reset = function(target) { + this.setLocationTarget('HEAD', this.getCommitFromRef(target)); }; GitEngine.prototype.commitStarter = function() {