Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions Editor/Scripts/GitLocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ public static void RefreshLocks()

// Get the locks asynchronously
currentlyRefreshing = true;
ExecuteNonBlockingProcessTerminal("git", "lfs locks --json");
ExecuteNonBlockingProcessTerminal(GetGitLfsPath(), "locks --json");
}

public static void RefreshCallback(string result)
{
// If empty result, start a simple git lfs locks (no json) to catch potential errors
if (result == "[]")
{
ExecuteNonBlockingProcessTerminal("git", "lfs locks");
ExecuteNonBlockingProcessTerminal(GetGitLfsPath(), "locks");
}

// Check that we're receiving what seems to be a JSON result
Expand Down Expand Up @@ -549,7 +549,7 @@ public static void LockFiles(List<string> paths)
// Send each request
foreach (string pathsString in pathsStrings)
{
ExecuteProcessTerminalWithConsole("git", "lfs lock " + pathsString);
ExecuteProcessTerminalWithConsole(GetGitLfsPath(), "lock " + pathsString);
}
}

Expand Down Expand Up @@ -585,7 +585,7 @@ public static void UnlockFiles(List<string> paths, bool force = false)
// Send each request
foreach (string pathsString in pathsStrings)
{
ExecuteProcessTerminalWithConsole("git", "lfs unlock " + pathsString + (force ? "--force" : string.Empty));
ExecuteProcessTerminalWithConsole(GetGitLfsPath(), "unlock " + pathsString + (force ? "--force" : string.Empty));
}
}

Expand Down Expand Up @@ -663,11 +663,23 @@ public static string GetGitUsername()
return EditorPrefs.GetString("gitLocksHostUsername", string.Empty);
}

public static string GetGitPath()
{
string path = EditorPrefs.GetString("gitLocksGitPath", "git");
return string.IsNullOrEmpty(path) ? "git" : path;
}

public static string GetGitLfsPath()
{
string path = EditorPrefs.GetString("gitLocksGitLfsPath", "git lfs");
return string.IsNullOrEmpty(path) ? "git lfs" : path;
}

public static string GetGitVersion()
{
if (gitVersion == null || gitVersion == string.Empty)
{
gitVersion = ExecuteProcessTerminalWithConsole("git", "--version");
gitVersion = ExecuteProcessTerminalWithConsole(GetGitPath(), "--version");
}

return gitVersion;
Expand Down Expand Up @@ -785,12 +797,12 @@ public static void BuildUncommitedCache()
char[] splitter = { '\n' };

// Staged
string output = ExecuteProcessTerminal("git", "diff --name-only --staged");
string output = ExecuteProcessTerminal(GetGitPath(), "diff --name-only --staged");
string[] lines = output.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
List<string> filesCandidates = new List<string>(lines);

// Not staged
output = ExecuteProcessTerminal("git", "diff --name-only");
output = ExecuteProcessTerminal(GetGitPath(), "diff --name-only");
lines = output.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
filesCandidates.AddRange(lines);

Expand Down Expand Up @@ -853,18 +865,18 @@ public static void BuildModifiedOnServerCache()
foreach (string branch in branchesToCheck)
{
// Fetch
ExecuteProcessTerminal("git", "fetch origin " + branch);
ExecuteProcessTerminal(GetGitPath(), "fetch origin " + branch);

// List all distant commits
string output = ExecuteProcessTerminal("git", "rev-list " + currentBranch + "..origin/" + branch);
string output = ExecuteProcessTerminal(GetGitPath(), "rev-list " + currentBranch + "..origin/" + branch);
string[] lines = output.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
List<string> commits = new List<string>(lines);

// Check all commits
foreach (string commit in commits)
{
// Add all files in commit to the list
string filesOutput = ExecuteProcessTerminal("git", "diff-tree --no-commit-id --name-only -r " + commit.Replace("\r", ""));
string filesOutput = ExecuteProcessTerminal(GetGitPath(), "diff-tree --no-commit-id --name-only -r " + commit.Replace("\r", ""));
string[] files = filesOutput.Split(splitter, StringSplitOptions.RemoveEmptyEntries);

foreach (string file in files)
Expand Down Expand Up @@ -902,7 +914,7 @@ public static bool IsEnabled()
public static string GetCurrentBranch()
{
char[] splitter = { '\n' };
string currentBranch = ExecuteProcessTerminal("git", "rev-parse --abbrev-ref HEAD");
string currentBranch = ExecuteProcessTerminal(GetGitPath(), "rev-parse --abbrev-ref HEAD");
currentBranch = currentBranch.Split(splitter)[0].Replace("\r", "");
return currentBranch;
}
Expand Down Expand Up @@ -935,7 +947,7 @@ private static void Update()
if (!EditorUtility.DisplayDialog("Git Lfs Locks Error", "Git lfs locks error :\n\n" + refreshCallbackError + "\n\nIf it's your first time using the tool, you should probably setup the credentials manager", "OK", "Setup credentials"))
{
DebugLog("Setup credentials manager");
ExecuteProcessTerminalWithConsole("git", "config --global credential.helper manager");
ExecuteProcessTerminalWithConsole(GetGitPath(), "config --global credential.helper manager");
}

refreshCallbackError = null;
Expand Down
2 changes: 1 addition & 1 deletion Editor/Scripts/GitLocksDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ private static void ItemMenuGitHistory()
}
else
{
GitLocks.ExecuteProcessTerminal("git", "log \"" + path + "\"", true);
GitLocks.ExecuteProcessTerminal(GitLocks.GetGitPath(), "log \"" + path + "\"", true);
}
}
}
Expand Down
22 changes: 20 additions & 2 deletions Editor/Scripts/GitLocksPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ public override void OnGUI(string searchContext)

