Skip to content

Commit deb6b82

Browse files
committed
Added lock, unlock and unlock force menu items.
1 parent c8b816d commit deb6b82

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor/Git.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,78 @@ public static string[] LockedFiles()
165165

166166
}
167167

168+
public static void LockFile(string path)
169+
{
170+
171+
var process = Process.Start(new ProcessStartInfo
172+
{
173+
FileName = GitLFSPath,
174+
Arguments = $@"lock ""{path.Replace(TopLevel(), "")}""",
175+
UseShellExecute = false,
176+
RedirectStandardOutput = true,
177+
RedirectStandardError = true,
178+
CreateNoWindow = true
179+
});
180+
181+
process?.WaitForExit();
182+
183+
}
184+
185+
public static void UnlockFile(string path)
186+
{
187+
188+
var process = Process.Start(new ProcessStartInfo
189+
{
190+
FileName = GitLFSPath,
191+
Arguments = $@"unlock ""{path.Replace(TopLevel(), "")}""",
192+
UseShellExecute = false,
193+
RedirectStandardOutput = true,
194+
RedirectStandardError = true,
195+
CreateNoWindow = true
196+
});
197+
198+
process?.WaitForExit();
199+
200+
Debug.Log(process.StandardError.ReadToEnd());
201+
202+
}
203+
204+
public static void ForceUnlockFile(string path)
205+
{
206+
207+
var process = Process.Start(new ProcessStartInfo
208+
{
209+
FileName = GitLFSPath,
210+
Arguments = $@"unlock ""{path.Replace(TopLevel(), "")}"" --force",
211+
UseShellExecute = false,
212+
RedirectStandardOutput = true,
213+
RedirectStandardError = true,
214+
CreateNoWindow = true
215+
});
216+
217+
process?.WaitForExit();
218+
219+
Debug.Log(process.StandardError.ReadToEnd());
220+
221+
}
222+
223+
public static string TopLevel()
224+
{
225+
226+
var process = Process.Start(new ProcessStartInfo
227+
{
228+
FileName = GitPath,
229+
Arguments = "rev-parse --show-toplevel",
230+
UseShellExecute = false,
231+
RedirectStandardOutput = true,
232+
RedirectStandardError = true,
233+
CreateNoWindow = true
234+
});
235+
236+
return process?.StandardOutput.ReadLine();
237+
238+
}
239+
168240
public static void DiscardChanges(string path)
169241
{
170242

Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor/GitMenuItems.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,60 @@ private static bool ValidateDiscardAllChanges()
6565

6666
}
6767

68+
[MenuItem("Git/Lock File", true, PRIORITY)]
69+
[MenuItem("Assets/Lock File", true, PRIORITY)]
70+
private static bool ValidateLockFile()
71+
{
72+
73+
return Selection.activeObject && File.Exists(GetSelectedPath());
74+
75+
}
76+
77+
[MenuItem("Git/Lock File", false, PRIORITY)]
78+
[MenuItem("Assets/Lock File", false, PRIORITY)]
79+
private static void LockFile()
80+
{
81+
82+
Git.LockFile(GetSelectedPath());
83+
84+
}
85+
86+
[MenuItem("Git/Unlock File", true, PRIORITY)]
87+
[MenuItem("Assets/Unlock File", true, PRIORITY)]
88+
private static bool ValidateUnlockFile()
89+
{
90+
91+
return Selection.activeObject && File.Exists(GetSelectedPath());
92+
93+
}
94+
95+
[MenuItem("Git/Unlock File", false, PRIORITY)]
96+
[MenuItem("Assets/Unlock File", false, PRIORITY)]
97+
private static void UnlockFile()
98+
{
99+
100+
Git.UnlockFile(GetSelectedPath());
101+
102+
}
103+
104+
[MenuItem("Git/Unlock File (Force)", true, PRIORITY)]
105+
[MenuItem("Assets/Unlock File (Force)", true, PRIORITY)]
106+
private static bool ValidateForceUnlockFile()
107+
{
108+
109+
return Selection.activeObject && File.Exists(GetSelectedPath());
110+
111+
}
112+
113+
[MenuItem("Git/Unlock File (Force)", false, PRIORITY)]
114+
[MenuItem("Assets/Unlock File (Force)", false, PRIORITY)]
115+
private static void ForceUnlockFile()
116+
{
117+
118+
Git.ForceUnlockFile(GetSelectedPath());
119+
120+
}
121+
68122
}
69123

70124
}

0 commit comments

Comments
 (0)