예제 #1
0
    public void RefreshGitLocks()
    {
        if (GitHelper.AutoUpdateSubmodules)
        {
            try
            {
                var startinfo = new ProcessStartInfo();
                startinfo.FileName = "git";
                startinfo.RedirectStandardOutput = true;
                startinfo.RedirectStandardError  = true;
                startinfo.UseShellExecute        = false;
                startinfo.CreateNoWindow         = true;
                startinfo.Arguments = "submodule update --init --recursive";

                var    proc = Process.Start(startinfo);
                string line = "Downloading...";
                while (!proc.HasExited)
                {
                    while (!proc.StandardError.EndOfStream && (line = proc.StandardError.ReadLine()) != null)
                    {
                        Debug.LogError(line);
                    }

                    while (!proc.StandardOutput.EndOfStream && (line = proc.StandardOutput.ReadLine()) != null)
                    {
                        Debug.Log(line);
                    }

                    EditorUtility.DisplayProgressBar("Downloading submodules...", line, 0);
                    Thread.Sleep(30);
                }
                Debug.Log("Submodules completed");
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
            AssetDatabase.Refresh();
        }

        GitHelper.RunGitCommand("lfs",
                                proc =>
        {
            // If it doesn't work in 10 seconds there's something wrong
            proc.WaitForExit(10000);
            return(false);
        },
                                result =>
        {
        },
                                error =>
        {
            if (error.Contains("'lfs' is "))
            {
                EditorUtility.DisplayDialog("Version Control", "Error: Git LFS is not installed.  File locking will not work.  Please install Git LFS.", "Okay");
                GitHelper.LFSEnabled = false;
            }
            return(true);
        });

        if (!GitHelper.LFSEnabled)
        {
            return;
        }

        foreach (var v in LockedFiles)
        {
            if (v.Value.FileLock != null)
            {
                v.Value.FileLock.Dispose();
            }
        }

        LockedFiles.Clear();

        if (GitHelper.LFSEnabled)
        {
            GitHelper.RunGitCommand("lfs locks",
                                    proc =>
            {
                try
                {
                    while (!proc.HasExited)
                    {
                        if (EditorUtility.DisplayCancelableProgressBar("Version Control", "Refreshing LFS locks...", 0))
                        {
                            proc.Kill();
                            return(true);
                        }
                        Thread.Sleep(16);
                    }
                }
                finally
                {
                    EditorUtility.ClearProgressBar();
                }
                return(false);
            },

                                    result =>
            {
                var parts = result.Split('\t');
                var path  = GitHelper.GitToUnityPath(parts[0]);
                Debug.Log("Locking path " + path + "(from " + parts[0] + ")");
                var user = parts[1];

                var locked  = new LockedFile();
                locked.Path = path;
                locked.User = user;

                if (user != GitHelper.Username && GitHelper.PreventEditsOnRemoteLock)
                {
                    if (File.Exists(path))
                    {
                        try
                        {
                            locked.FileLock = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                        }
                        catch (System.Exception ex)
                        {
                            Debug.LogError("Failed to create file lock for " + path + ": " + ex);
                        }
                    }
                }
                LockedFiles.Add(path.Trim(), locked);
            },

                                    error =>
            {
                Debug.LogError(error);
                return(true);
            }
                                    );
        }

        UpdateLockedFiles();
        EditorApplication.RepaintProjectWindow();
    }
예제 #2
0
    /// <summary>
    /// Locks a set of files in git.
    /// </summary>
    /// <param name="paths"></param>
    /// <returns></returns>
    public bool GitLockFile(string[] paths)
    {
        if (!GitHelper.LFSEnabled)
        {
            return(false);
        }

        var cmdstring = new StringBuilder();

        foreach (var path in paths)
        {
            cmdstring.Append('"' + path + '"');
        }

        /*
         * GitHelper.RunGitCommand("track -- " + cmdstring,
         *  proc =>
         *  {
         *      if (!proc.WaitForExit(5000))
         *      {
         *          return true;
         *      }
         *      return false;
         *  }
         * );*/

        bool hasError = GitHelper.RunGitCommand("lfs lock -- " + cmdstring,
                                                proc =>
        {
            try
            {
                while (!proc.HasExited)
                {
                    if (paths.Length > 1)
                    {
                        if (EditorUtility.DisplayCancelableProgressBar("Version Control", "Locking files " + (cmdstring.ToString()) + "...", 0))
                        {
                            proc.Kill();
                            return(true);
                        }
                    }
                    else
                    {
                        if (EditorUtility.DisplayCancelableProgressBar("Version Control", "Locking file " + Path.GetFileName(paths[0]) + "...", 0))
                        {
                            proc.Kill();
                            return(true);
                        }
                    }
                    Thread.Sleep(16);
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
            return(false);
        },
                                                result =>
        {
            Debug.Log("[LFS Lock] " + result);
            if (!result.Contains("Locked"))
            {
                // Failed for some reason and didn't go to std::error, search for updated locks.
                RefreshGitLocks();
            }
            else
            {
                foreach (var path in paths)
                {
                    var locked  = new LockedFile();
                    locked.Path = GitHelper.GitToUnityPath(path);
                    locked.User = GitHelper.Username;
                    LockedFiles.Add(path.Trim(), locked);
                }
            }
        },
                                                error =>
        {
            Debug.Log("Failed to lock " + cmdstring);
            Debug.LogError(error);
            return(true);
        });

        EditorApplication.RepaintProjectWindow();
        UpdateLockedFiles();
        return(!hasError);
    }
예제 #3
0
    public void RefreshGitLocks()
    {
        foreach (var v in LockedFiles)
        {
            if (v.Value.FileLock != null)
            {
                v.Value.FileLock.Close();
            }
        }

        LockedFiles.Clear();

        GitHelper.RunGitCommand("lfs locks",
                                proc =>
        {
            try
            {
                while (!proc.HasExited)
                {
                    if (EditorUtility.DisplayCancelableProgressBar("Version Control", "Refreshing LFS locks...", 0))
                    {
                        proc.Kill();
                        return(true);
                    }
                    Thread.Sleep(16);
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
            return(false);
        },

                                result =>
        {
            var parts = result.Split('\t');
            var path  = parts[0];
            var user  = parts[1];

            var locked  = new LockedFile();
            locked.Path = path;
            locked.User = user;
            if (user != GitHelper.Username && GitHelper.PreventEditsOnRemoteLock)
            {
                try
                {
                    locked.FileLock = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
                }
                catch (System.Exception ex)
                {
                    Debug.LogError("Failed to create file lock for " + path + ": " + ex);
                }
            }
            LockedFiles.Add(path.Trim(), locked);
        },

                                error =>
        {
            Debug.LogError(error);
            return(true);
        }
                                );

        UpdateLockedFiles();
        EditorApplication.RepaintProjectWindow();
    }