GUILayout.Space(5);

EditorGUI.BeginChangeCheck();
string gitPath = EditorGUILayout.TextField(new GUIContent("Git binary path", "Absolute path to the git binary. Leave empty to use 'git' from PATH."), EditorPrefs.GetString("gitLocksGitPath", ""));
if (EditorGUI.EndChangeCheck())
{
EditorPrefs.SetString("gitLocksGitPath", gitPath);
}

GUILayout.Space(5);

EditorGUI.BeginChangeCheck();
string gitLfsPath = EditorGUILayout.TextField(new GUIContent("Git LFS binary path", "Absolute path to the git-lfs binary. Leave empty to use 'git-lfs' from PATH."), EditorPrefs.GetString("gitLocksGitLfsPath", ""));
if (EditorGUI.EndChangeCheck())
{
EditorPrefs.SetString("gitLocksGitLfsPath", gitLfsPath);
}

GUILayout.Space(5);

EditorGUI.BeginChangeCheck();
int maxFilesNumPerRequest = EditorGUILayout.IntField(new GUIContent("Max number of files grouped per request"), EditorPrefs.GetInt("gitLocksMaxFilesNumPerRequest"));
if (EditorGUI.EndChangeCheck())
Expand Down Expand Up @@ -230,13 +248,13 @@ public override void OnGUI(string searchContext)
EditorGUILayout.LabelField(new GUIContent("Your git version seems outdated (2.30.0 minimum), you may need to update it and then setup the Credentials Manager for the authentication to work properly"), EditorStyles.wordWrappedLabel);
if (GUILayout.Button("Update Git for Windows"))
{
GitLocks.ExecuteProcessTerminal("git", "update-git-for-windows", true);
GitLocks.ExecuteProcessTerminal(GitLocks.GetGitPath(), "update-git-for-windows", true);
}
}

if (GUILayout.Button("Setup credentials manager (when using HTTPS)"))
{
GitLocks.ExecuteProcessTerminalWithConsole("git", "config --local credential.helper manager");
GitLocks.ExecuteProcessTerminalWithConsole(GitLocks.GetGitPath(), "config --local credential.helper manager");
}

EditorGUI.indentLevel--;
Expand Down