js-git-browser
A build of js-git that is made to run
in the browser via browserify and uses promises by default (that can be used in
combination with await
).
Usage
var modes = jsgitmodes repo = jsgit; // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-// initial commit var author = name: "Robert Krahn" email: "robert.krahn@gmail.com" date: ; var changes = path: "test.txt" mode: modesfile content: "some content" path: "test2.txt" mode: modesfile content: "some more content" path: "dir/test3.txt" mode: modesfile content: "foo bar baz"; var commitHash = await { Object; var tree = await repo commitHash = await repo; return repo;} // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-// load commit await { var tree = await repo return ;} { // readAs = "text"|"blob" var textObjs = reader = await repo obj; while obj = await reader if objmode !== modesfile continue; textObjs return textObjs;}
// Create a repo by creating a plain object.var repo = jsgit; // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // First we create a blob from a string. The `formats` mixin allows us to// use a string directly instead of having to pass in a binary buffer. // echo 'Hello World' | git hash-object -w --stdin var blobHash = await repo; // Now we create a tree that is a folder containing the blob as `greeting.txt`var treeHash = await repo; // With that tree, we can create a commit.// Again the `formats` mixin allows us to omit details like committer, date,// and parents. It assumes sane defaults for these.var commitHash = await repo; // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- var fileAsText = await repo; // Also if you prefer array format, you can load a directory as an array.var entries = await repo; // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- var logStream = await repo; // Looping through the stream is easy by repeatedly calling waiting on `read`.var commit object;while commit = await logStream commit !== undefined console; // We can also loop through all the files of each commit version. var treeStream = await repo; while object = await treeStream object !== undefined ; // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- var headHash = await repo;var commit = await repo;var tree = await repo;