diff --git a/src/git.js b/src/git.js index f648657e..c2e2b092 100644 --- a/src/git.js +++ b/src/git.js @@ -14,6 +14,10 @@ function GitEngine() { this.id_gen = 0; this.branches = []; + // global variable to keep track of the options given + // along with the command call. + this.currentOptions = {}; + events.on('gitCommandReady', _.bind(this.dispatch, this)); this.init(); @@ -95,17 +99,20 @@ GitEngine.prototype.makeCommit = function(parent) { }; GitEngine.prototype.commit = function() { - var targetCommit = null; - if (this.getDetachedHead()) { - // in detached head mode, must warn user TODO - targetCommit = this.HEAD.get('target'); - } else { - var targetBranch = this.HEAD.get('target'); - targetCommit = targetBranch.get('target'); + var targetCommit = this.getCommitFromRef(this.HEAD); + // if we want to ammend, go one above + if (this.currentOptions['--amend']) { + targetCommit = this.resolveId('HEAD~1'); } var newCommit = this.makeCommit(targetCommit); - targetBranch.set('target', newCommit); + + if (this.getDetachedHead()) { + events.trigger('commandProcessWarn', "Warning!! Detached HEAD state"); + } else { + var targetBranch = this.HEAD.get('target'); + targetBranch.set('target', newCommit); + } }; GitEngine.prototype.resolveId = function(idOrTarget) { @@ -255,8 +262,7 @@ GitEngine.prototype.deleteBranch = function(name) { }; GitEngine.prototype.dispatch = function(commandObj) { - // TODO: parse arguments as well - console.log(commandObj); + this.currentOptions = commandObj.optionParser.supportedMap; this[commandObj.method](); }; diff --git a/src/views.js b/src/views.js index 54069ab0..e19be13f 100644 --- a/src/views.js +++ b/src/views.js @@ -69,6 +69,10 @@ var CommandLineHistoryView = Backbone.View.extend({ this.commandError, this )); + events.on('commandProcessWarn', _.bind( + this.commandWarn, this + )); + events.on('commandResultPrint', _.bind( this.commandResultPrint, this )); @@ -111,6 +115,18 @@ var CommandLineHistoryView = Backbone.View.extend({ ); }, + commandWarn: function(msg) { + this.$('#commandDisplay').append( + _.template( + this.resultTemplate, + { + className: 'commandWarn', + result: msg + } + ) + ); + }, + commandResultPrint: function(err) { if (!err.msg.length) { // blank lines