-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utility.Svn.cs
208 lines (179 loc) · 5.68 KB
/
Utility.Svn.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using System;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
namespace Lib.Editor
{
public partial class CommonUtility
{
/// <summary>
/// SVN更新指定的路径
/// 路径示例:Assets/1.png
/// </summary>
/// <param name="assetPaths"></param>
public static void UpdateAtPath(string assetPath)
{
var assetPaths = new List<string>();
assetPaths.Add(assetPath);
UpdateAtPaths(assetPaths);
}
public static void AddAtPaths(List<string> assetPaths)
{
if (assetPaths.Count == 0)
return;
var arg = "/command:add /closeonend:0 /path:\"";
for (var i = 0; i < assetPaths.Count; i++)
{
var assetPath = assetPaths[i];
if (i != 0) arg += "*";
arg += assetPath;
}
arg += "\"";
SvnCommandRun(arg);
}
/// <summary>
/// SVN更新指定的路径
/// 路径示例:Assets/1.png
/// </summary>
/// <param name="assetPaths"></param>
public static void UpdateAtPaths(List<string> assetPaths)
{
if (assetPaths.Count == 0) return;
var arg = "/command:update /closeonend:0 /path:\"";
for (var i = 0; i < assetPaths.Count; i++)
{
var assetPath = assetPaths[i];
if (i != 0) arg += "*";
arg += assetPath;
}
arg += "\"";
SvnCommandRun(arg);
}
/// <summary>
/// SVN提交指定的路径
/// 路径示例:Assets/1.png
/// </summary>
/// <param name="assetPaths"></param>
public static void CommitAtPaths(List<string> assetPaths, string logmsg = null)
{
if (assetPaths.Count == 0) return;
var arg = "/command:commit /closeonend:0 /path:\"";
for (var i = 0; i < assetPaths.Count; i++)
{
var assetPath = assetPaths[i];
if (i != 0) arg += "*";
arg += assetPath;
}
arg += "\"";
if (!string.IsNullOrEmpty(logmsg)) arg += " /logmsg:\"" + logmsg + "\"";
SvnCommandRun(arg);
}
public static void RevertAtPaths(List<string> assetPaths, string logmsg = null)
{
if (assetPaths.Count == 0) return;
var arg = "/command:revert /closeonend:0 /path:\"";
for (var i = 0; i < assetPaths.Count; i++)
{
var assetPath = assetPaths[i];
if (i != 0) arg += "*";
arg += assetPath;
}
arg += "\"";
if (!string.IsNullOrEmpty(logmsg)) arg += " /logmsg:\"" + logmsg + "\"";
SvnCommandRun(arg);
}
[MenuItem("Assets/SVN Tool/SVN 更新")]
private static void SvnToolUpdate()
{
var assetPaths = CommonUtility.GetSelectionAssetPaths();
UpdateAtPaths(assetPaths);
}
[MenuItem("Assets/SVN Tool/SVN 提交...")]
private static void SvnToolCommit()
{
var assetPaths = CommonUtility.GetSelectionAssetPaths();
CommitAtPaths(assetPaths);
}
[MenuItem("Assets/SVN Tool/SVN 还原")]
private static void SvnToolRevert()
{
var assetPaths = CommonUtility.GetSelectionAssetPaths();
RevertAtPaths(assetPaths);
}
[MenuItem("Assets/SVN Tool/SVN 增加")]
private static void SvnToolAdd()
{
var assetPaths = CommonUtility.GetSelectionAssetPaths();
AddAtPaths(assetPaths);
}
[MenuItem("Assets/SVN Tool/显示日志")]
private static void SvnToolLog()
{
var assetPaths = CommonUtility.GetSelectionAssetPaths();
if (assetPaths.Count == 0) return;
// 显示日志,只能对单一资产
var arg = "/command:log /closeonend:0 /path:\"";
arg += assetPaths[0];
arg += "\"";
SvnCommandRun(arg);
}
[MenuItem("Assets/SVN Tool/检查修改")]
private static void SvnCheckModify()
{
var assetPaths = CommonUtility.GetSelectionAssetPaths();
if (assetPaths.Count == 0) return;
// 显示日志,只能对单一资产
var arg = "/command:diff /closeonend:0 /path:\"";
arg += assetPaths[0];
arg += "\"";
SvnCommandRun(arg);
}
[MenuItem("Assets/SVN Tool/追溯(仅文件)")]
private static void SvnBlame()
{
var assetPaths = CommonUtility.GetSelectionAssetPaths();
if (assetPaths.Count == 0) return;
// 显示日志,只能对单一资产
var arg = "/command:blame /closeonend:0 /path:\"";
arg += assetPaths[0];
arg += "\"";
SvnCommandRun(arg);
}
[MenuItem("Assets/SVN Tool/全部更新", false, 1100)]
private static void SvnToolAllUpdate()
{
// 往上两级,包括数据配置文件
var arg = "/command:update /closeonend:0 /path:\"";
arg += "..";
arg += "\"";
SvnCommandRun(arg);
}
[MenuItem("Assets/SVN Tool/全部日志", false, 1101)]
private static void SvnToolAllLog()
{
// 往上两级,包括数据配置文件
var arg = "/command:log /closeonend:0 /path:\"";
arg += "..";
arg += "\"";
SvnCommandRun(arg);
}
/// <summary>
/// SVN命令运行
/// </summary>
/// <param name="arg"></param>
private static void SvnCommandRun(string arg)
{
var workDirectory =
Application.dataPath.Remove(Application.dataPath.LastIndexOf("/Assets", StringComparison.Ordinal));
Process.Start(new ProcessStartInfo
{
UseShellExecute = false,
CreateNoWindow = true,
FileName = "TortoiseProc",
Arguments = arg,
WorkingDirectory = workDirectory
});
}
}
}