예제 #1
0
        public CommandContext()
        {
            Streams = new StandardStreams();
            Trace   = new Trace();
            Git     = new LibGit2(Trace);

            if (PlatformUtils.IsWindows())
            {
                FileSystem      = new WindowsFileSystem();
                Environment     = new WindowsEnvironment(FileSystem);
                Terminal        = new WindowsTerminal(Trace);
                CredentialStore = WindowsCredentialManager.Open();
            }
            else if (PlatformUtils.IsPosix())
            {
                if (PlatformUtils.IsMacOS())
                {
                    FileSystem      = new MacOSFileSystem();
                    CredentialStore = MacOSKeychain.Open();
                }
                else if (PlatformUtils.IsLinux())
                {
                    throw new NotImplementedException();
                }

                Environment = new PosixEnvironment(FileSystem);
                Terminal    = new PosixTerminal(Trace);
            }

            string repoPath = Git.GetRepositoryPath(FileSystem.GetCurrentDirectory());

            Settings          = new Settings(Environment, Git, repoPath);
            HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams);
        }
예제 #2
0
        public CommandContext()
        {
            Streams    = new StandardStreams();
            Trace      = new Trace();
            FileSystem = new FileSystem();

            var git    = new LibGit2();
            var envars = new EnvironmentVariables(Environment.GetEnvironmentVariables());

            Settings = new Settings(envars, git)
            {
                RepositoryPath = git.GetRepositoryPath(FileSystem.GetCurrentDirectory())
            };

            HttpClientFactory = new HttpClientFactory(Trace, Settings, Streams);

            if (PlatformUtils.IsWindows())
            {
                Terminal        = new WindowsTerminal(Trace);
                CredentialStore = WindowsCredentialManager.Open();
            }
            else if (PlatformUtils.IsPosix())
            {
                Terminal = new PosixTerminal(Trace);

                if (PlatformUtils.IsMacOS())
                {
                    CredentialStore = MacOSKeychain.Open();
                }
                else if (PlatformUtils.IsLinux())
                {
                    throw new NotImplementedException();
                }
            }
        }
예제 #3
0
        public void LibGit2_GetRepositoryPath_NotInsideRepository_ReturnsNull()
        {
            var    git        = new LibGit2();
            string randomPath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid():N}");

            Directory.CreateDirectory(randomPath);

            string repositoryPath = git.GetRepositoryPath(randomPath);

            Assert.Null(repositoryPath);
        }
예제 #4
0
        public void LibGit2Configuration_GetRepositoryPath_ReturnsRepositoryPath()
        {
            string repoBasePath        = CreateRepository();
            string expectedRepoGitPath = Path.Combine(repoBasePath, ".git") + "/";
            string fileL0Path          = Path.Combine(repoBasePath, "file.txt");
            string directoryL0Path     = Path.Combine(repoBasePath, "directory");
            string fileL1Path          = Path.Combine(directoryL0Path, "inner-file.txt");
            string directoryL1Path     = Path.Combine(directoryL0Path, "sub-directory");

            var git = new LibGit2();

            // Create files and directories
            Directory.CreateDirectory(directoryL0Path);
            Directory.CreateDirectory(directoryL1Path);
            File.WriteAllText(fileL0Path, string.Empty);
            File.WriteAllText(fileL1Path, string.Empty);

            // Check from L0 file
            string fileL0RepoPath = git.GetRepositoryPath(fileL0Path);

            AssertPathsEquivalent(expectedRepoGitPath, fileL0RepoPath);

            // Check from L0 directory
            string dirL0RepoPath = git.GetRepositoryPath(directoryL0Path);

            AssertPathsEquivalent(expectedRepoGitPath, dirL0RepoPath);

            // Check from L1 file
            string fileL1RepoPath = git.GetRepositoryPath(fileL1Path);

            AssertPathsEquivalent(expectedRepoGitPath, fileL1RepoPath);

            // Check from L1 directory
            string dirL1RepoPath = git.GetRepositoryPath(directoryL1Path);

            AssertPathsEquivalent(expectedRepoGitPath, dirL1RepoPath);
        }