Skip to content

Conversation

@rafaelgieschke
Copy link
Contributor

@rafaelgieschke rafaelgieschke commented Mar 22, 2017

Currently, Tree#createUpdated is not usable as new TreeUpdates cannot be constructed and createUpdated(repo, nupdates, updates) only accepts a single TreeUpdate as updates.

This pull request allows to new TreeUpdate() and turns updates into an Array<TreeUpdate>.

Usage is, e.g., as follows:

#!/usr/bin/env node

const Git = require("nodegit");

(async () => {
  const repo = await Git.Repository.init("test", 1);
  const odb = await repo.odb();
  const emptyTree = await repo.getTree(await odb.write("", 0, Git.Object.TYPE.TREE));
  const oid = await odb.write("test\n", 5, Git.Object.TYPE.BLOB);

  const update = new Git.TreeUpdate();
  update.action = Git.Tree.UPDATE.UPSERT;
  update.filemode = Git.TreeEntry.FILEMODE.BLOB;
  update.id = oid;
  update.path = "directory1/file";

  const update2 = new Git.TreeUpdate();
  update2.action = Git.Tree.UPDATE.UPSERT;
  update2.filemode = Git.TreeEntry.FILEMODE.BLOB;
  update2.id = oid;
  update2.path = "directory2/file";

  const treeOid = await emptyTree.createUpdated(repo, 2, [update, update2]);
  console.log(treeOid);
})();

@johnhaley81
Copy link
Collaborator

@rafaelgieschke sorry about taking so long to look at this. This is great! Could you provide some tests to ensure functionality now and in the future please?

@johnhaley81
Copy link
Collaborator

Perfect, thanks!

@rafaelgieschke
Copy link
Contributor Author

@johnhaley81 Thanks for looking at this. I added a simple test.

@stewartlord
Copy link

Hey @rafaelgieschke and @johnhaley81. I was curious if this change is ready to be merged? It looks like it might have been forgotten.

@rafaelgieschke
Copy link
Contributor Author

@stewartlord Yes, this and #1255 should be ready to be merged.

@JoostK
Copy link

JoostK commented May 27, 2019

This would be great! Any chance it can be rebased and get merged?

@henkesn henkesn mentioned this pull request Jul 22, 2019
@implausible implausible merged commit 8dae43a into nodegit:master Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants