| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6decdd1 commit 39357aa
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,18 @@ | |||
| 1 | 1 | var NodeGit = require("../"); | |
| 2 | 2 | var TreeEntry = require("./tree_entry"); | |
| 3 | + var LookupWrapper = require("./util/lookupWrapper"); | ||
| 3 | 4 | ||
| 4 | 5 | var Blob = NodeGit.Blob; | |
| 5 | 6 | ||
| 7 | + /** | ||
| 8 | + * Retrieves the blob pointed to by the oid | ||
| 9 | + * @param {Repository} repo The repo that the blob lives in | ||
| 10 | + * @param {String|Oid|Blob} id The blob to lookup | ||
| 11 | + * @param {Function} callback | ||
| 12 | + * @return {Blob} | ||
| 13 | + */ | ||
| 14 | + Blob.lookup = LookupWrapper(Blob); | ||
| 15 | + | ||
| 6 | 16 | /** | |
| 7 | 17 | * Retrieve the content of the Blob. | |
| 8 | 18 | * | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,19 @@ | |||
| 1 | 1 | var events = require("events"); | |
| 2 | 2 | var Promise = require("nodegit-promise"); | |
| 3 | 3 | var NodeGit = require("../"); | |
| 4 | + var LookupWrapper = require("./util/lookupWrapper"); | ||
| 4 | 5 | ||
| 5 | 6 | var Commit = NodeGit.Commit; | |
| 6 | 7 | ||
| 8 | + /** | ||
| 9 | + * Retrieves the commit pointed to by the oid | ||
| 10 | + * @param {Repository} repo The repo that the commit lives in | ||
| 11 | + * @param {String|Oid|Commit} id The commit to lookup | ||
| 12 | + * @param {Function} callback | ||
| 13 | + * @return {Commit} | ||
| 14 | + */ | ||
| 15 | + Commit.lookup = LookupWrapper(Commit); | ||
| 16 | + | ||
| 7 | 17 | /** | |
| 8 | 18 | * Retrieve the SHA. | |
| 9 | 19 | * @return {String} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | var NodeGit = require("../"); | |
| 2 | 2 | var normalizeOptions = require("./util/normalize_options"); | |
| 3 | + var Promise = require("nodegit-promise"); | ||
| 3 | 4 | ||
| 4 | 5 | var Merge = NodeGit.Merge; | |
| 5 | 6 | var mergeCommits = Merge.commits; | |
@@ -16,7 +17,12 @@ var mergeCommits = Merge.commits; | |||
| 16 | 17 | Merge.commits = function(repo, ourCommit, theirCommit, options) { | |
| 17 | 18 | options = normalizeOptions(options, NodeGit.MergeOptions); | |
| 18 | 19 | ||
| 19 | - return mergeCommits.call(this, repo, ourCommit, theirCommit, options); | ||
| 20 | + return Promise.all([ | ||
| 21 | + repo.getCommit(ourCommit), | ||
| 22 | + repo.getCommit(theirCommit) | ||
| 23 | + ]).then(function(commits) { | ||
| 24 | + return mergeCommits.call(this, repo, commits[0], commits[1], options); | ||
| 25 | + }); | ||
| 20 | 26 | }; | |
| 21 | 27 | ||
| 22 | 28 | module.exports = Merge; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,18 @@ | |||
| 1 | 1 | var NodeGit = require("../"); | |
| 2 | + var LookupWrapper = require("./util/lookupWrapper"); | ||
| 2 | 3 | ||
| 3 | 4 | var Reference = NodeGit.Reference; | |
| 4 | 5 | var Branch = NodeGit.Branch; | |
| 5 | 6 | ||
| 7 | + /** | ||
| 8 | + * Retrieves the reference pointed to by the oid | ||
| 9 | + * @param {Repository} repo The repo that the reference lives in | ||
| 10 | + * @param {String|Reference} id The reference to lookup | ||
| 11 | + * @param {Function} callback | ||
| 12 | + * @return {Reference} | ||
| 13 | + */ | ||
| 14 | + Reference.lookup = LookupWrapper(Reference); | ||
| 15 | + | ||
| 6 | 16 | /** | |
| 7 | 17 | * Returns true if this reference is valid | |
| 8 | 18 | * @return {Boolean} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,12 +55,14 @@ function(name, commit, force, signature, logMessage) { | |||
| 55 | 55 | /** | |
| 56 | 56 | * Look up a branch | |
| 57 | 57 | * | |
| 58 | - * @param {String} name Branch name, e.g. "master" | ||
| 58 | + * @param {String|Ref} name Branch name, e.g. "master" or Branch Ref | ||
| 59 | 59 | * @param {Function} callback | |
| 60 | 60 | * @return {Ref} | |
| 61 | 61 | */ | |
| 62 | 62 | Repository.prototype.getBranch = function(name, callback) { | |
| 63 | - name = ~name.indexOf("refs/heads/") ? name : "refs/heads/" + name; | ||
| 63 | + name = name instanceof Reference || ~name.indexOf("refs/heads/") | ||
| 64 | + ? name | ||
| 65 | + : "refs/heads/" + name; | ||
| 64 | 66 | ||
| 65 | 67 | return this.getReference(name).then(function(reference) { | |
| 66 | 68 | if (typeof callback === "function") { | |
@@ -74,7 +76,7 @@ Repository.prototype.getBranch = function(name, callback) { | |||
| 74 | 76 | /** | |
| 75 | 77 | * Look up a branch's most recent commit. | |
| 76 | 78 | * | |
| 77 | - * @param {String} name Branch name, e.g. "master" | ||
| 79 | + * @param {String|Ref} name Branch name, e.g. "master" or Branch Ref | ||
| 78 | 80 | * @param {Function} callback | |
| 79 | 81 | * @return {Commit} | |
| 80 | 82 | */ | |
@@ -331,40 +333,40 @@ Repository.prototype.getHeadCommit = function(callback) { | |||
| 331 | 333 | Repository.prototype.createCommit = function( | |
| 332 | 334 | updateRef, author, committer, message, tree, parents, callback) { | |
| 333 | 335 | ||
| 334 | - var createCommit = null; | ||
| 335 | 336 | var repo = this; | |
| 337 | + var promises = []; | ||
| 336 | 338 | ||
| 337 | - if (tree instanceof Tree) { | ||
| 338 | - createCommit = Promise.all([ | ||
| 339 | - Commit.create( | ||
| 340 | - repo, | ||
| 341 | - updateRef, | ||
| 342 | - author, | ||
| 343 | - committer, | ||
| 344 | - null /* use default message encoding */, | ||
| 345 | - message, | ||
| 346 | - tree, | ||
| 347 | - parents.length, | ||
| 348 | - parents | ||
| 349 | - ) | ||
| 350 | - ]); | ||
| 351 | - } else { | ||
| 352 | - createCommit = this.getTree(tree).then(function(tree) { | ||
| 353 | - return Commit.create( | ||
| 354 | - repo, | ||
| 355 | - updateRef, | ||
| 356 | - author, | ||
| 357 | - committer, | ||
| 358 | - null /* use default message encoding */, | ||
| 359 | - message, | ||
| 360 | - tree, | ||
| 361 | - parents.length, | ||
| 362 | - parents | ||
| 363 | - ); | ||
| 364 | - }); | ||
| 365 | - } | ||
| 339 | + parents = parents || []; | ||
| 340 | + | ||
| 341 | + promises.push(repo.getTree(tree)); | ||
| 342 | + | ||
| 343 | + parents.forEach(function(parent) { | ||
| 344 | + promises.push(repo.getCommit(parent)); | ||
| 345 | + }); | ||
| 366 | 346 | ||
| 367 | - return createCommit.then(function(commit) { | ||
| 347 | + return Promise.all(promises).then(function(results) { | ||
| 348 | + tree = results[0]; | ||
| 349 | + | ||
| 350 | + // Get the normalized values for our input into the function | ||
| 351 | + var parentsLength = parents.length; | ||
| 352 | + parents = []; | ||
| 353 | + | ||
| 354 | + for (var i = 0; i < parentsLength; i++) { | ||
| 355 | + parents.push(results[i + 1]); | ||
| 356 | + } | ||
| 357 | + | ||
| 358 | + return Commit.create( | ||
| 359 | + repo, | ||
| 360 | + updateRef, | ||
| 361 | + author, | ||
| 362 | + committer, | ||
| 363 | + null /* use default message encoding */, | ||
| 364 | + message, | ||
| 365 | + tree, | ||
| 366 | + parents.length, | ||
| 367 | + parents | ||
| 368 | + ); | ||
| 369 | + }).then(function(commit) { | ||
| 368 | 370 | if (typeof callback === "function") { | |
| 369 | 371 | callback(null, commit); | |
| 370 | 372 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,15 @@ | |||
| 1 | 1 | var git = require("../"); | |
| 2 | + var LookupWrapper = require("./util/lookupWrapper"); | ||
| 2 | 3 | ||
| 3 | 4 | var Tag = git.Tag; | |
| 4 | 5 | ||
| 6 | + /** | ||
| 7 | + * Retrieves the tag pointed to by the oid | ||
| 8 | + * @param {Repository} repo The repo that the tag lives in | ||
| 9 | + * @param {String|Oid|Tag} id The tag to lookup | ||
| 10 | + * @param {Function} callback | ||
| 11 | + * @return {Tag} | ||
| 12 | + */ | ||
| 13 | + Tag.lookup = LookupWrapper(Tag); | ||
| 14 | + | ||
| 5 | 15 | module.exports = Tag; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,16 @@ var Tree = git.Tree; | |||
| 3 | 3 | var Treebuilder = git.Treebuilder; | |
| 4 | 4 | var Diff = git.Diff; | |
| 5 | 5 | var events = require("events"); | |
| 6 | + var LookupWrapper = require("./util/lookupWrapper"); | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * Retrieves the tree pointed to by the oid | ||
| 10 | + * @param {Repository} repo The repo that the tree lives in | ||
| 11 | + * @param {String|Oid|Tree} id The tree to lookup | ||
| 12 | + * @param {Function} callback | ||
| 13 | + * @return {Tree} | ||
| 14 | + */ | ||
| 15 | + Tree.lookup = LookupWrapper(Tree); | ||
| 6 | 16 | ||
| 7 | 17 | /** | |
| 8 | 18 | * Diff two trees | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 1 | + var Promise = require("nodegit-promise"); | ||
| 2 | + | ||
| 3 | + /** | ||
| 4 | + * Wraps a method so that you can pass in either a string, OID or the object | ||
| 5 | + * itself and you will always get back a promise that resolves to the object. | ||
| 6 | + * @param {Object} objectType The object type that you're expecting to receive. | ||
| 7 | + * @param {Function} lookupFunction The function to do the lookup for the | ||
| 8 | + * object. Defaults to `objectType.lookup`. | ||
| 9 | + * @return {Function} | ||
| 10 | + */ | ||
| 11 | + module.exports = function(objectType, lookupFunction) { | ||
| 12 | + lookupFunction = lookupFunction || objectType.lookup; | ||
| 13 | + | ||
| 14 | + return function(repo, id, callback) { | ||
| 15 | + if (id instanceof objectType) { | ||
| 16 | + return Promise.resolve(id).then(function(obj) { | ||
| 17 | + obj.repo = repo; | ||
| 18 | + | ||
| 19 | + if (typeof callback === "function") { | ||
| 20 | + callback(null, obj); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + return obj; | ||
| 24 | + }, callback); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + return lookupFunction(repo, id).then(function(obj) { | ||
| 28 | + obj.repo = repo; | ||
| 29 | + | ||
| 30 | + if (typeof callback === "function") { | ||
| 31 | + callback(null, obj); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + return obj; | ||
| 35 | + }, callback); | ||
| 36 | + }; | ||
| 37 | + }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments