Exemplo n.º 1
0
        protected IEnvironment InitializePlatformAndEnvironment(NPath repoPath,
                                                                NPath?environmentPath       = null,
                                                                bool enableEnvironmentTrace = false,
                                                                bool setupGit = true,
                                                                Action <IRepositoryManager> onRepositoryManagerCreated = null,
                                                                [CallerMemberName] string testName = "")
        {
            InitializePlatform(repoPath, environmentPath, enableEnvironmentTrace, setupGit, testName);

            DotGitPath = repoPath.Combine(".git");

            if (DotGitPath.FileExists())
            {
                DotGitPath = DotGitPath.ReadAllLines().Where(x => x.StartsWith("gitdir:"))
                             .Select(x => x.Substring(7).Trim().ToNPath()).First();
            }

            BranchesPath = DotGitPath.Combine("refs", "heads");
            RemotesPath  = DotGitPath.Combine("refs", "remotes");
            DotGitIndex  = DotGitPath.Combine("index");
            DotGitHead   = DotGitPath.Combine("HEAD");
            DotGitConfig = DotGitPath.Combine("config");

            RepositoryManager = GitHub.Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, Environment.FileSystem, repoPath);
            RepositoryManager.Initialize();

            onRepositoryManagerCreated?.Invoke(RepositoryManager);

            Environment.Repository?.Initialize(RepositoryManager, TaskManager);

            RepositoryManager.Start();
            Environment.Repository?.Start();
            return(Environment);
        }
Exemplo n.º 2
0
        protected async Task <IEnvironment> Initialize(NPath repoPath, NPath environmentPath = null,
                                                       bool enableEnvironmentTrace           = false, bool initializeRepository = true, Action <RepositoryManager> onRepositoryManagerCreated = null)
        {
            TaskManager             = new TaskManager();
            SyncContext             = new ThreadSynchronizationContext(TaskManager.Token);
            TaskManager.UIScheduler = new SynchronizationContextTaskScheduler(SyncContext);

            //TODO: Mock CacheContainer
            ICacheContainer cacheContainer = Substitute.For <ICacheContainer>();

            Environment = new IntegrationTestEnvironment(cacheContainer, repoPath, SolutionDirectory, environmentPath, enableEnvironmentTrace);

            var gitSetup = new GitInstaller(Environment, TaskManager.Token);
            await gitSetup.SetupIfNeeded();

            Environment.GitExecutablePath = gitSetup.GitExecutablePath;

            Platform = new Platform(Environment);

            GitEnvironment = Platform.GitEnvironment;
            ProcessManager = new ProcessManager(Environment, GitEnvironment, TaskManager.Token);

            Platform.Initialize(ProcessManager, TaskManager);

            GitClient = new GitClient(Environment, ProcessManager, TaskManager);

            var repositoryManager = GitHub.Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, repoPath);

            onRepositoryManagerCreated?.Invoke(repositoryManager);

            RepositoryManager = repositoryManager;
            RepositoryManager.Initialize();

            if (initializeRepository)
            {
                Environment.Repository = new Repository(repoPath, cacheContainer);
                Environment.Repository.Initialize(RepositoryManager);
            }

            RepositoryManager.Start();

            DotGitPath = repoPath.Combine(".git");

            if (DotGitPath.FileExists())
            {
                DotGitPath =
                    DotGitPath.ReadAllLines()
                    .Where(x => x.StartsWith("gitdir:"))
                    .Select(x => x.Substring(7).Trim().ToNPath())
                    .First();
            }

            BranchesPath = DotGitPath.Combine("refs", "heads");
            RemotesPath  = DotGitPath.Combine("refs", "remotes");
            DotGitIndex  = DotGitPath.Combine("index");
            DotGitHead   = DotGitPath.Combine("HEAD");
            DotGitConfig = DotGitPath.Combine("config");
            return(Environment);
        }
Exemplo n.º 3
0
        protected async Task <IEnvironment> Initialize(NPath repoPath, NPath environmentPath = null,
                                                       bool enableEnvironmentTrace           = false)
        {
            TaskManager             = new TaskManager();
            SyncContext             = new ThreadSynchronizationContext(TaskManager.Token);
            TaskManager.UIScheduler = new SynchronizationContextTaskScheduler(SyncContext);

            Environment = new IntegrationTestEnvironment(repoPath, SolutionDirectory, environmentPath, enableEnvironmentTrace);

            var gitSetup = new GitInstaller(Environment, TaskManager.Token);
            await gitSetup.SetupIfNeeded();

            Environment.GitExecutablePath = gitSetup.GitExecutablePath;

            Platform       = new Platform(Environment);
            GitEnvironment = Platform.GitEnvironment;
            ProcessManager = new ProcessManager(Environment, GitEnvironment, TaskManager.Token);

            Platform.Initialize(ProcessManager, TaskManager);

            GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);

            var usageTracker = new NullUsageTracker();

            var repositoryManagerFactory = new RepositoryManagerFactory();

            RepositoryManager = repositoryManagerFactory.CreateRepositoryManager(Platform, TaskManager, usageTracker, GitClient, repoPath);
            await RepositoryManager.Initialize();

            RepositoryManager.Start();

            Environment.Repository = RepositoryManager.Repository;

            DotGitPath = repoPath.Combine(".git");

            if (DotGitPath.FileExists())
            {
                DotGitPath =
                    DotGitPath.ReadAllLines()
                    .Where(x => x.StartsWith("gitdir:"))
                    .Select(x => x.Substring(7).Trim().ToNPath())
                    .First();
            }

            BranchesPath = DotGitPath.Combine("refs", "heads");
            RemotesPath  = DotGitPath.Combine("refs", "remotes");
            DotGitIndex  = DotGitPath.Combine("index");
            DotGitHead   = DotGitPath.Combine("HEAD");
            DotGitConfig = DotGitPath.Combine("config");
            return(Environment);
        }
