Refresh the Git index when the window gains focus

Closes #121
This commit is contained in:
Kevin Sawicki
2013-01-07 17:29:20 -08:00
parent 1535930521
commit 146ae9d776
3 changed files with 21 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ var $git = {};
native function checkoutHead(path);
native function getDiffStats(path);
native function isSubmodule(path);
native function refreshIndex();
function GitRepository(path) {
var repo = getRepository(path);
@@ -24,5 +25,6 @@ var $git = {};
GitRepository.prototype.checkoutHead = checkoutHead;
GitRepository.prototype.getDiffStats = getDiffStats;
GitRepository.prototype.isSubmodule = isSubmodule;
GitRepository.prototype.refreshIndex = refreshIndex;
this.GitRepository = GitRepository;
})();

View File

@@ -69,12 +69,6 @@ public:
return CefV8Value::CreateInt(0);
}
git_index* index;
if (git_repository_index(&index, repo) == GIT_OK) {
git_index_read(index);
git_index_free(index);
}
unsigned int status = 0;
if (git_status_file(&status, repo, path) == GIT_OK) {
return CefV8Value::CreateInt(status);
@@ -192,7 +186,6 @@ public:
BOOL isSubmodule = false;
git_index* index;
if (git_repository_index(&index, repo) == GIT_OK) {
git_index_read(index);
const git_index_entry *entry = git_index_get_bypath(index, path, 0);
isSubmodule = entry != NULL && (entry->mode & S_IFMT) == GIT_FILEMODE_COMMIT;
git_index_free(index);
@@ -201,6 +194,14 @@ public:
return CefV8Value::CreateBool(isSubmodule);
}
void RefreshIndex() {
git_index* index;
if (exists && git_repository_index(&index, repo) == GIT_OK) {
git_index_read(index);
git_index_free(index);
}
}
IMPLEMENT_REFCOUNTING(GitRepository);
};
@@ -264,6 +265,12 @@ bool Git::Execute(const CefString& name,
return true;
}
if (name == "refreshIndex") {
GitRepository *userData = (GitRepository *)object->GetUserData().get();
userData->RefreshIndex();
return true;
}
return false;
}

View File

@@ -1,3 +1,5 @@
$ = require 'jquery'
module.exports =
class Git
@@ -15,6 +17,9 @@ class Git
constructor: (path) ->
@repo = new GitRepository(path)
$(window).on 'focus', => @refreshIndex()
refreshIndex: -> @repo.refreshIndex()
getPath: -> @repo.getPath()