static void Git_Test_Clone()
 {
     GitUtil.Clone(GitTestBaseDir, GitUrl);
 }
    public static void StartRepository(string repoUrl)
    {
        Module.CheckInitalized();

        lock (RepositoryUpdateLock)
        {
            if (repoUrl.IndexOf("@") != -1)
            {
                throw new ArgumentException($"The repository name \'{repoUrl}\' must not contain '@'.");
            }

            if (Data.IsReadOnly)
            {
                throw new ApplicationException("Data.IsReadOnly");
            }

            lock (Data.DataLock)
            {
                GitGlobalFsRepository?repoData = Data.ManagedData.RepositoryList.Where(x => x.Url._IsSamei(repoUrl)).SingleOrDefault();

L_RETRY:

                if (repoData == null)
                {
                    string dirName     = GenerateNewRepositoryDirName(repoUrl);
                    string dirFullPath = Lfs.PathParser.Combine(RepoDir, dirName);

                    Con.WriteDebug($"Clone the repository \"{repoUrl}\" to \"{dirFullPath}\" ...");
                    try
                    {
                        GitUtil.Clone(dirFullPath, repoUrl);
                    }
                    catch (Exception ex)
                    {
                        Con.WriteError($"GitUtil.Clone error: {ex.ToString()}");
                        throw;
                    }
                    Con.WriteDebug("Done.");
                    GitRepository gitRepo = new GitRepository(dirFullPath);
                    repoData = new GitGlobalFsRepository()
                    {
                        Url          = repoUrl,
                        LocalWorkDir = dirName,
                        Repository   = gitRepo,
                    };

                    Data.ManagedData.RepositoryList.Add(repoData);
                }
                else
                {
                    repoData.Url = repoUrl;

                    if (repoData.Repository == null)
                    {
                        string dirName     = repoData.LocalWorkDir._NullCheck();
                        string dirFullPath = Lfs.PathParser.Combine(RepoDir, dirName);

                        try
                        {
                            GitRepository gitRepo = new GitRepository(dirFullPath);
                            repoData.Repository = gitRepo;
                        }
                        catch (Exception ex)
                        {
                            Con.WriteDebug($"Repository local dir \"{dirFullPath}\" load error: {ex.ToString()}");
                            Con.WriteDebug($"Trying to clone as a new local dir.");

                            Data.ManagedData.RepositoryList.Remove(repoData);
                            Data.SyncWithStorage(HiveSyncFlags.SaveToFile, false);

                            repoData = null;
                            goto L_RETRY;
                        }
                    }
                }
            }

            Data.SyncWithStorage(HiveSyncFlags.SaveToFile, false);

            StartUpdateLoop();
        }
    }