initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
This commit is contained in:
6
editor/version_control/SCsub
Normal file
6
editor/version_control/SCsub
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
|
||||
env.add_source_files(env.editor_sources, "*.cpp")
|
380
editor/version_control/editor_vcs_interface.cpp
Normal file
380
editor/version_control/editor_vcs_interface.cpp
Normal file
@@ -0,0 +1,380 @@
|
||||
/**************************************************************************/
|
||||
/* editor_vcs_interface.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "editor_vcs_interface.h"
|
||||
|
||||
#include "editor/editor_node.h"
|
||||
|
||||
EditorVCSInterface *EditorVCSInterface::singleton = nullptr;
|
||||
|
||||
void EditorVCSInterface::popup_error(const String &p_msg) {
|
||||
// TRANSLATORS: %s refers to the name of a version control system (e.g. "Git").
|
||||
EditorNode::get_singleton()->show_warning(p_msg.strip_edges(), vformat(TTR("%s Error"), get_vcs_name()));
|
||||
}
|
||||
|
||||
bool EditorVCSInterface::initialize(const String &p_project_path) {
|
||||
bool result = false;
|
||||
GDVIRTUAL_CALL(_initialize, p_project_path, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void EditorVCSInterface::set_credentials(const String &p_username, const String &p_password, const String &p_ssh_public_key, const String &p_ssh_private_key, const String &p_ssh_passphrase) {
|
||||
GDVIRTUAL_CALL(_set_credentials, p_username, p_password, p_ssh_public_key, p_ssh_private_key, p_ssh_passphrase);
|
||||
}
|
||||
|
||||
List<String> EditorVCSInterface::get_remotes() {
|
||||
TypedArray<String> result;
|
||||
if (!GDVIRTUAL_CALL(_get_remotes, result)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
List<String> remotes;
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
remotes.push_back(result[i]);
|
||||
}
|
||||
return remotes;
|
||||
}
|
||||
|
||||
List<EditorVCSInterface::StatusFile> EditorVCSInterface::get_modified_files_data() {
|
||||
TypedArray<Dictionary> result;
|
||||
if (!GDVIRTUAL_CALL(_get_modified_files_data, result)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
List<EditorVCSInterface::StatusFile> status_files;
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
status_files.push_back(_convert_status_file(result[i]));
|
||||
}
|
||||
return status_files;
|
||||
}
|
||||
|
||||
void EditorVCSInterface::stage_file(const String &p_file_path) {
|
||||
GDVIRTUAL_CALL(_stage_file, p_file_path);
|
||||
}
|
||||
|
||||
void EditorVCSInterface::unstage_file(const String &p_file_path) {
|
||||
GDVIRTUAL_CALL(_unstage_file, p_file_path);
|
||||
}
|
||||
|
||||
void EditorVCSInterface::discard_file(const String &p_file_path) {
|
||||
GDVIRTUAL_CALL(_discard_file, p_file_path);
|
||||
}
|
||||
|
||||
void EditorVCSInterface::commit(const String &p_msg) {
|
||||
GDVIRTUAL_CALL(_commit, p_msg);
|
||||
}
|
||||
|
||||
List<EditorVCSInterface::DiffFile> EditorVCSInterface::get_diff(const String &p_identifier, TreeArea p_area) {
|
||||
TypedArray<Dictionary> result;
|
||||
if (!GDVIRTUAL_CALL(_get_diff, p_identifier, int(p_area), result)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
List<DiffFile> diff_files;
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
diff_files.push_back(_convert_diff_file(result[i]));
|
||||
}
|
||||
return diff_files;
|
||||
}
|
||||
|
||||
List<EditorVCSInterface::Commit> EditorVCSInterface::get_previous_commits(int p_max_commits) {
|
||||
TypedArray<Dictionary> result;
|
||||
if (!GDVIRTUAL_CALL(_get_previous_commits, p_max_commits, result)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
List<EditorVCSInterface::Commit> commits;
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
commits.push_back(_convert_commit(result[i]));
|
||||
}
|
||||
return commits;
|
||||
}
|
||||
|
||||
List<String> EditorVCSInterface::get_branch_list() {
|
||||
TypedArray<String> result;
|
||||
if (!GDVIRTUAL_CALL(_get_branch_list, result)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
List<String> branch_list;
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
branch_list.push_back(result[i]);
|
||||
}
|
||||
return branch_list;
|
||||
}
|
||||
|
||||
void EditorVCSInterface::create_branch(const String &p_branch_name) {
|
||||
GDVIRTUAL_CALL(_create_branch, p_branch_name);
|
||||
}
|
||||
|
||||
void EditorVCSInterface::create_remote(const String &p_remote_name, const String &p_remote_url) {
|
||||
GDVIRTUAL_CALL(_create_remote, p_remote_name, p_remote_url);
|
||||
}
|
||||
|
||||
void EditorVCSInterface::remove_branch(const String &p_branch_name) {
|
||||
GDVIRTUAL_CALL(_remove_branch, p_branch_name);
|
||||
}
|
||||
|
||||
void EditorVCSInterface::remove_remote(const String &p_remote_name) {
|
||||
GDVIRTUAL_CALL(_remove_remote, p_remote_name);
|
||||
}
|
||||
|
||||
String EditorVCSInterface::get_current_branch_name() {
|
||||
String result;
|
||||
GDVIRTUAL_CALL(_get_current_branch_name, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool EditorVCSInterface::checkout_branch(const String &p_branch_name) {
|
||||
bool result = false;
|
||||
GDVIRTUAL_CALL(_checkout_branch, p_branch_name, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void EditorVCSInterface::pull(const String &p_remote) {
|
||||
GDVIRTUAL_CALL(_pull, p_remote);
|
||||
}
|
||||
|
||||
void EditorVCSInterface::push(const String &p_remote, bool p_force) {
|
||||
GDVIRTUAL_CALL(_push, p_remote, p_force);
|
||||
}
|
||||
|
||||
void EditorVCSInterface::fetch(const String &p_remote) {
|
||||
GDVIRTUAL_CALL(_fetch, p_remote);
|
||||
}
|
||||
|
||||
List<EditorVCSInterface::DiffHunk> EditorVCSInterface::get_line_diff(const String &p_file_path, const String &p_text) {
|
||||
TypedArray<Dictionary> result;
|
||||
if (!GDVIRTUAL_CALL(_get_line_diff, p_file_path, p_text, result)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
List<DiffHunk> diff_hunks;
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
diff_hunks.push_back(_convert_diff_hunk(result[i]));
|
||||
}
|
||||
return diff_hunks;
|
||||
}
|
||||
|
||||
bool EditorVCSInterface::shut_down() {
|
||||
bool result = false;
|
||||
GDVIRTUAL_CALL(_shut_down, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
String EditorVCSInterface::get_vcs_name() {
|
||||
String result;
|
||||
GDVIRTUAL_CALL(_get_vcs_name, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
Dictionary EditorVCSInterface::create_diff_line(int p_new_line_no, int p_old_line_no, const String &p_content, const String &p_status) {
|
||||
Dictionary diff_line;
|
||||
diff_line["new_line_no"] = p_new_line_no;
|
||||
diff_line["old_line_no"] = p_old_line_no;
|
||||
diff_line["content"] = p_content;
|
||||
diff_line["status"] = p_status;
|
||||
|
||||
return diff_line;
|
||||
}
|
||||
|
||||
Dictionary EditorVCSInterface::create_diff_hunk(int p_old_start, int p_new_start, int p_old_lines, int p_new_lines) {
|
||||
Dictionary diff_hunk;
|
||||
diff_hunk["new_lines"] = p_new_lines;
|
||||
diff_hunk["old_lines"] = p_old_lines;
|
||||
diff_hunk["new_start"] = p_new_start;
|
||||
diff_hunk["old_start"] = p_old_start;
|
||||
diff_hunk["diff_lines"] = TypedArray<Dictionary>();
|
||||
return diff_hunk;
|
||||
}
|
||||
|
||||
Dictionary EditorVCSInterface::add_line_diffs_into_diff_hunk(Dictionary p_diff_hunk, TypedArray<Dictionary> p_line_diffs) {
|
||||
p_diff_hunk["diff_lines"] = p_line_diffs;
|
||||
return p_diff_hunk;
|
||||
}
|
||||
|
||||
Dictionary EditorVCSInterface::create_diff_file(const String &p_new_file, const String &p_old_file) {
|
||||
Dictionary file_diff;
|
||||
file_diff["new_file"] = p_new_file;
|
||||
file_diff["old_file"] = p_old_file;
|
||||
file_diff["diff_hunks"] = TypedArray<Dictionary>();
|
||||
return file_diff;
|
||||
}
|
||||
|
||||
Dictionary EditorVCSInterface::create_commit(const String &p_msg, const String &p_author, const String &p_id, int64_t p_unix_timestamp, int64_t p_offset_minutes) {
|
||||
Dictionary commit_info;
|
||||
commit_info["message"] = p_msg;
|
||||
commit_info["author"] = p_author;
|
||||
commit_info["unix_timestamp"] = p_unix_timestamp;
|
||||
commit_info["offset_minutes"] = p_offset_minutes;
|
||||
commit_info["id"] = p_id;
|
||||
return commit_info;
|
||||
}
|
||||
|
||||
Dictionary EditorVCSInterface::add_diff_hunks_into_diff_file(Dictionary p_diff_file, TypedArray<Dictionary> p_diff_hunks) {
|
||||
p_diff_file["diff_hunks"] = p_diff_hunks;
|
||||
return p_diff_file;
|
||||
}
|
||||
|
||||
Dictionary EditorVCSInterface::create_status_file(const String &p_file_path, ChangeType p_change, TreeArea p_area) {
|
||||
Dictionary sf;
|
||||
sf["file_path"] = p_file_path;
|
||||
sf["change_type"] = p_change;
|
||||
sf["area"] = p_area;
|
||||
return sf;
|
||||
}
|
||||
|
||||
EditorVCSInterface::DiffLine EditorVCSInterface::_convert_diff_line(const Dictionary &p_diff_line) {
|
||||
DiffLine d;
|
||||
d.new_line_no = p_diff_line["new_line_no"];
|
||||
d.old_line_no = p_diff_line["old_line_no"];
|
||||
d.content = p_diff_line["content"];
|
||||
d.status = p_diff_line["status"];
|
||||
return d;
|
||||
}
|
||||
|
||||
EditorVCSInterface::DiffHunk EditorVCSInterface::_convert_diff_hunk(const Dictionary &p_diff_hunk) {
|
||||
DiffHunk dh;
|
||||
dh.new_lines = p_diff_hunk["new_lines"];
|
||||
dh.old_lines = p_diff_hunk["old_lines"];
|
||||
dh.new_start = p_diff_hunk["new_start"];
|
||||
dh.old_start = p_diff_hunk["old_start"];
|
||||
TypedArray<Dictionary> diff_lines = p_diff_hunk["diff_lines"];
|
||||
for (int i = 0; i < diff_lines.size(); i++) {
|
||||
DiffLine dl = _convert_diff_line(diff_lines[i]);
|
||||
dh.diff_lines.push_back(dl);
|
||||
}
|
||||
return dh;
|
||||
}
|
||||
|
||||
EditorVCSInterface::DiffFile EditorVCSInterface::_convert_diff_file(const Dictionary &p_diff_file) {
|
||||
DiffFile df;
|
||||
df.new_file = p_diff_file["new_file"];
|
||||
df.old_file = p_diff_file["old_file"];
|
||||
TypedArray<Dictionary> diff_hunks = p_diff_file["diff_hunks"];
|
||||
for (int i = 0; i < diff_hunks.size(); i++) {
|
||||
DiffHunk dh = _convert_diff_hunk(diff_hunks[i]);
|
||||
df.diff_hunks.push_back(dh);
|
||||
}
|
||||
return df;
|
||||
}
|
||||
|
||||
EditorVCSInterface::Commit EditorVCSInterface::_convert_commit(const Dictionary &p_commit) {
|
||||
EditorVCSInterface::Commit c;
|
||||
c.msg = p_commit["message"];
|
||||
c.author = p_commit["author"];
|
||||
c.unix_timestamp = p_commit["unix_timestamp"];
|
||||
c.offset_minutes = p_commit["offset_minutes"];
|
||||
c.id = p_commit["id"];
|
||||
return c;
|
||||
}
|
||||
|
||||
EditorVCSInterface::StatusFile EditorVCSInterface::_convert_status_file(const Dictionary &p_status_file) {
|
||||
StatusFile sf;
|
||||
sf.file_path = p_status_file["file_path"];
|
||||
sf.change_type = (ChangeType)(int)p_status_file["change_type"];
|
||||
sf.area = (TreeArea)(int)p_status_file["area"];
|
||||
return sf;
|
||||
}
|
||||
|
||||
void EditorVCSInterface::_bind_methods() {
|
||||
// Proxy end points that implement the VCS specific operations that the editor demands.
|
||||
GDVIRTUAL_BIND(_initialize, "project_path");
|
||||
GDVIRTUAL_BIND(_set_credentials, "username", "password", "ssh_public_key_path", "ssh_private_key_path", "ssh_passphrase");
|
||||
GDVIRTUAL_BIND(_get_modified_files_data);
|
||||
GDVIRTUAL_BIND(_stage_file, "file_path");
|
||||
GDVIRTUAL_BIND(_unstage_file, "file_path");
|
||||
GDVIRTUAL_BIND(_discard_file, "file_path");
|
||||
GDVIRTUAL_BIND(_commit, "msg");
|
||||
GDVIRTUAL_BIND(_get_diff, "identifier", "area");
|
||||
GDVIRTUAL_BIND(_shut_down);
|
||||
GDVIRTUAL_BIND(_get_vcs_name);
|
||||
GDVIRTUAL_BIND(_get_previous_commits, "max_commits");
|
||||
GDVIRTUAL_BIND(_get_branch_list);
|
||||
GDVIRTUAL_BIND(_get_remotes);
|
||||
GDVIRTUAL_BIND(_create_branch, "branch_name");
|
||||
GDVIRTUAL_BIND(_remove_branch, "branch_name");
|
||||
GDVIRTUAL_BIND(_create_remote, "remote_name", "remote_url");
|
||||
GDVIRTUAL_BIND(_remove_remote, "remote_name");
|
||||
GDVIRTUAL_BIND(_get_current_branch_name);
|
||||
GDVIRTUAL_BIND(_checkout_branch, "branch_name");
|
||||
GDVIRTUAL_BIND(_pull, "remote");
|
||||
GDVIRTUAL_BIND(_push, "remote", "force");
|
||||
GDVIRTUAL_BIND(_fetch, "remote");
|
||||
GDVIRTUAL_BIND(_get_line_diff, "file_path", "text");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("create_diff_line", "new_line_no", "old_line_no", "content", "status"), &EditorVCSInterface::create_diff_line);
|
||||
ClassDB::bind_method(D_METHOD("create_diff_hunk", "old_start", "new_start", "old_lines", "new_lines"), &EditorVCSInterface::create_diff_hunk);
|
||||
ClassDB::bind_method(D_METHOD("create_diff_file", "new_file", "old_file"), &EditorVCSInterface::create_diff_file);
|
||||
ClassDB::bind_method(D_METHOD("create_commit", "msg", "author", "id", "unix_timestamp", "offset_minutes"), &EditorVCSInterface::create_commit);
|
||||
ClassDB::bind_method(D_METHOD("create_status_file", "file_path", "change_type", "area"), &EditorVCSInterface::create_status_file);
|
||||
ClassDB::bind_method(D_METHOD("add_diff_hunks_into_diff_file", "diff_file", "diff_hunks"), &EditorVCSInterface::add_diff_hunks_into_diff_file);
|
||||
ClassDB::bind_method(D_METHOD("add_line_diffs_into_diff_hunk", "diff_hunk", "line_diffs"), &EditorVCSInterface::add_line_diffs_into_diff_hunk);
|
||||
ClassDB::bind_method(D_METHOD("popup_error", "msg"), &EditorVCSInterface::popup_error);
|
||||
|
||||
BIND_ENUM_CONSTANT(CHANGE_TYPE_NEW);
|
||||
BIND_ENUM_CONSTANT(CHANGE_TYPE_MODIFIED);
|
||||
BIND_ENUM_CONSTANT(CHANGE_TYPE_RENAMED);
|
||||
BIND_ENUM_CONSTANT(CHANGE_TYPE_DELETED);
|
||||
BIND_ENUM_CONSTANT(CHANGE_TYPE_TYPECHANGE);
|
||||
BIND_ENUM_CONSTANT(CHANGE_TYPE_UNMERGED);
|
||||
|
||||
BIND_ENUM_CONSTANT(TREE_AREA_COMMIT);
|
||||
BIND_ENUM_CONSTANT(TREE_AREA_STAGED);
|
||||
BIND_ENUM_CONSTANT(TREE_AREA_UNSTAGED);
|
||||
}
|
||||
|
||||
EditorVCSInterface *EditorVCSInterface::get_singleton() {
|
||||
return singleton;
|
||||
}
|
||||
|
||||
void EditorVCSInterface::set_singleton(EditorVCSInterface *p_singleton) {
|
||||
singleton = p_singleton;
|
||||
}
|
||||
|
||||
void EditorVCSInterface::create_vcs_metadata_files(VCSMetadata p_vcs_metadata_type, String &p_dir) {
|
||||
if (p_vcs_metadata_type == VCSMetadata::GIT) {
|
||||
Ref<FileAccess> f = FileAccess::open(p_dir.path_join(".gitignore"), FileAccess::WRITE);
|
||||
if (f.is_null()) {
|
||||
ERR_FAIL_MSG("Couldn't create .gitignore in project path.");
|
||||
} else {
|
||||
f->store_line("# Godot 4+ specific ignores");
|
||||
f->store_line(".godot/");
|
||||
f->store_line("/android/");
|
||||
}
|
||||
f = FileAccess::open(p_dir.path_join(".gitattributes"), FileAccess::WRITE);
|
||||
if (f.is_null()) {
|
||||
ERR_FAIL_MSG("Couldn't create .gitattributes in project path.");
|
||||
} else {
|
||||
f->store_line("# Normalize EOL for all files that Git considers text files.");
|
||||
f->store_line("* text=auto eol=lf");
|
||||
}
|
||||
}
|
||||
}
|
178
editor/version_control/editor_vcs_interface.h
Normal file
178
editor/version_control/editor_vcs_interface.h
Normal file
@@ -0,0 +1,178 @@
|
||||
/**************************************************************************/
|
||||
/* editor_vcs_interface.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/typed_array.h"
|
||||
|
||||
class EditorVCSInterface : public Object {
|
||||
GDCLASS(EditorVCSInterface, Object)
|
||||
|
||||
public:
|
||||
enum ChangeType {
|
||||
CHANGE_TYPE_NEW = 0,
|
||||
CHANGE_TYPE_MODIFIED = 1,
|
||||
CHANGE_TYPE_RENAMED = 2,
|
||||
CHANGE_TYPE_DELETED = 3,
|
||||
CHANGE_TYPE_TYPECHANGE = 4,
|
||||
CHANGE_TYPE_UNMERGED = 5
|
||||
};
|
||||
|
||||
enum TreeArea {
|
||||
TREE_AREA_COMMIT = 0,
|
||||
TREE_AREA_STAGED = 1,
|
||||
TREE_AREA_UNSTAGED = 2
|
||||
};
|
||||
|
||||
struct DiffLine {
|
||||
int new_line_no;
|
||||
int old_line_no;
|
||||
String content;
|
||||
String status;
|
||||
|
||||
String old_text;
|
||||
String new_text;
|
||||
};
|
||||
|
||||
struct DiffHunk {
|
||||
int new_start;
|
||||
int old_start;
|
||||
int new_lines;
|
||||
int old_lines;
|
||||
List<DiffLine> diff_lines;
|
||||
};
|
||||
|
||||
struct DiffFile {
|
||||
String new_file;
|
||||
String old_file;
|
||||
List<DiffHunk> diff_hunks;
|
||||
};
|
||||
|
||||
struct Commit {
|
||||
String author;
|
||||
String msg;
|
||||
String id;
|
||||
int64_t unix_timestamp;
|
||||
int64_t offset_minutes;
|
||||
};
|
||||
|
||||
struct StatusFile {
|
||||
TreeArea area;
|
||||
ChangeType change_type;
|
||||
String file_path;
|
||||
};
|
||||
|
||||
protected:
|
||||
static EditorVCSInterface *singleton;
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
DiffLine _convert_diff_line(const Dictionary &p_diff_line);
|
||||
DiffHunk _convert_diff_hunk(const Dictionary &p_diff_hunk);
|
||||
DiffFile _convert_diff_file(const Dictionary &p_diff_file);
|
||||
Commit _convert_commit(const Dictionary &p_commit);
|
||||
StatusFile _convert_status_file(const Dictionary &p_status_file);
|
||||
|
||||
// Proxy endpoints for extensions to implement
|
||||
GDVIRTUAL1R_REQUIRED(bool, _initialize, String);
|
||||
GDVIRTUAL5_REQUIRED(_set_credentials, String, String, String, String, String);
|
||||
GDVIRTUAL0R_REQUIRED(TypedArray<Dictionary>, _get_modified_files_data);
|
||||
GDVIRTUAL1_REQUIRED(_stage_file, String);
|
||||
GDVIRTUAL1_REQUIRED(_unstage_file, String);
|
||||
GDVIRTUAL1_REQUIRED(_discard_file, String);
|
||||
GDVIRTUAL1_REQUIRED(_commit, String);
|
||||
GDVIRTUAL2R_REQUIRED(TypedArray<Dictionary>, _get_diff, String, int);
|
||||
GDVIRTUAL0R_REQUIRED(bool, _shut_down);
|
||||
GDVIRTUAL0R_REQUIRED(String, _get_vcs_name);
|
||||
GDVIRTUAL1R_REQUIRED(TypedArray<Dictionary>, _get_previous_commits, int);
|
||||
GDVIRTUAL0R_REQUIRED(TypedArray<String>, _get_branch_list);
|
||||
GDVIRTUAL0R_REQUIRED(TypedArray<String>, _get_remotes);
|
||||
GDVIRTUAL1_REQUIRED(_create_branch, String);
|
||||
GDVIRTUAL1_REQUIRED(_remove_branch, String);
|
||||
GDVIRTUAL2_REQUIRED(_create_remote, String, String);
|
||||
GDVIRTUAL1_REQUIRED(_remove_remote, String);
|
||||
GDVIRTUAL0R_REQUIRED(String, _get_current_branch_name);
|
||||
GDVIRTUAL1R_REQUIRED(bool, _checkout_branch, String);
|
||||
GDVIRTUAL1_REQUIRED(_pull, String);
|
||||
GDVIRTUAL2_REQUIRED(_push, String, bool);
|
||||
GDVIRTUAL1_REQUIRED(_fetch, String);
|
||||
GDVIRTUAL2R_REQUIRED(TypedArray<Dictionary>, _get_line_diff, String, String);
|
||||
|
||||
public:
|
||||
static EditorVCSInterface *get_singleton();
|
||||
static void set_singleton(EditorVCSInterface *p_singleton);
|
||||
|
||||
enum class VCSMetadata {
|
||||
NONE,
|
||||
GIT,
|
||||
};
|
||||
static void create_vcs_metadata_files(VCSMetadata p_vcs_metadata_type, String &p_dir);
|
||||
|
||||
// Proxies to the editor for use
|
||||
bool initialize(const String &p_project_path);
|
||||
void set_credentials(const String &p_username, const String &p_password, const String &p_ssh_public_key_path, const String &p_ssh_private_key_path, const String &p_ssh_passphrase);
|
||||
List<StatusFile> get_modified_files_data();
|
||||
void stage_file(const String &p_file_path);
|
||||
void unstage_file(const String &p_file_path);
|
||||
void discard_file(const String &p_file_path);
|
||||
void commit(const String &p_msg);
|
||||
List<DiffFile> get_diff(const String &p_identifier, TreeArea p_area);
|
||||
bool shut_down();
|
||||
String get_vcs_name();
|
||||
List<Commit> get_previous_commits(int p_max_commits);
|
||||
List<String> get_branch_list();
|
||||
List<String> get_remotes();
|
||||
void create_branch(const String &p_branch_name);
|
||||
void remove_branch(const String &p_branch_name);
|
||||
void create_remote(const String &p_remote_name, const String &p_remote_url);
|
||||
void remove_remote(const String &p_remote_name);
|
||||
String get_current_branch_name();
|
||||
bool checkout_branch(const String &p_branch_name);
|
||||
void pull(const String &p_remote);
|
||||
void push(const String &p_remote, bool p_force);
|
||||
void fetch(const String &p_remote);
|
||||
List<DiffHunk> get_line_diff(const String &p_file_path, const String &p_text);
|
||||
|
||||
// Helper functions to create and convert Dictionary into data structures
|
||||
Dictionary create_diff_line(int p_new_line_no, int p_old_line_no, const String &p_content, const String &p_status);
|
||||
Dictionary create_diff_hunk(int p_old_start, int p_new_start, int p_old_lines, int p_new_lines);
|
||||
Dictionary create_diff_file(const String &p_new_file, const String &p_old_file);
|
||||
Dictionary create_commit(const String &p_msg, const String &p_author, const String &p_id, int64_t p_unix_timestamp, int64_t p_offset_minutes);
|
||||
Dictionary create_status_file(const String &p_file_path, ChangeType p_change, TreeArea p_area);
|
||||
Dictionary add_line_diffs_into_diff_hunk(Dictionary p_diff_hunk, TypedArray<Dictionary> p_line_diffs);
|
||||
Dictionary add_diff_hunks_into_diff_file(Dictionary p_diff_file, TypedArray<Dictionary> p_diff_hunks);
|
||||
|
||||
void popup_error(const String &p_msg);
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(EditorVCSInterface::ChangeType);
|
||||
VARIANT_ENUM_CAST(EditorVCSInterface::TreeArea);
|
1531
editor/version_control/version_control_editor_plugin.cpp
Normal file
1531
editor/version_control/version_control_editor_plugin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
214
editor/version_control/version_control_editor_plugin.h
Normal file
214
editor/version_control/version_control_editor_plugin.h
Normal file
@@ -0,0 +1,214 @@
|
||||
/**************************************************************************/
|
||||
/* version_control_editor_plugin.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "editor/plugins/editor_plugin.h"
|
||||
#include "editor/version_control/editor_vcs_interface.h"
|
||||
#include "scene/gui/check_button.h"
|
||||
#include "scene/gui/file_dialog.h"
|
||||
#include "scene/gui/menu_button.h"
|
||||
#include "scene/gui/rich_text_label.h"
|
||||
#include "scene/gui/text_edit.h"
|
||||
#include "scene/gui/tree.h"
|
||||
|
||||
class VersionControlEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(VersionControlEditorPlugin, EditorPlugin)
|
||||
|
||||
public:
|
||||
enum ButtonType {
|
||||
BUTTON_TYPE_OPEN = 0,
|
||||
BUTTON_TYPE_DISCARD = 1,
|
||||
};
|
||||
|
||||
enum DiffViewType {
|
||||
DIFF_VIEW_TYPE_SPLIT = 0,
|
||||
DIFF_VIEW_TYPE_UNIFIED = 1,
|
||||
};
|
||||
|
||||
enum ExtraOption {
|
||||
EXTRA_OPTION_FORCE_PUSH,
|
||||
EXTRA_OPTION_CREATE_BRANCH,
|
||||
EXTRA_OPTION_CREATE_REMOTE,
|
||||
};
|
||||
|
||||
private:
|
||||
static VersionControlEditorPlugin *singleton;
|
||||
|
||||
List<StringName> available_plugins;
|
||||
|
||||
PopupMenu *version_control_actions = nullptr;
|
||||
ConfirmationDialog *metadata_dialog = nullptr;
|
||||
OptionButton *metadata_selection = nullptr;
|
||||
AcceptDialog *set_up_dialog = nullptr;
|
||||
CheckButton *toggle_vcs_choice = nullptr;
|
||||
OptionButton *set_up_choice = nullptr;
|
||||
VBoxContainer *set_up_vbc = nullptr;
|
||||
VBoxContainer *set_up_settings_vbc = nullptr;
|
||||
LineEdit *set_up_username = nullptr;
|
||||
LineEdit *set_up_password = nullptr;
|
||||
LineEdit *set_up_ssh_public_key_path = nullptr;
|
||||
LineEdit *set_up_ssh_private_key_path = nullptr;
|
||||
LineEdit *set_up_ssh_passphrase = nullptr;
|
||||
FileDialog *set_up_ssh_public_key_file_dialog = nullptr;
|
||||
FileDialog *set_up_ssh_private_key_file_dialog = nullptr;
|
||||
Label *set_up_warning_text = nullptr;
|
||||
|
||||
AcceptDialog *discard_all_confirm = nullptr;
|
||||
|
||||
OptionButton *commit_list_size_button = nullptr;
|
||||
|
||||
AcceptDialog *branch_create_confirm = nullptr;
|
||||
LineEdit *branch_create_name_input = nullptr;
|
||||
Button *branch_create_ok = nullptr;
|
||||
|
||||
AcceptDialog *remote_create_confirm = nullptr;
|
||||
LineEdit *remote_create_name_input = nullptr;
|
||||
LineEdit *remote_create_url_input = nullptr;
|
||||
Button *remote_create_ok = nullptr;
|
||||
|
||||
HashMap<EditorVCSInterface::ChangeType, String> change_type_to_strings;
|
||||
HashMap<EditorVCSInterface::ChangeType, Color> change_type_to_color;
|
||||
HashMap<EditorVCSInterface::ChangeType, Ref<Texture>> change_type_to_icon;
|
||||
|
||||
VBoxContainer *version_commit_dock = nullptr;
|
||||
Tree *staged_files = nullptr;
|
||||
Tree *unstaged_files = nullptr;
|
||||
Tree *commit_list = nullptr;
|
||||
|
||||
OptionButton *branch_select = nullptr;
|
||||
Button *branch_remove_button = nullptr;
|
||||
AcceptDialog *branch_remove_confirm = nullptr;
|
||||
|
||||
Button *fetch_button = nullptr;
|
||||
Button *pull_button = nullptr;
|
||||
Button *push_button = nullptr;
|
||||
OptionButton *remote_select = nullptr;
|
||||
Button *remote_remove_button = nullptr;
|
||||
AcceptDialog *remote_remove_confirm = nullptr;
|
||||
MenuButton *extra_options = nullptr;
|
||||
PopupMenu *extra_options_remove_branch_list = nullptr;
|
||||
PopupMenu *extra_options_remove_remote_list = nullptr;
|
||||
|
||||
String branch_to_remove;
|
||||
String remote_to_remove;
|
||||
|
||||
Button *stage_all_button = nullptr;
|
||||
Button *unstage_all_button = nullptr;
|
||||
Button *discard_all_button = nullptr;
|
||||
Button *refresh_button = nullptr;
|
||||
TextEdit *commit_message = nullptr;
|
||||
Button *commit_button = nullptr;
|
||||
|
||||
VBoxContainer *version_control_dock = nullptr;
|
||||
Button *version_control_dock_button = nullptr;
|
||||
Label *diff_title = nullptr;
|
||||
RichTextLabel *diff = nullptr;
|
||||
OptionButton *diff_view_type_select = nullptr;
|
||||
bool show_commit_diff_header = false;
|
||||
List<EditorVCSInterface::DiffFile> diff_content;
|
||||
|
||||
void _notification(int p_what);
|
||||
void _initialize_vcs();
|
||||
void _set_vcs_ui_state(bool p_enabled);
|
||||
void _set_credentials();
|
||||
void _ssh_public_key_selected(const String &p_path);
|
||||
void _ssh_private_key_selected(const String &p_path);
|
||||
void _populate_available_vcs_names();
|
||||
void _update_remotes_list();
|
||||
void _update_set_up_warning(const String &p_new_text);
|
||||
void _update_opened_tabs();
|
||||
void _update_extra_options();
|
||||
|
||||
bool _load_plugin(const String &p_name);
|
||||
|
||||
void _pull();
|
||||
void _push();
|
||||
void _force_push();
|
||||
void _fetch();
|
||||
void _commit();
|
||||
void _confirm_discard_all();
|
||||
void _discard_all();
|
||||
void _refresh_stage_area();
|
||||
void _refresh_branch_list();
|
||||
void _set_commit_list_size(int p_index);
|
||||
void _refresh_commit_list();
|
||||
void _refresh_remote_list();
|
||||
void _display_diff(int p_idx);
|
||||
void _move_all(Object *p_tree);
|
||||
void _load_diff(Object *p_tree);
|
||||
void _clear_diff();
|
||||
int _get_item_count(Tree *p_tree);
|
||||
void _item_activated(Object *p_tree);
|
||||
void _create_branch();
|
||||
void _create_remote();
|
||||
void _update_branch_create_button(const String &p_new_text);
|
||||
void _update_remote_create_button(const String &p_new_text);
|
||||
void _branch_item_selected(int p_index);
|
||||
void _remote_selected(int p_index);
|
||||
void _remove_branch();
|
||||
void _remove_remote();
|
||||
void _popup_branch_remove_confirm(int p_index);
|
||||
void _popup_remote_remove_confirm(int p_index);
|
||||
void _move_item(Tree *p_tree, TreeItem *p_itme);
|
||||
void _display_diff_split_view(List<EditorVCSInterface::DiffLine> &p_diff_content);
|
||||
void _display_diff_unified_view(List<EditorVCSInterface::DiffLine> &p_diff_content);
|
||||
void _discard_file(const String &p_file_path, EditorVCSInterface::ChangeType p_change);
|
||||
void _cell_button_pressed(Object *p_item, int p_column, int p_id, int p_mouse_button_index);
|
||||
void _add_new_item(Tree *p_tree, const String &p_file_path, EditorVCSInterface::ChangeType p_change);
|
||||
void _update_commit_button();
|
||||
void _commit_message_gui_input(const Ref<InputEvent> &p_event);
|
||||
void _extra_option_selected(int p_index);
|
||||
bool _is_staging_area_empty();
|
||||
String _get_date_string_from(int64_t p_unix_timestamp, int64_t p_offset_minutes) const;
|
||||
void _create_vcs_metadata_files();
|
||||
void _popup_file_dialog(const Variant &p_file_dialog_variant);
|
||||
void _toggle_vcs_integration(bool p_toggled);
|
||||
|
||||
friend class EditorVCSInterface;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static VersionControlEditorPlugin *get_singleton();
|
||||
|
||||
void popup_vcs_metadata_dialog();
|
||||
void popup_vcs_set_up_dialog(const Control *p_gui_base);
|
||||
|
||||
PopupMenu *get_version_control_actions_panel() const { return version_control_actions; }
|
||||
|
||||
void register_editor();
|
||||
void fetch_available_vcs_plugin_names();
|
||||
void shut_down();
|
||||
|
||||
VersionControlEditorPlugin();
|
||||
~VersionControlEditorPlugin();
|
||||
};
|
Reference in New Issue
Block a user