From e7334d81becda07c482f14ddf2b73e0afdd4d76d Mon Sep 17 00:00:00 2001 From: Martin Zagora Date: Fri, 14 Mar 2014 00:01:33 -0700 Subject: [PATCH] Fix not a git root --- src/Branch.js | 63 +++++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/src/Branch.js b/src/Branch.js index a6381fb5..e86bb32f 100644 --- a/src/Branch.js +++ b/src/Branch.js @@ -131,24 +131,13 @@ define(function (require, exports) { }); } - function _isRepository() { - return Main.gitControl.getGitStatus().then(function () { - return true; - }).fail(function (err) { - if (err.match(/not a git repository/i)) { - return false; - } - throw err; - }); - } - function _isRepositoryRoot() { - var currentFolder = Main.getProjectRoot(); - return q.ninvoke(FileSystem, "resolve", currentFolder).spread(function (directory) { - return q.ninvoke(directory, "getContents"); - }).spread(function (contents) { - return _.any(contents, function (content) { return content.name === ".git"; }); + var gitFolder = Main.getProjectRoot() + "/.git", + defer = q.defer(); + FileSystem.resolve(gitFolder, function (err, directory) { + defer.resolve(directory && !err ? true : false); }); + return defer.promise; } function refresh() { @@ -158,42 +147,32 @@ define(function (require, exports) { .parent() .show(); - return _isRepository().then(function (isRepo) { - $gitBranchName.parent().toggle(isRepo); + return _isRepositoryRoot().then(function (isRepositoryRoot) { + $gitBranchName.parent().toggle(isRepositoryRoot); - if (!isRepo) { + if (!isRepositoryRoot) { $gitBranchName .off("click") .text("not a git repo"); Panel.disable("not-repo"); return; } - - return _isRepositoryRoot().then(function (isRepositoryRoot) { - if (!isRepositoryRoot) { + + return Main.gitControl.getBranchName().then(function (branchName) { + $gitBranchName.text(branchName) + .off("click") + .on("click", toggleDropdown) + .append($("")); + Panel.enable(); + }).fail(function (ex) { + if (ex.match(/unknown revision/)) { $gitBranchName .off("click") - .text("not a git root"); - Panel.disable("not-root"); - return; - } - - return Main.gitControl.getBranchName().then(function (branchName) { - $gitBranchName.text(branchName) - .off("click") - .on("click", toggleDropdown) - .append($("")); + .text("no branch"); Panel.enable(); - }).fail(function (ex) { - if (ex.match(/unknown revision/)) { - $gitBranchName - .off("click") - .text("no branch"); - Panel.enable(); - } else { - throw ex; - } - }); + } else { + throw ex; + } }); }).fail(function (err) { throw ErrorHandler.showError(err);