Skip to content

Instantly share code, notes, and snippets.

@thedanielhanke
Created October 12, 2018 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedanielhanke/430c61258c4f7e2162459678dacf89ac to your computer and use it in GitHub Desktop.
Save thedanielhanke/430c61258c4f7e2162459678dacf89ac to your computer and use it in GitHub Desktop.
{
//given:
const repo - bare Repository {}
const branchCommit = repo.getBranchCommit(branchName),
// actual method:
open: async (fn) => {
const tree = await branchCommit.getTree();
const treeBuilder = await nodegit.Treebuilder.create(repo, tree);
const write = async (fileName, body) => {
const buffer = Buffer.from(body, 'UTF-8');
const oid = await nodegit.Blob.createFromBuffer(repo, buffer, buffer.length);
await treeBuilder.insert(fileName, oid, 33188);
};
await fn({ write });
const id = await treeBuilder.write();
return id;
},
//..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment