mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-06 23:26:25 +03:00
Support getting status of entire repository
New Git.getAllStatuses() method returns all non-ignored status entries in the repository.
This commit is contained in:
parent
69f79b940b
commit
4add7b6213
@ -8,6 +8,14 @@ namespace v8_extensions {
|
||||
private:
|
||||
git_repository *repo;
|
||||
|
||||
static int CollectStatus(const char *path, unsigned int status, void *payload) {
|
||||
if ((status & GIT_STATUS_IGNORED) == 0) {
|
||||
std::map<const char*, unsigned int> *statuses = (std::map<const char*, unsigned int> *) payload;
|
||||
statuses->insert(std::pair<const char*, unsigned int>(path, status));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
GitRepository(const char *pathInRepo) {
|
||||
if (git_repository_open_ext(&repo, pathInRepo, 0, NULL) != GIT_OK) {
|
||||
@ -55,6 +63,17 @@ namespace v8_extensions {
|
||||
return CefV8Value::CreateNull();
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> GetStatuses() {
|
||||
std::map<const char*, unsigned int> statuses;
|
||||
git_status_foreach(repo, CollectStatus, &statuses);
|
||||
std::map<const char*, unsigned int>::iterator iter = statuses.begin();
|
||||
CefRefPtr<CefV8Value> v8Statuses = CefV8Value::CreateObject(NULL);
|
||||
for (; iter != statuses.end(); ++iter) {
|
||||
v8Statuses->SetValue(iter->first, CefV8Value::CreateInt(iter->second), V8_PROPERTY_ATTRIBUTE_NONE);
|
||||
}
|
||||
return v8Statuses;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> IsIgnored(const char *path) {
|
||||
int ignored;
|
||||
if (git_ignore_path_is_ignored(&ignored, repo, path) == GIT_OK) {
|
||||
@ -190,7 +209,7 @@ namespace v8_extensions {
|
||||
void Git::CreateContextBinding(CefRefPtr<CefV8Context> context) {
|
||||
const char* methodNames[] = {
|
||||
"getRepository", "getHead", "getPath", "isIgnored", "getStatus", "checkoutHead",
|
||||
"getDiffStats", "isSubmodule", "refreshIndex", "destroy"
|
||||
"getDiffStats", "isSubmodule", "refreshIndex", "destroy", "getStatuses"
|
||||
};
|
||||
|
||||
CefRefPtr<CefV8Value> nativeObject = CefV8Value::CreateObject(NULL);
|
||||
@ -277,6 +296,12 @@ namespace v8_extensions {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (name == "getStatuses") {
|
||||
GitRepository *userData = (GitRepository *)object->GetUserData().get();
|
||||
retval = userData->GetStatuses();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -147,3 +147,25 @@ describe "Git", ->
|
||||
expect(repo.getDiffStats(path)).toEqual {added: 0, deleted: 0}
|
||||
fs.write(path, "#{originalPathText} edited line")
|
||||
expect(repo.getDiffStats(path)).toEqual {added: 1, deleted: 1}
|
||||
|
||||
describe ".getStatuses()", ->
|
||||
[newPath, modifiedPath, cleanPath, originalModifiedPathText] = []
|
||||
|
||||
beforeEach ->
|
||||
repo = new Git(require.resolve('fixtures/git/working-dir'))
|
||||
modifiedPath = fixturesProject.resolve('git/working-dir/file.txt')
|
||||
originalModifiedPathText = fs.read(modifiedPath)
|
||||
newPath = fixturesProject.resolve('git/working-dir/untracked.txt')
|
||||
cleanPath = fixturesProject.resolve('git/working-dir/other.txt')
|
||||
fs.write(newPath, '')
|
||||
|
||||
afterEach ->
|
||||
fs.write(modifiedPath, originalModifiedPathText)
|
||||
fs.remove(newPath) if fs.exists(newPath)
|
||||
|
||||
it "returns status information for all new and modified files", ->
|
||||
fs.write(modifiedPath, 'making this path modified')
|
||||
statuses = repo.getAllStatuses()
|
||||
expect(statuses[cleanPath]).toBeUndefined()
|
||||
expect(repo.isStatusNew(statuses[repo.relativize(newPath)])).toBeTruthy()
|
||||
expect(repo.isStatusModified(statuses[repo.relativize(modifiedPath)])).toBeTruthy()
|
||||
|
@ -54,6 +54,9 @@ class Git
|
||||
getPathStatus: (path) ->
|
||||
pathStatus = @getRepo().getStatus(@relativize(path))
|
||||
|
||||
getAllStatuses: (path) ->
|
||||
@getRepo().getStatuses()
|
||||
|
||||
isPathIgnored: (path) ->
|
||||
@getRepo().isIgnored(@relativize(path))
|
||||
|
||||
|
@ -10,6 +10,7 @@ class GitRepository
|
||||
getHead: $git.getHead
|
||||
getPath: $git.getPath
|
||||
getStatus: $git.getStatus
|
||||
getStatuses: $git.getStatuses
|
||||
isIgnored: $git.isIgnored
|
||||
checkoutHead: $git.checkoutHead
|
||||
getDiffStats: $git.getDiffStats
|
||||
|
Loading…
Reference in New Issue
Block a user