Exemplo n.º 4
0
 public TestRepoData(TestData test, string repoName)
 {
     RepoPath   = test.TestPath.Combine("IOTestsRepo", repoName);
     DotGitPath = RepoPath.Combine(".git");
     if (DotGitPath.FileExists())
     {
         DotGitPath = DotGitPath.ReadAllLines().Where(x => x.StartsWith("gitdir:"))
                      .Select(x => x.Substring(7).Trim().ToSPath()).First();
     }
     BranchesPath = DotGitPath.Combine("refs", "heads");
     RemotesPath  = DotGitPath.Combine("refs", "remotes");
     DotGitIndex  = DotGitPath.Combine("index");
     DotGitHead   = DotGitPath.Combine("HEAD");
     DotGitConfig = DotGitPath.Combine("config");
 }
Exemplo n.º 5
0
        public RepositoryPathConfiguration(NPath repositoryPath)
        {
            RepositoryPath     = repositoryPath;
            WorktreeDotGitPath = NPath.Default;

            DotGitPath = repositoryPath.Combine(".git");
            NPath commonPath;

            if (DotGitPath.FileExists())
            {
                DotGitPath =
                    DotGitPath.ReadAllLines()
                    .Where(x => x.StartsWith("gitdir:"))
                    .Select(x => x.Substring(7).Trim().ToNPath())
                    .First();
                if (DotGitPath.Combine("commondir").FileExists())
                {
                    commonPath = DotGitPath.Combine("commondir").ReadAllLines()
                                 .Select(x => x.Trim().ToNPath())
                                 .First();
                    commonPath = DotGitPath.Combine(commonPath);

                    IsWorktree         = true;
                    WorktreeDotGitPath = commonPath;
                }
                else
                {
                    commonPath = DotGitPath;
                }
            }
            else
            {
                commonPath = DotGitPath;
            }

            BranchesPath        = commonPath.Combine("refs", "heads");
            RemotesPath         = commonPath.Combine("refs", "remotes");
            DotGitIndex         = DotGitPath.Combine("index");
            DotGitHead          = DotGitPath.Combine("HEAD");
            DotGitConfig        = commonPath.Combine("config");
            DotGitCommitEditMsg = DotGitPath.Combine("COMMIT_EDITMSG");
        }
Exemplo n.º 6
0
        public RepositoryPathConfiguration(NPath repositoryPath)
        {
            RepositoryPath = repositoryPath;

            DotGitPath = repositoryPath.Combine(".git");
            if (DotGitPath.FileExists())
            {
                DotGitPath =
                    DotGitPath.ReadAllLines()
                    .Where(x => x.StartsWith("gitdir:"))
                    .Select(x => x.Substring(7).Trim().ToNPath())
                    .First();
            }

            BranchesPath = DotGitPath.Combine("refs", "heads");
            RemotesPath  = DotGitPath.Combine("refs", "remotes");
            DotGitIndex  = DotGitPath.Combine("index");
            DotGitHead   = DotGitPath.Combine("HEAD");
            DotGitConfig = DotGitPath.Combine("config");
        }
Exemplo n.º 7
0
        protected IEnvironment Initialize(NPath repoPath, NPath environmentPath = null,
                                          bool enableEnvironmentTrace           = false, bool initializeRepository = true,
                                          Action <RepositoryManager> onRepositoryManagerCreated = null)
        {
            InitializePlatform(repoPath, environmentPath, enableEnvironmentTrace);

            var repositoryManager =
                GitHub.Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, repoPath);

            onRepositoryManagerCreated?.Invoke(repositoryManager);

            RepositoryManager = repositoryManager;
            RepositoryManager.Initialize();

            if (initializeRepository)
            {
                Environment.Repository = new Repository(repoPath, CacheContainer);
                Environment.Repository.Initialize(RepositoryManager);
            }

            RepositoryManager.Start();

            DotGitPath = repoPath.Combine(".git");

            if (DotGitPath.FileExists())
            {
                DotGitPath = DotGitPath.ReadAllLines().Where(x => x.StartsWith("gitdir:"))
                             .Select(x => x.Substring(7).Trim().ToNPath()).First();
            }

            BranchesPath = DotGitPath.Combine("refs", "heads");
            RemotesPath  = DotGitPath.Combine("refs", "remotes");
            DotGitIndex  = DotGitPath.Combine("index");
            DotGitHead   = DotGitPath.Combine("HEAD");
            DotGitConfig = DotGitPath.Combine("config");
            return(Environment);
        }