From abd41d120804f1d6c53078390f7baf149fd875ba Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Mon, 26 Oct 2015 16:35:57 +0100 Subject: [PATCH] Add .isSubmodule --- src/git-repository-async.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/git-repository-async.js b/src/git-repository-async.js index 79ebf359f..9fd8a9e1d 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -288,4 +288,21 @@ module.exports = class GitRepositoryAsync { return this.projectAtRoot } + + // Returns a {Promise} that resolves true if the given path is a submodule in + // the repository. + isSubmodule (_path) { + return this.repoPromise.then(function (repo) { + return repo.openIndex() + }).then(function (index) { + let entry = index.getByPath(_path) + let submoduleMode = 57344 // TODO compose this from libgit2 constants + + if (entry.mode === submoduleMode) { + return true + } else { + return false + } + }) + } }