Skip to content

Commit 774bb29

Browse files
committed
Added LockedFiles method.
1 parent 910baea commit 774bb29

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#if UNITY_EDITOR
44
using System.Collections.Generic;
55
using System.Diagnostics;
6+
using UnityEngine;
67
using Debug = UnityEngine.Debug;
78

89
namespace CandyCoded.GitStatus
@@ -15,6 +16,8 @@ public static class Git
1516
public static string GitPath => "C:\\Program Files\\Git\\cmd\\git.exe";
1617
#else
1718
public static string GitPath => "/usr/local/bin/git";
19+
20+
public static string GitLFSPath => "/usr/local/bin/git-lfs";
1821
#endif
1922

2023
public static string Branch()
@@ -127,6 +130,41 @@ public static string[] UntrackedFiles()
127130

128131
}
129132

133+
public static string[] LockedFiles()
134+
{
135+
136+
var process = Process.Start(new ProcessStartInfo
137+
{
138+
FileName = GitLFSPath,
139+
Arguments = "locks --json",
140+
UseShellExecute = false,
141+
RedirectStandardOutput = true,
142+
RedirectStandardError = true,
143+
CreateNoWindow = true
144+
});
145+
146+
process?.WaitForExit();
147+
148+
var locked = new List<string>();
149+
150+
var locks = JsonUtility.FromJson<Locks>($@"{{""locks"":{process?.StandardOutput.ReadToEnd()}}}").locks;
151+
152+
if (locks != null)
153+
{
154+
155+
for (var i = 0; i < locks.Length; i += 1)
156+
{
157+
158+
locked.Add(locks[i].path);
159+
160+
}
161+
162+
}
163+
164+
return locked.ToArray();
165+
166+
}
167+
130168
public static void DiscardChanges(string path)
131169
{
132170

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
3+
namespace CandyCoded.GitStatus
4+
{
5+
6+
public struct Locks
7+
{
8+
9+
public Lock[] locks;
10+
11+
}
12+
13+
[Serializable]
14+
public struct Lock
15+
{
16+
17+
[Serializable]
18+
public struct Owner
19+
{
20+
21+
public string name;
22+
23+
}
24+
25+
public long id;
26+
27+
public string path;
28+
29+
public Owner owner;
30+
31+
public string locked_at;
32+
33+
}
34+
35+
}

Assets/Plugins/CandyCoded.GitStatus/Scripts/CustomEditor/Lock.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)