开发过程中少不了要提交一些代码,文件,虽然操作过程简单,但是容易遗漏提交文件,写个editor工具可以减少文件漏提交的情况。
提交到SVN的代码很简单,不过有一个前提,就是要先配置SVN的环境变量。代码如下:
public class SvnTool : EditorWindow
{
[MenuItem("GameTools/Svn工具")]
public static void ShowWindow()
{
var w = EditorWindow.CreateInstance<SvnTool>();
w.Show();
}
void OnGUI()
{
OnCsCommit();
OnCsUpdate();
}
void OnCsCommit()
{
if(GUILayout.Button("提交CS代码")
{
string path = Application.dataPath + "/Scripts";
Process.Start(fileName: "TortoiseProc.exe", arguments: "/command:commit /path:" + path + " /logmsg:modify" + " /closeonend:0");
}
}
void OnCsUpdate()
{
if(GUILayout.Button("更新CS代码")
{
string path = Application.dataPath + "/Scripts";
Process.Start(fileName: "TortoiseProc.exe", arguments: "/command:update /path:" + path + " /closeonend:0");
}
}
}
这里面有几个地方要注意:
1 命令里面参数之间是空格格开,比如“/command:update空格/path”。
2 如果要提交多个路径,用"*"连接,比如:
path = Application.dataPath + "/Scripts" + "*" + Application.dataPath + "/Editor";
TortoiseProc.exe的一些命令参数如下:
-
/closeonend:0
不自动关闭对话框 -
/closeonend:1
如果没发生错误则自动关闭对话框 -
/closeonend:2
如果没发生错误和冲突则自动关闭对话框 -
/closeonend:3
如果没有错误、冲突和合并,会自动关闭 -
/closeonend:4
如果没有错误、冲突和合并,会自动关闭
命令 | 描述 |
---|---|
:about | 显示关于对话框。如果没有给命令也会显示。 |
:log | 打开日志对话框,路径指定了日志显示的文件或目录,另外还有三个选项可以设置: /revstart:xxx 、/revend:xxx 和/strict |
:checkout | 打开检出对话框,/path 指定了目标路径,而/url 制定了检出的URL。 |
:import | 打开导入对话框,路径制定了数据导入路径。 |
:update | Updates the working copy in /path to HEAD. If the option /rev is given then a dialog is shown to ask the user to which revision the update should go. |
:commit | 打开提交对话框,路经指定了目标路径或需要提交的文件列表,你也可以使用参数/logmsg给提交窗口传递预定义的日志信息,或者你不希望将日志传递给命令行,你也可以使用/logmsgfile:path,path 指向了保存日志信息的文件。为了预先填入bug的ID(如果你设置了集成bug追踪属性),你可以使用/bugid:"the bug id here" 完成这个任务。 |
:add | 将/path 的文件添加到版本控制 。 |
:revert | 恢复工作副本的本地修改,/path 说明恢复哪些条目。 |
:cleanup | 清理中断和终止的操作,将工作副本的/path 解锁。 |
:resolve | 将/path 指定文件的冲突标示为解决,如果给定/noquestion ,解决不会向用户确认操作。 |
:repocreate | 在/path 创建一个版本库。 |
:switch | 打开选项对话框。路径参数指定目标目录。 |
:export | 将/path 的工作副本导出到另一个目录,如果/path 指向另一个未版本控制目录,对话框会询问要导出到/path 的URL。 |
:merge | Opens the merge dialog. The path specifies the target directory. |
:copy | 带来branch/tag对话框,/path 是branch/tag在工作副本中的出处。 |
:settings | 打开设置对话框。 |
:remove | 从版本控制里移除/path 中的文件。 |
:rename | 重命名/path 的文件,会在对话框中询问新文件,为了防止一个步骤中询问相似文件,传递/noquestion 。 |
:diff | 启动TortoiseSVN设置的外置比较程序,/path 指定了第一个文件,如果设置了/path2 ,比较程序会启动两个文件,如果省略/path2 ,比较程序会比较/path 和它的BASE。 |
:conflicteditor | 打开TortoiseSVN设置的冲突工具,在/path 中需要设置冲突文件的正确文件。 |
:relocate | 打开重定位对话框,/path 指定了重定位的工作副本路径。 |
:help | 打开帮助文件 |
:repostatus | 打开为修改检出对话框,路经指定了工作副本目录。 |
:repobrowser | 打开版本库浏览对话框,URL为工作副本/path 指向的或/path 直接指出的,另外一个选项是/rev:xxx ,可以用来指定要显示的修订版本号,如果省略/rev:xxx ,缺省是HEAD。 |
:ignore | 将/path 中的对象加入到忽略列表,也就是将这些文件添加到svn:ignore属性。 |
:blame | 打开/path 指定文件的追溯对话框,如果设置了startrev 和endrev ,对话框询问追溯范围的对话框不会显示,如果设置了/line:nnn ,TortoiseBlame会打开特定文件的某一行。 |
:cat | 将/path 指定的工作副本或URL的文件保存到/savepath:path ,修订版本号在/revision:xxx ,这样可以得到特定修订版本的文件。 |
:createpatch | 创建/path 下的补丁文件。 |
:revisiongraph | 显示/path 目录下的版本变化图。 |
:lock | Locks a file. The 'lock' dialog is shown so the user can enter a comment for the lock. /path |
:rebuildiconcache | 重建windows的图标缓存,只有windows的图标缓存出了问题才需要这样做,一个副作用就是(不可避免)桌面的图标会重新组织。/noquestion |