mirror of
https://github.com/godotengine/godot-git-plugin.git
synced 2026-01-03 10:09:43 +03:00
Implement git status
This commit is contained in:
7
demo/.gitignore
vendored
Normal file
7
demo/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Import cache
|
||||
.import/
|
||||
|
||||
# Binaries
|
||||
bin/
|
||||
build/
|
||||
lib/
|
||||
Binary file not shown.
Binary file not shown.
@@ -17,7 +17,6 @@ void GitAPI::_register_methods() {
|
||||
register_method("_get_vcs_name", &GitAPI::_get_vcs_name);
|
||||
register_method("_initialize", &GitAPI::_initialize);
|
||||
register_method("_shut_down", &GitAPI::_shut_down);
|
||||
register_method("_stage_all", &GitAPI::_stage_all);
|
||||
register_method("_stage_file", &GitAPI::_stage_file);
|
||||
}
|
||||
|
||||
@@ -53,31 +52,17 @@ void GitAPI::_commit(const String p_msg) {
|
||||
git_signature_free(sig);
|
||||
}
|
||||
|
||||
void GitAPI::_stage_all() {
|
||||
void GitAPI::_stage_file(const String p_file_path) {
|
||||
|
||||
git_index_matched_path_cb matched_cb = NULL;
|
||||
git_index *index;
|
||||
git_strarray array = { 0 };
|
||||
int options = 0, count = 0;
|
||||
StatusPayload payload;
|
||||
|
||||
GIT2_CALL(git_repository_index(&index, repo), "Could not get repository index", NULL);
|
||||
ERR_FAIL_NULL(repo);
|
||||
char *c_path = p_file_path.alloc_c_string();
|
||||
GIT2_CALL(git_index_open(&index, c_path), "Could not load file to index", c_path);
|
||||
GIT2_CALL(git_index_add_bypath(index, c_path), "Could not stage file", c_path);
|
||||
|
||||
matched_cb = &status_callback;
|
||||
|
||||
payload.repo = repo;
|
||||
|
||||
GIT2_CALL(git_index_add_all(index, &array, 0, matched_cb, &payload), "Could not stage in repository", NULL);
|
||||
GIT2_CALL(git_index_update_all(index, &array, matched_cb, &payload), "Could not update in repository", NULL);
|
||||
|
||||
GIT2_CALL(git_index_write(index), "Could not write index object", NULL);
|
||||
git_index_free(index);
|
||||
}
|
||||
|
||||
void GitAPI::_stage_file(const String file_path) {
|
||||
}
|
||||
|
||||
void GitAPI::create_gitignore() {
|
||||
|
||||
File *file = File::_new();
|
||||
@@ -86,28 +71,17 @@ void GitAPI::create_gitignore() {
|
||||
|
||||
file->open("res://.gitignore", File::ModeFlags::WRITE);
|
||||
file->store_string(
|
||||
"# Import cache"
|
||||
"\n"
|
||||
".import/"
|
||||
"\n"
|
||||
"\n"
|
||||
"# Binaries"
|
||||
"\n"
|
||||
"bin/"
|
||||
"\n"
|
||||
"build/"
|
||||
"\n"
|
||||
"lib/"
|
||||
"\n");
|
||||
"# Import cache\n"
|
||||
".import/\n\n"
|
||||
"# Binaries\n"
|
||||
"bin/\n"
|
||||
"build/\n"
|
||||
"lib/\n"
|
||||
);
|
||||
file->close();
|
||||
}
|
||||
}
|
||||
|
||||
void GitAPI::create_initial_commit() {
|
||||
|
||||
_commit("Initial commit");
|
||||
}
|
||||
|
||||
Control *GitAPI::_get_initialization_settings_panel_container() {
|
||||
|
||||
init_settings_panel_container = memnew(PanelContainer);
|
||||
@@ -125,18 +99,47 @@ bool GitAPI::_get_is_vcs_intialized() {
|
||||
Dictionary GitAPI::_get_modified_files_data() {
|
||||
|
||||
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
|
||||
opts.flags += GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
|
||||
opts.flags += GIT_STATUS_OPT_INCLUDE_UNTRACKED;
|
||||
opts.flags += GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
|
||||
opts.flags += GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX;
|
||||
git_status_list *statuses = NULL;
|
||||
GIT2_CALL(git_status_list_new(&statuses, repo, &opts), "Could not get status information from repository", NULL);
|
||||
|
||||
Dictionary diff;
|
||||
Dictionary diff; // Schema is <file_path, status>
|
||||
size_t count = git_status_list_entrycount(statuses);
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
|
||||
const git_status_entry *entry = git_status_byindex(statuses, i);
|
||||
|
||||
switch (entry->status) {
|
||||
|
||||
case GIT_STATUS_INDEX_NEW: { // GIT_STATUS_WT???
|
||||
|
||||
diff[entry->head_to_index->new_file.path] = "new";
|
||||
} break;
|
||||
case GIT_STATUS_INDEX_MODIFIED: {
|
||||
|
||||
diff[entry->head_to_index->new_file.path] = "modified";
|
||||
} break;
|
||||
case GIT_STATUS_INDEX_RENAMED: {
|
||||
|
||||
diff[entry->head_to_index->new_file.path] = "renamed";
|
||||
} break;
|
||||
case GIT_STATUS_INDEX_DELETED: {
|
||||
|
||||
diff[entry->head_to_index->new_file.path] = "deleted";
|
||||
} break;
|
||||
case GIT_STATUS_INDEX_TYPECHANGE: {
|
||||
|
||||
diff[entry->head_to_index->new_file.path] = "typechange";
|
||||
} break;
|
||||
}
|
||||
printf("%s", entry->head_to_index->new_file.path);
|
||||
}
|
||||
|
||||
git_status_list_free(statuses);
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
@@ -160,22 +163,21 @@ bool GitAPI::_initialize(const String p_project_root_path) {
|
||||
WARN_PRINT("Multiple libgit2 instances are running");
|
||||
}
|
||||
|
||||
char *c_path = p_project_root_path.alloc_c_string();
|
||||
git_repository_init(&repo, c_path, 0); //GIT2_CALL(, "Could not initialize repository", NULL);
|
||||
if (is_initialized) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GIT2_CALL(git_repository_init(&repo, p_project_root_path.alloc_c_string(), 0), "Could not initialize repository", NULL);
|
||||
if (repo) {
|
||||
|
||||
WARN_PRINT("Initialized empty Git repository in res://");
|
||||
is_initialized = true;
|
||||
|
||||
create_gitignore();
|
||||
create_initial_commit();
|
||||
_commit("Initial Commit");
|
||||
}
|
||||
|
||||
GIT2_CALL(git_repository_open(&repo, p_project_root_path.alloc_c_string()), "Could not open repository", false);
|
||||
if (repo) {
|
||||
|
||||
WARN_PRINT("Git API was initialised successfully");
|
||||
is_initialized = true;
|
||||
}
|
||||
|
||||
return is_initialized;
|
||||
}
|
||||
|
||||
@@ -30,23 +30,21 @@ class GitAPI : public EditorVCSInterface {
|
||||
git_signature *author;
|
||||
git_signature *committer;
|
||||
|
||||
public:
|
||||
static void _register_methods();
|
||||
|
||||
void _commit(const String msg);
|
||||
void _commit(const String p_msg);
|
||||
Control *_get_commit_dock_panel_container();
|
||||
Control *_get_initialization_settings_panel_container();
|
||||
bool _get_is_vcs_intialized();
|
||||
Dictionary _get_modified_files_data();
|
||||
String _get_project_name();
|
||||
String _get_vcs_name();
|
||||
bool _initialize(const String project_root_path);
|
||||
bool _initialize(const String p_project_root_path);
|
||||
bool _shut_down();
|
||||
void _stage_all();
|
||||
void _stage_file(const String file_path);
|
||||
void _stage_file(const String p_file_path);
|
||||
|
||||
public:
|
||||
static void _register_methods();
|
||||
|
||||
void create_gitignore();
|
||||
void create_initial_commit();
|
||||
|
||||
void _init();
|
||||
void _process();
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <git_common.h>
|
||||
|
||||
|
||||
int status_callback(const char *p_path, const char *p_matched_pathspec, void *p_payload);
|
||||
|
||||
#endif // !GIT_CALLBACKS_H
|
||||
|
||||
@@ -18,9 +18,9 @@ void check_git2_errors(int error, const char *message, const char *extra) {
|
||||
|
||||
if (extra) {
|
||||
|
||||
printf("%s '%s' [%d]%s%s\n", message, extra, error, lg2spacer, lg2msg);
|
||||
printf("Git API: %s '%s' [%d]%s%s\n", message, extra, error, lg2spacer, lg2msg);
|
||||
} else {
|
||||
|
||||
printf("%s [%d]%s%s\n", message, error, lg2spacer, lg2msg);
|
||||
printf("Git API: %s [%d]%s%s\n", message, error, lg2spacer, lg2msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user