Skip to content

Commit edf5bb2

Browse files
author
John Haley
committed
Fixed tests and reimplemented missing functions on Repository
1 parent 22c58ce commit edf5bb2

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

lib/reference.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ var Branch = NodeGit.Branch;
1313
*/
1414
Reference.lookup = LookupWrapper(Reference);
1515

16+
/**
17+
* Retrieves the reference by it's short name
18+
* @param {Repository} repo The repo that the reference lives in
19+
* @param {String|Reference} id The reference to lookup
20+
* @param {Function} callback
21+
* @return {Reference}
22+
*/
23+
Reference.dwim = LookupWrapper(Reference, Reference.dwim);
24+
1625
/**
1726
* Returns true if this reference is valid
1827
* @return {Boolean}

lib/repository.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ function(name, commit, force, signature, logMessage) {
5555
/**
5656
* Look up a refs's commit.
5757
*
58-
* @param {String|Ref} name Ref name, e.g. "master", "refs/heads/master" or Branch Ref
58+
* @param {String|Ref} name Ref name, e.g. "master", "refs/heads/master"
59+
* or Branch Ref
5960
* @param {Function} callback
6061
* @return {Commit}
6162
*/
@@ -73,6 +74,30 @@ Repository.prototype.getReferenceCommit = function(name, callback) {
7374
}, callback);
7475
};
7576

77+
/**
78+
* Look up a branch. Alias for `getReference`
79+
*
80+
* @param {String|Ref} name Ref name, e.g. "master", "refs/heads/master"
81+
* or Branch Ref
82+
* @param {Function} callback
83+
* @return {Ref}
84+
*/
85+
Repository.prototype.getBranch = function(name, callback) {
86+
return this.getReference(name, callback);
87+
};
88+
89+
/**
90+
* Look up a branch's most recent commit. Alias to `getReferenceCommit`
91+
*
92+
* @param {String|Ref} name Ref name, e.g. "master", "refs/heads/master"
93+
* or Branch Ref
94+
* @param {Function} callback
95+
* @return {Commit}
96+
*/
97+
Repository.prototype.getBranchCommit = function(name, callback) {
98+
return this.getReferenceCommit(name, callback);
99+
};
100+
76101
/**
77102
* Gets the branch that HEAD currently points to
78103
* Is an alias to head()
@@ -85,17 +110,15 @@ Repository.prototype.getCurrentBranch = function() {
85110
/**
86111
* Lookup the reference with the given name.
87112
*
88-
* @param {String} name
113+
* @param {String|Ref} name Ref name, e.g. "master", "refs/heads/master"
114+
* or Branch Ref
89115
* @param {Function} callback
90116
* @return {Reference}
91117
*/
92118
Repository.prototype.getReference = function(name, callback) {
93119
var repository = this;
94-
var lookup = name.indexOf("refs/") === 0
95-
? Reference.lookup(this, name)
96-
: Reference.dwim(this, name);
97120

98-
return lookup.then(function(reference) {
121+
return Reference.dwim(this, name).then(function(reference) {
99122
if (reference.isSymbolic()) {
100123
return reference.resolve(function (error, reference) {
101124
reference.repo = repository;

test/tests/remote.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,10 @@ describe("Remote", function() {
104104
});
105105

106106
it("can fetch from a remote", function() {
107-
return this.repository.fetch("origin")
108-
.then(function() {
109-
assert(true);
110-
}, function() {
111-
assert(false);
107+
return this.repository.fetch("origin", {
108+
credentials: function(url, userName) {
109+
return NodeGit.Cred.sshKeyFromAgent(userName);
110+
}
112111
});
113112
});
114113
});

test/tests/repository.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ describe("Repository", function() {
4949

5050
it("can list remotes", function() {
5151
return this.repository.getRemotes().then(function(remotes) {
52-
assert.equal(remotes.count(), 1);
53-
assert.equal(remotes.strings(), "origin");
52+
assert.equal(remotes.length, 1);
53+
assert.equal(remotes[0], "origin");
5454
});
5555
});
5656

0 commit comments

Comments
 (0)