Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

EditorVCSInterface

继承: Object

版本控制系统(VCS)接口,用于读取和写入正在使用的本地 VCS。

描述

定义编辑器使用的 API,负责从底层 VCS 提取信息。该 API 的实现包含在 VCS 插件中,这些插件是继承 EditorVCSInterface 并被附加(按需)到 EditorVCSInterface 的单例实例的 GDExtension 插件。以下列出的所有虚函数都不会亲自执行操作,而是会去调用 VCS 插件中内部覆盖的函数,以提供即插即用的体验。自定义 VCS 插件应当继承 EditorVCSInterface 并覆盖这些虚函数。

教程

方法

bool

_checkout_branch ( String branch_name ) virtual

void

_commit ( String msg ) virtual

void

_create_branch ( String branch_name ) virtual

void

_create_remote ( String remote_name, String remote_url ) virtual

void

_discard_file ( String file_path ) virtual

void

_fetch ( String remote ) virtual

String[]

_get_branch_list ( ) virtual

String

_get_current_branch_name ( ) virtual

Dictionary[]

_get_diff ( String identifier, int area ) virtual

Dictionary[]

_get_line_diff ( String file_path, String text ) virtual

Dictionary[]

_get_modified_files_data ( ) virtual

Dictionary[]

_get_previous_commits ( int max_commits ) virtual

String[]

_get_remotes ( ) virtual

String

_get_vcs_name ( ) virtual

bool

_initialize ( String project_path ) virtual

void

_pull ( String remote ) virtual

void

_push ( String remote, bool force ) virtual

void

_remove_branch ( String branch_name ) virtual

void

_remove_remote ( String remote_name ) virtual

void

_set_credentials ( String username, String password, String ssh_public_key_path, String ssh_private_key_path, String ssh_passphrase ) virtual

bool

_shut_down ( ) virtual

void

_stage_file ( String file_path ) virtual

void

_unstage_file ( String file_path ) virtual

Dictionary

add_diff_hunks_into_diff_file ( Dictionary diff_file, Dictionary[] diff_hunks )

Dictionary

add_line_diffs_into_diff_hunk ( Dictionary diff_hunk, Dictionary[] line_diffs )

Dictionary

create_commit ( String msg, String author, String id, int unix_timestamp, int offset_minutes )

Dictionary

create_diff_file ( String new_file, String old_file )

Dictionary

create_diff_hunk ( int old_start, int new_start, int old_lines, int new_lines )

Dictionary

create_diff_line ( int new_line_no, int old_line_no, String content, String status )

Dictionary

create_status_file ( String file_path, ChangeType change_type, TreeArea area )

void

popup_error ( String msg )


枚举

enum ChangeType:

ChangeType CHANGE_TYPE_NEW = 0

添加了新文件。

ChangeType CHANGE_TYPE_MODIFIED = 1

先前添加的文件已被修改。

ChangeType CHANGE_TYPE_RENAMED = 2

先前添加的文件已被重命名。

ChangeType CHANGE_TYPE_DELETED = 3

先前添加的文件已被删除。

ChangeType CHANGE_TYPE_TYPECHANGE = 4

先前添加的文件已更改类型。

ChangeType CHANGE_TYPE_UNMERGED = 5

文件未合并。


enum TreeArea:

TreeArea TREE_AREA_COMMIT = 0

在提交区域遇到了提交。

TreeArea TREE_AREA_STAGED = 1

在暂存区域遇到了文件。

TreeArea TREE_AREA_UNSTAGED = 2

在未暂存区域遇到了文件。


方法说明

bool _checkout_branch ( String branch_name ) virtual

检出 VCS 中的 branch_name 分支。


void _commit ( String msg ) virtual

提交当前暂存的修改,并对提交应用提交信息 msg


void _create_branch ( String branch_name ) virtual

在 VCS 中新建名为 branch_name 的分支。


void _create_remote ( String remote_name, String remote_url ) virtual

创建一个名为 remote_name 的新远程仓库目标,并将其指向 remote_url。这既可以是 HTTPS 远程仓库,也可以是 SSH 远程仓库。


void _discard_file ( String file_path ) virtual

丢弃对位于 file_path 的文件进行的修改。


void _fetch ( String remote ) virtual

从远程仓库 remote 中抓取新修改,但不将修改写入当前工作目录。相当于 git fetch


String[] _get_branch_list ( ) virtual

获取 String 字符串的 Array 数组实例,包含在 VCS 中可用的分支名称。


String _get_current_branch_name ( ) virtual

获取 VCS 中定义的当前分支名称。


Dictionary[] _get_diff ( String identifier, int area ) virtual

