mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-22 03:35:41 +02:00
local storage and general arg stuff
This commit is contained in:
parent
eeff8da035
commit
aaf7a462c0
4 changed files with 34 additions and 32 deletions
4
lib/backbone.localStorage-min.js
vendored
Normal file
4
lib/backbone.localStorage-min.js
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/**
|
||||||
|
* Backbone localStorage Adapter
|
||||||
|
* https://github.com/jeromegn/Backbone.localStorage
|
||||||
|
*/(function(){function c(){return((1+Math.random())*65536|0).toString(16).substring(1)}function d(){return c()+c()+"-"+c()+"-"+c()+"-"+c()+"-"+c()+c()+c()}var a=this._,b=this.Backbone;b.LocalStorage=window.Store=function(a){this.name=a;var b=this.localStorage().getItem(this.name);this.records=b&&b.split(",")||[]},a.extend(b.LocalStorage.prototype,{save:function(){this.localStorage().setItem(this.name,this.records.join(","))},create:function(a){return a.id||(a.id=d(),a.set(a.idAttribute,a.id)),this.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),this.records.push(a.id.toString()),this.save(),a.toJSON()},update:function(b){return this.localStorage().setItem(this.name+"-"+b.id,JSON.stringify(b)),a.include(this.records,b.id.toString())||this.records.push(b.id.toString()),this.save(),b.toJSON()},find:function(a){return JSON.parse(this.localStorage().getItem(this.name+"-"+a.id))},findAll:function(){return a(this.records).chain().map(function(a){return JSON.parse(this.localStorage().getItem(this.name+"-"+a))},this).compact().value()},destroy:function(b){return this.localStorage().removeItem(this.name+"-"+b.id),this.records=a.reject(this.records,function(a){return a==b.id.toString()}),this.save(),b},localStorage:function(){return localStorage}}),b.LocalStorage.sync=window.Store.sync=b.localSync=function(a,b,c,d){var e=b.localStorage||b.collection.localStorage;typeof c=="function"&&(c={success:c,error:d});var f,g=$.Deferred&&$.Deferred();switch(a){case"read":f=b.id!=undefined?e.find(b):e.findAll();break;case"create":f=e.create(b);break;case"update":f=e.update(b);break;case"delete":f=e.destroy(b)}return f?(c.success(f),g&&g.resolve()):(c.error("Record not found"),g&&g.reject()),g&&g.promise()},b.ajaxSync=b.sync,b.getSyncMethod=function(a){return a.localStorage||a.collection&&a.collection.localStorage?b.localSync:b.ajaxSync},b.sync=function(a,c,d,e){return b.getSyncMethod(c).apply(this,[a,c,d,e])}})();
|
58
src/git.js
58
src/git.js
|
@ -314,8 +314,31 @@ GitEngine.prototype.acceptNoGeneralArgs = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.validateArgBounds = function(args, lower, upper) {
|
GitEngine.prototype.validateArgBounds = function(args, lower, upper, option) {
|
||||||
// TODO
|
// this is a little utility class to help arg validation that happens over and over again
|
||||||
|
var what = 'with ' + (option === undefined) ?
|
||||||
|
'git ' + this.command.get('method') :
|
||||||
|
this.command.get('method') + ' ' + option + ' ';
|
||||||
|
|
||||||
|
if (args.length < lower) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: 'I expect at least ' + String(lower) + ' argument(s) ' + what
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (args.length > upper) {
|
||||||
|
throw new GitError({
|
||||||
|
msg: 'I expect at most ' + String(upper) + ' argument(s) ' + what
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GitEngine.prototype.twoArgsImpliedHead = function(args, option) {
|
||||||
|
// our args we expect to be between 1 and 2
|
||||||
|
this.validateArgBounds(args, 1, 2, option);
|
||||||
|
// and if it's one, add a HEAD to the back
|
||||||
|
if (args.length == 1) {
|
||||||
|
args.push('HEAD');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.revertStarter = function() {
|
GitEngine.prototype.revertStarter = function() {
|
||||||
|
@ -1012,45 +1035,20 @@ GitEngine.prototype.branchStarter = function() {
|
||||||
|
|
||||||
if (this.commandOptions['-f']) {
|
if (this.commandOptions['-f']) {
|
||||||
var args = this.commandOptions['-f'];
|
var args = this.commandOptions['-f'];
|
||||||
if (args.length < 1) {
|
this.twoArgsImpliedHead(args, '-f');
|
||||||
throw new GitError({
|
|
||||||
msg: 'Give me an argument with -f so I know which branch to force!'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length > 2) {
|
|
||||||
throw new GitError({
|
|
||||||
msg: 'Too many args for -f'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length == 1) {
|
|
||||||
args.push('HEAD');
|
|
||||||
}
|
|
||||||
|
|
||||||
// we want to force a branch somewhere
|
// we want to force a branch somewhere
|
||||||
this.forceBranch(args[0], args[1]);
|
this.forceBranch(args[0], args[1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var len = this.generalArgs.length;
|
|
||||||
if (len > 2) {
|
|
||||||
throw new GitError({
|
|
||||||
msg: 'git branch with more than two general args does not make sense!'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (this.generalArgs.length == 0) {
|
||||||
if (len == 0) {
|
|
||||||
this.printBranches();
|
this.printBranches();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 1) {
|
|
||||||
// making a branch from where we are now
|
|
||||||
this.generalArgs.push('HEAD');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
this.twoArgsImpliedHead(this.generalArgs);
|
||||||
this.branch(this.generalArgs[0], this.generalArgs[1]);
|
this.branch(this.generalArgs[0], this.generalArgs[1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@
|
||||||
<script src="../lib/jquery-1.8.0.min.js"></script>
|
<script src="../lib/jquery-1.8.0.min.js"></script>
|
||||||
<script src="../lib/underscore-min.js"></script>
|
<script src="../lib/underscore-min.js"></script>
|
||||||
<script src="../lib/backbone-min.js"></script>
|
<script src="../lib/backbone-min.js"></script>
|
||||||
|
<script src="../lib/backbone.localStorage-min.js"></script>
|
||||||
<script src="../lib/raphael-min.js"></script>
|
<script src="../lib/raphael-min.js"></script>
|
||||||
|
|
||||||
<!-- Templates -->
|
<!-- Templates -->
|
||||||
|
|
3
todo.txt
3
todo.txt
|
@ -9,8 +9,7 @@ Big Graphic things:
|
||||||
|
|
||||||
Medium things:
|
Medium things:
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
- Rebuilding trees from a JSON snapshot / blob. this should be easy... i think. if we remove the need for parents
|
- gitEngine loads from tree immediately, not the weird thing we have now!
|
||||||
- gitEngine loads from tree immediately, not the weird thing we have now
|
|
||||||
|
|
||||||
Small things to implement:
|
Small things to implement:
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue