Skip to content

Commit

Permalink
native-or-bluebird promises + thenify
Browse files Browse the repository at this point in the history
also, add reserved word fixes to thenify (temporarily)
  • Loading branch information
heavyk committed Jun 23, 2015
1 parent 957043f commit 2e0a0c6
Show file tree
Hide file tree
Showing 60 changed files with 136 additions and 147 deletions.
11 changes: 3 additions & 8 deletions examples/add-and-commit.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
var nodegit = require("../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["ensureDir", "writeFile"]);
var fileName = "newfile.txt";
var fileContent = "hello world";
var directoryName = "salad/toast/strangerinastrangeland/theresnowaythisexists";
// ensureDir is an alias to mkdirp, which has the callback with a weird name
// and in the 3rd position of 4 (the 4th being used for recursion). We have to
// force promisify it, because promisify-node won't detect it on its
// own and assumes sync
fse.ensureDir = promisify(fse.ensureDir);

/**
* This example creates a certain file `newfile.txt`, adds it to the git
Expand Down Expand Up @@ -71,6 +66,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))

return repo.createCommit("HEAD", author, committer, "message", oid, [parent]);
})
.done(function(commitId) {
.then(function(commitId) {
console.log("New Commit: ", commitId);
});
6 changes: 3 additions & 3 deletions examples/clone.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var nodegit = require("../");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["remove"]);
var path = "/tmp/nodegit-clone-demo";

fse.remove(path).then(function() {
Expand Down Expand Up @@ -28,7 +28,7 @@ fse.remove(path).then(function() {
entry = entryResult;
return entry.getBlob();
})
.done(function(blob) {
.then(function(blob) {
console.log(entry.filename(), entry.sha(), blob.rawsize() + "b");
console.log("========================================================\n\n");
var firstTenLines = blob.toString().split("\n").slice(0, 10).join("\n");
Expand Down
6 changes: 3 additions & 3 deletions examples/cloneFromGithubWith2Factor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var nodegit = require("../");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["remove"]);
var path = "/tmp/nodegit-github-2factor-demo";

var token = "{Your GitHub user token}";
Expand Down Expand Up @@ -35,7 +35,7 @@ var opts = {

fse.remove(path).then(function() {
nodegit.Clone(repoUrl, path, opts)
.done(function(repo) {
.then(function(repo) {
if (repo instanceof nodegit.Repository) {
console.info("We cloned the repo!");
}
Expand Down
2 changes: 1 addition & 1 deletion examples/create-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
repo.defaultSignature(),
"Created new-branch on HEAD");
});
}).done(function() {
}).then(function() {
console.log("All done!");
});
8 changes: 3 additions & 5 deletions examples/create-new-repo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
var nodegit = require("../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["ensureDir", "writeFile"]);
var fileName = "newfile.txt";
var fileContent = "hello world";
var repoDir = "../../newRepo";

fse.ensureDir = promisify(fse.ensureDir);

var repository;
var index;

Expand Down Expand Up @@ -45,6 +43,6 @@ fse.ensureDir(path.resolve(__dirname, repoDir))
// normal we don't get the head either, because there isn't one yet.
return repository.createCommit("HEAD", author, committer, "message", oid, []);
})
.done(function(commitId) {
.then(function(commitId) {
console.log("New Commit: ", commitId);
});
2 changes: 1 addition & 1 deletion examples/details-for-tree-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
});
});
})
.done(function() {
.then(function() {
console.log("Done!");
});
2 changes: 1 addition & 1 deletion examples/diff-commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))

return commit.getDiff();
})
.done(function(diffList) {
.then(function(diffList) {
diffList.forEach(function(diff) {
diff.patches().forEach(function(patch) {
console.log("diff", patch.oldFile().path(), patch.newFile().path());
Expand Down
2 changes: 1 addition & 1 deletion examples/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
return nodegit.Cred.sshKeyFromAgent(userName);
}
});
}).done(function() {
}).then(function() {
console.log("It worked!");
});
4 changes: 2 additions & 2 deletions examples/general.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var nodegit = require("../");
var path = require("path");
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var oid;
var odb;
var repo;
Expand Down Expand Up @@ -362,6 +362,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
return Promise.all(promises);
})

.done(function() {
.then(function() {
console.log("Done!");
});
8 changes: 4 additions & 4 deletions examples/index-add-and-remove.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var nodegit = require("../");
var path = require("path");
var Promise = require("nodegit-promise");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var Promise = require("bluebird");
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["writeFile"]);

nodegit.Repository.open(path.resolve(__dirname, "../.git"))
.then(function(repo) {
Expand Down Expand Up @@ -129,6 +129,6 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
console.log("New files in index: " + newFiles.length);
});
});
}).done(function() {
}).then(function() {
console.log("All done!");
});
7 changes: 3 additions & 4 deletions examples/merge-cleanly.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var nodegit = require("../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
fse.ensureDir = promisify(fse.ensureDir);
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["remove", "ensureDir", "writeFile"]);

var ourFileName = "ourNewFile.txt";
var ourFileContent = "I like Toll Roads. I have an EZ-Pass!";
Expand Down Expand Up @@ -123,7 +122,7 @@ fse.remove(path.resolve(__dirname, repoDir))
return repository.createCommit(ourBranch.name(), ourSignature,
ourSignature, "we merged their commit", oid, [ourCommit, theirCommit]);
})
.done(function(commitId) {
.then(function(commitId) {
// We never changed the HEAD after the initial commit;
// it should still be the same as master.
console.log("New Commit: ", commitId);
Expand Down
10 changes: 5 additions & 5 deletions examples/merge-with-conflicts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var nodegit = require("../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
fse.ensureDir = promisify(fse.ensureDir);
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["remove", "ensureDir", "writeFile"]);
var fs = require("fs");

var repoDir = "../../newRepo";
var fileName = "newFile.txt";
Expand Down Expand Up @@ -163,7 +163,7 @@ fse.remove(path.resolve(__dirname, repoDir))

// if the merge had comflicts, solve them
// (in this case, we simply overwrite the file)
fse.writeFileSync(
fs.writeFileSync(
path.join(repository.workdir(), fileName),
finalFileContent
);
Expand All @@ -187,6 +187,6 @@ fse.remove(path.resolve(__dirname, repoDir))
return repository.createCommit(ourBranch.name(), baseSignature,
baseSignature, "Stop this bob sized fued", oid, [ourCommit, theirCommit]);
})
.done(function(commitId) {
.then(function(commitId) {
console.log("New Commit: ", commitId);
});
2 changes: 1 addition & 1 deletion examples/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ nodegit.Repository.open(path.resolve(__dirname, repoDir))
.then(function() {
return repository.mergeBranches("master", "origin/master");
})
.done(function() {
.then(function() {
console.log("Done!");
});
7 changes: 3 additions & 4 deletions examples/push.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var nodegit = require("../");
var path = require("path");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
fse.ensureDir = promisify(fse.ensureDir);
var promisify = require("thenify-all");
var fse = promisify(require("fs-extra"), ["remove", "ensureDir", "writeFile"]);

var fileName = "newFile.txt";
var fileContent = "hello world";
Expand Down Expand Up @@ -64,6 +63,6 @@ fse.remove(path.resolve(__dirname, repoDir))
repository.defaultSignature(),
"Push to master");
});
}).done(function() {
}).then(function() {
console.log("Done!");
});
2 changes: 1 addition & 1 deletion examples/read-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
console.log(firstTenLines);
console.log("...");
})
.done();
.then();
2 changes: 1 addition & 1 deletion examples/remove-and-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
// from the filesystem.
console.log("New Commit:", commitId.allocfmt());
})
.done();
.then();
2 changes: 1 addition & 1 deletion examples/walk-history-for-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
// Don't forget to call `start()`!
history.start();
})
.done();
.then();
2 changes: 1 addition & 1 deletion examples/walk-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
// Don't forget to call `start()`!
history.start();
})
.done();
.then();
2 changes: 1 addition & 1 deletion examples/walk-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ nodegit.Repository.open(path.resolve(__dirname, "../.git"))
// Don't forget to call `start()`!
walker.start();
})
.done();
.then();
4 changes: 1 addition & 3 deletions generate/scripts/generateMissingTests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const path = require("path");
const Promise = require("nodegit-promise");
const promisify = require("promisify-node");
const fse = promisify(require("fs-extra"));
const Promise = require("bluebird");
const utils = require("./utils");

const testFilesPath = "../test/tests";
Expand Down
9 changes: 3 additions & 6 deletions generate/scripts/generateNativeCode.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const path = require("path");
const promisify = require("promisify-node");
const fse = promisify(require("fs-extra"));
const exec = promisify(function(command, opts, callback) {
return require("child_process").exec(command, opts, callback);
});

const promisify = require("thenify-all");
const fse = promisify(require("fs-extra"), ["remove", 'copy']);
const exec = promisify(require("child_process").exec);
const utils = require("./utils");

module.exports = function generateNativeCode() {
Expand Down
4 changes: 2 additions & 2 deletions generate/scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const promisify = require("promisify-node");
const fse = require("fs-extra");
const promisify = require("thenify-all");
const fse = require("fs-extra", []);

const fs = require("fs");
const path = require("path");
Expand Down
4 changes: 2 additions & 2 deletions generate/templates/templates/nodegit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Promise = require("nodegit-promise");
var promisify = require("promisify-node");
var Promise = require("bluebird");
var promisify = require("thenify-all");
var rawApi;

// Attempt to load the production release first, if it fails fall back to the
Expand Down
2 changes: 1 addition & 1 deletion guides/repositories/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ NodeGit.Repository.open(pathToRepo).then(function (sucessfulResult) {
// This is the first function of the then which contains the successfully
// calculated result of the promise
})
.done(function () {
.then(function () {
// If we have a .done then the error will be thrown if there was an error that
// wasn't caught by either providing a 2nd function to the `.then` or a
// `.catch` function
Expand Down
2 changes: 1 addition & 1 deletion guides/repositories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ NodeGit.Repository.open(pathToRepo).then(function (repo) {
// You can also provide a catch function which will contain the reason why
// any above promises that weren't handled have failed
})
.done(function() {
.then(function() {
// If we have a .done then the error will be thrown if there was an error that
// wasn't caught by either providing a 2nd function to the `.then` or a
// `.catch` function
Expand Down
2 changes: 1 addition & 1 deletion lib/commit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var events = require("events");
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var NodeGit = require("../");
var Commit = NodeGit.Commit;
var LookupWrapper = NodeGit.Utils.lookupWrapper;
Expand Down
2 changes: 1 addition & 1 deletion lib/convenient_hunk.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var NodeGit = require("../");
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var ConvenientLine = NodeGit.ConvenientLine;

function ConvenientHunk(hunk, linesInHunk, patch, i) {
Expand Down
2 changes: 1 addition & 1 deletion lib/convenient_patch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var NodeGit = require("../");
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var Diff = NodeGit.Diff;
var ConvenientHunk = NodeGit.ConvenientHunk;

Expand Down
2 changes: 1 addition & 1 deletion lib/diff.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var NodeGit = require("../");
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var Diff = NodeGit.Diff;
var ConvenientPatch = NodeGit.ConvenientPatch;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
Expand Down
2 changes: 1 addition & 1 deletion lib/merge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var NodeGit = require("../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var Promise = require("nodegit-promise");
var Promise = require("bluebird");

var Merge = NodeGit.Merge;
var mergeCommits = Merge.commits;
Expand Down
2 changes: 1 addition & 1 deletion lib/repository.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var NodeGit = require("../");
var Blob = NodeGit.Blob;
var Checkout = NodeGit.Checkout;
Expand Down
2 changes: 1 addition & 1 deletion lib/revwalk.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var NodeGit = require("../");
var Revwalk = NodeGit.Revwalk;
var Promise = require("nodegit-promise");
var Promise = require("bluebird");

var oldSorting = Revwalk.prototype.sorting;

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/lookup_wrapper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var NodeGit = require("../../");

/**
Expand Down
2 changes: 1 addition & 1 deletion lifecycleScripts/checkPrepared.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Promise = require("nodegit-promise");
var Promise = require("bluebird");
var path = require("path");
var fs = require("fs");
var rooted = path.join.bind(path, __dirname, "..");
Expand Down
2 changes: 1 addition & 1 deletion lifecycleScripts/clean.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var fse = require("fs-extra");
var path = require("path");
var npm = require("npm");
var Promise = require("nodegit-promise");
var Promise = require("bluebird");

var rooted = path.join.bind(path, __dirname, "..");
if (fse.existsSync(rooted(".didntcomefromthenpmregistry"))) {
Expand Down
4 changes: 2 additions & 2 deletions lifecycleScripts/install.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var Promise = require("nodegit-promise");
var promisify = require("promisify-node");
var Promise = require("bluebird");
var promisify = require("thenify-all");
var path = require("path");
var fs = require("fs");

Expand Down
Loading

0 comments on commit 2e0a0c6

Please sign in to comment.