Skip to content

Commit

Permalink
Fix not a git root
Browse files Browse the repository at this point in the history
  • Loading branch information
zaggino committed Mar 14, 2014
1 parent 5d69a98 commit e7334d8
Showing 1 changed file with 21 additions and 42 deletions.
63 changes: 21 additions & 42 deletions src/Branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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($("<span class='dropdown-arrow' />"));
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($("<span class='dropdown-arrow' />"));
.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);
Expand Down

0 comments on commit e7334d8

Please sign in to comment.