Skip to content
0.2.0-dev Download ZIP
184 lines ·7.4 KB Raw
1/**************************************************************************/
2/* editor_vcs_interface.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#pragma once
32
33#include "core/object/gdvirtual.gen.h"
34#include "core/string/ustring.h"
35#include "core/variant/typed_array.h"
36
37class EditorVCSInterface : public Object {
38 GDCLASS(EditorVCSInterface, Object)
39
40public:
41 enum ChangeType {
42 CHANGE_TYPE_NEW = 0,
43 CHANGE_TYPE_MODIFIED = 1,
44 CHANGE_TYPE_RENAMED = 2,
45 CHANGE_TYPE_DELETED = 3,
46 CHANGE_TYPE_TYPECHANGE = 4,
47 CHANGE_TYPE_UNMERGED = 5
48 };
49
50 enum TreeArea {
51 TREE_AREA_COMMIT = 0,
52 TREE_AREA_STAGED = 1,
53 TREE_AREA_UNSTAGED = 2
54 };
55
56 struct DiffLine {
57 int new_line_no;
58 int old_line_no;
59 String content;
60 String status;
61
62 String old_text;
63 String new_text;
64 };
65
66 struct DiffHunk {
67 int new_start;
68 int old_start;
69 int new_lines;
70 int old_lines;
71 List<DiffLine> diff_lines;
72 };
73
74 struct DiffFile {
75 String new_file;
76 String old_file;
77 List<DiffHunk> diff_hunks;
78 };
79
80 struct Commit {
81 String author;
82 String msg;
83 String id;
84 int64_t unix_timestamp;
85 int64_t offset_minutes;
86 };
87
88 struct StatusFile {
89 TreeArea area;
90 ChangeType change_type;
91 String file_path;
92 };
93
94protected:
95 static EditorVCSInterface *singleton;
96
97 static void _bind_methods();
98
99 DiffLine _convert_diff_line(const Dictionary &p_diff_line);
100 DiffHunk _convert_diff_hunk(const Dictionary &p_diff_hunk);
101 DiffFile _convert_diff_file(const Dictionary &p_diff_file);
102 Commit _convert_commit(const Dictionary &p_commit);
103 StatusFile _convert_status_file(const Dictionary &p_status_file);
104
105 // Proxy endpoints for extensions to implement
106 GDVIRTUAL1R_REQUIRED(bool, _initialize, String);
107 GDVIRTUAL5_REQUIRED(_set_credentials, String, String, String, String, String);
108 GDVIRTUAL0R_REQUIRED(TypedArray<Dictionary>, _get_modified_files_data);
109 GDVIRTUAL1_REQUIRED(_stage_file, String);
110 GDVIRTUAL1_REQUIRED(_unstage_file, String);
111 GDVIRTUAL1_REQUIRED(_discard_file, String);
112 GDVIRTUAL2(_commit, String, bool);
113 GDVIRTUAL0R(bool, _allow_amends);
114 GDVIRTUAL2R_REQUIRED(TypedArray<Dictionary>, _get_diff, String, int);
115 GDVIRTUAL0R_REQUIRED(bool, _shut_down);
116 GDVIRTUAL0R_REQUIRED(String, _get_vcs_name);
117 GDVIRTUAL1R_REQUIRED(TypedArray<Dictionary>, _get_previous_commits, int);
118 GDVIRTUAL0R_REQUIRED(TypedArray<String>, _get_branch_list);
119 GDVIRTUAL0R_REQUIRED(TypedArray<String>, _get_remotes);
120 GDVIRTUAL1_REQUIRED(_create_branch, String);
121 GDVIRTUAL1_REQUIRED(_remove_branch, String);
122 GDVIRTUAL2_REQUIRED(_create_remote, String, String);
123 GDVIRTUAL1_REQUIRED(_remove_remote, String);
124 GDVIRTUAL0R_REQUIRED(String, _get_current_branch_name);
125 GDVIRTUAL1R_REQUIRED(bool, _checkout_branch, String);
126 GDVIRTUAL1_REQUIRED(_pull, String);
127 GDVIRTUAL2_REQUIRED(_push, String, bool);
128 GDVIRTUAL1_REQUIRED(_fetch, String);
129 GDVIRTUAL2R_REQUIRED(TypedArray<Dictionary>, _get_line_diff, String, String);
130
131#ifndef DISABLE_DEPRECATED
132 GDVIRTUAL1_COMPAT(_commit_bind_compat_117968, _commit, String);
133#endif
134
135public:
136 static EditorVCSInterface *get_singleton();
137 static void set_singleton(EditorVCSInterface *p_singleton);
138
139 enum class VCSMetadata {
140 NONE,
141 GIT,
142 };
143 static void create_vcs_metadata_files(VCSMetadata p_vcs_metadata_type, String &p_dir);
144
145 // Proxies to the editor for use
146 bool initialize(const String &p_project_path);
147 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);
148 List<StatusFile> get_modified_files_data();
149 void stage_file(const String &p_file_path);
150 void unstage_file(const String &p_file_path);
151 void discard_file(const String &p_file_path);
152 void commit(const String &p_msg, bool p_amend);
153 bool allow_amends();
154 List<DiffFile> get_diff(const String &p_identifier, TreeArea p_area);
155 bool shut_down();
156 String get_vcs_name();
157 List<Commit> get_previous_commits(int p_max_commits);
158 List<String> get_branch_list();
159 List<String> get_remotes();
160 void create_branch(const String &p_branch_name);
161 void remove_branch(const String &p_branch_name);
162 void create_remote(const String &p_remote_name, const String &p_remote_url);
163 void remove_remote(const String &p_remote_name);
164 String get_current_branch_name();
165 bool checkout_branch(const String &p_branch_name);
166 void pull(const String &p_remote);
167 void push(const String &p_remote, bool p_force);
168 void fetch(const String &p_remote);
169 List<DiffHunk> get_line_diff(const String &p_file_path, const String &p_text);
170
171 // Helper functions to create and convert Dictionary into data structures
172 Dictionary create_diff_line(int p_new_line_no, int p_old_line_no, const String &p_content, const String &p_status);
173 Dictionary create_diff_hunk(int p_old_start, int p_new_start, int p_old_lines, int p_new_lines);
174 Dictionary create_diff_file(const String &p_new_file, const String &p_old_file);
175 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);
176 Dictionary create_status_file(const String &p_file_path, ChangeType p_change, TreeArea p_area);
177 Dictionary add_line_diffs_into_diff_hunk(Dictionary p_diff_hunk, TypedArray<Dictionary> p_line_diffs);
178 Dictionary add_diff_hunks_into_diff_file(Dictionary p_diff_file, TypedArray<Dictionary> p_diff_hunks);
179
180 void popup_error(const String &p_msg);
181};
182
183VARIANT_ENUM_CAST(EditorVCSInterface::ChangeType);
184VARIANT_ENUM_CAST(EditorVCSInterface::TreeArea);