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