mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-30 01:34:26 +02:00
really basic option parsing
This commit is contained in:
parent
908b403c4b
commit
513315af3c
2 changed files with 32 additions and 10 deletions
26
src/git.js
26
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]();
|
||||
};
|
||||
|
||||
|
|
16
src/views.js
16
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue