Skip to content

Commit 62120eb

Browse files
authored
Merge pull request nodegit#1080 from novalis/dturner/issubmodule
add isSubmodule() method
2 parents 6eb5e38 + 8e7d035 commit 62120eb

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/tree_entry.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ TreeEntry.prototype.isDirectory = TreeEntry.prototype.isTree;
3131
*/
3232
TreeEntry.prototype.isBlob = TreeEntry.prototype.isFile;
3333

34+
/**
35+
* Is this TreeEntry a submodule?
36+
* @return {Boolean}
37+
*/
38+
TreeEntry.prototype.isSubmodule = function() {
39+
return this.filemode() === TreeEntry.FILEMODE.COMMIT;
40+
};
41+
3442
/**
3543
* Retrieve the SHA for this TreeEntry.
3644
* @return {String}

test/tests/tree_entry.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,35 @@ describe("TreeEntry", function() {
122122
});
123123
});
124124

125-
it("can determine if an entry is a directory", function() {
125+
it("can determine if an entry is not a file", function() {
126126
return this.commit.getEntry("example")
127127
.then(function(entry) {
128128
assert.equal(entry.isFile(), false);
129129
});
130130
});
131+
132+
it("can determine if an entry is a directory", function() {
133+
return this.commit.getEntry("example")
134+
.then(function(entry) {
135+
assert.equal(entry.isDirectory(), true);
136+
});
137+
});
138+
139+
it("can determine if an entry is a submodule", function() {
140+
var repo = this.repository;
141+
return repo.getCommit("878ef6efbc5f85c4f63aeedf41addc262a621308")
142+
.then(function(commit) {
143+
return commit.getEntry("vendor/libgit2")
144+
.then(function(entry) {
145+
assert.equal(entry.isSubmodule(), true);
146+
});
147+
});
148+
});
149+
150+
it("can determine if an entry is not a submodule", function() {
151+
return this.commit.getEntry("example")
152+
.then(function(entry) {
153+
assert.equal(entry.isSubmodule(), false);
154+
});
155+
});
131156
});

0 commit comments

Comments
 (0)