返回 Dictionary 项的数组(参见 create_diff_filecreate_diff_hunkcreate_diff_lineadd_line_diffs_into_diff_hunk、和 add_diff_hunks_into_diff_file),每项都包含一个差异的信息。如果 identifier 是文件路径,则返回文件差异;如果它是提交标识符,则返回提交差异。


Dictionary[] _get_line_diff ( String file_path, String text ) virtual

返回 Dictionary 字典项的 Array 数组(见 create_diff_hunk),每一项都包含位于 file_path 的文件与传入的 text 之间的单行差异。


Dictionary[] _get_modified_files_data ( ) virtual

返回 Dictionary 字典项的 Array 数组(见 create_status_file),每一项都包含项目文件夹中每个已修改的文件的状态数据。


Dictionary[] _get_previous_commits ( int max_commits ) virtual

返回 Dictionary 字典项的 Array 数组(见 create_commit),每一项都包含一个过去提交的数据。


String[] _get_remotes ( ) virtual

返回 String 字符串的 Array 数组,每一个都包含 VCS 中配置的一个远程仓库的名称。


String _get_vcs_name ( ) virtual

返回底层 VCS 提供方的名称。


bool _initialize ( String project_path ) virtual

从编辑器中调用时初始化该 VCS 插件。返回该插件是否成功初始化。会在 project_path 初始化 VCS 项目。


void _pull ( String remote ) virtual

从远程仓库拉取修改。这可能会导致合并冲突。


void _push ( String remote, bool force ) virtual

将修改推送至远程仓库 remote。如果 forcetrue,则会进行强制推送,覆盖远程仓库中现有的修改历史。


void _remove_branch ( String branch_name ) virtual

从本地 VCS 中移除一个分支。


void _remove_remote ( String remote_name ) virtual

从本地 VCS 中移除一个远程仓库。


void _set_credentials ( String username, String password, String ssh_public_key_path, String ssh_private_key_path, String ssh_passphrase ) virtual

在底层 VCS 中设置用户认证信息。用户名 username 和密码 password 只会在进行 HTTPS 认证且没有在远程仓库 URL 中给出时使用。SSH 公钥路径 ssh_public_key_path、SSH 私钥路径 ssh_private_key_path、SSH 密码 ssh_passphrase 只会在进行 SSH 认证时使用。


bool _shut_down ( ) virtual

关闭 VCS 插件实例。会在用户关闭编辑器或通过编辑器 UI 关闭该 VCS 插件时调用。


void _stage_file ( String file_path ) virtual

将位于 file_path 的文件暂存到暂存区。


void _unstage_file ( String file_path ) virtual

将位于 file_path 的文件从暂存区撤销到未暂存区。


Dictionary add_diff_hunks_into_diff_file ( Dictionary diff_file, Dictionary[] diff_hunks )

辅助函数,用于将一组 diff_hunks 添加到 diff_file


Dictionary add_line_diffs_into_diff_hunk ( Dictionary diff_hunk, Dictionary[] line_diffs )

辅助函数,用于将一组 line_diffs 添加到 diff_hunk 中。


Dictionary create_commit ( String msg, String author, String id, int unix_timestamp, int offset_minutes )

辅助函数, 用于创建一个提交 Dictionary 项。msg 是该提交的提交消息。author 是单个人类可读的字符串,包含所有作者的详细信息,例如 VCS 中配置的电子邮件和名称。无论 VCS 可能以哪种格式为提交提供标识符,id 是该提交的标识符。unix_timestamp 是该提交被创建时的 UTC Unix 时间戳。offset_minutes 是该提交创建时当前系统时区的偏移量,单位为分钟。


Dictionary create_diff_file ( String new_file, String old_file )

辅助函数,用于创建用来保存新旧文件路径差异的 Dictionary


Dictionary create_diff_hunk ( int old_start, int new_start, int old_lines, int new_lines )

辅助函数,用于创建用于保存差异块数据的 Dictionaryold_start 是旧文件中的起始行号。new_start 是新文件中的起始行号。old_lines 是旧文件中的行数。new_lines 是新文件中的行数。


Dictionary create_diff_line ( int new_line_no, int old_line_no, String content, String status )

辅助函数,创建用于保存行差异的 Dictionarynew_line_no 是新文件中的行号(该行被删除时可为 -1)。old_line_no 是旧文件中的行号(该行为新增时可为 -1)。content 为差异文本。status 为保存该行原点的单字符字符串。


Dictionary create_status_file ( String file_path, ChangeType change_type, TreeArea area )

辅助函数,用于创建被编辑器用来读取文件状态的 Dictionary


void popup_error ( String msg )

在编辑器中弹出一条错误消息,显示为来自底层 VCS。使用它来显示 VCS 特定的错误消息。