Beispiel #1
0
        public void TryGetRepositoryPath_fails_when_starting_path_is_not_a_git_repository()
        {
            // ARRANGE
            using var temporaryDirectory = new TemporaryDirectory();

            // ACT
            var success = RepositoryLocator.TryGetRepositoryPath(temporaryDirectory, out var actualRepositoryPath);

            // ASSERT
            Assert.False(success);
            Assert.Null(actualRepositoryPath);
        }
Beispiel #2
0
        public async Task TryGetRepositoryPath_fails_when_starting_path_is_a_bare_repository()
        {
            // ARRANGE
            using var temporaryDirectory = new TemporaryDirectory();
            var git = new GitWrapper(temporaryDirectory, m_TestOutputHelper);
            await git.InitAsync(createBareRepository : true);

            // ACT
            var success = RepositoryLocator.TryGetRepositoryPath(temporaryDirectory, out var actualRepositoryPath);

            // ASSERT
            Assert.False(success);
            Assert.Null(actualRepositoryPath);
        }
Beispiel #3
0
        public async Task TryGetRepositoryPath_succeeds_when_starting_path_is_a_git_repository()
        {
            // ARRANGE
            using var temporaryDirectory = new TemporaryDirectory();
            var git = new GitWrapper(temporaryDirectory, m_TestOutputHelper);
            await git.InitAsync();

            // ACT
            var success = RepositoryLocator.TryGetRepositoryPath(temporaryDirectory, out var actualRepositoryPath);

            // ASSERT
            Assert.True(success);
            Assert.Equal(temporaryDirectory, actualRepositoryPath?.TrimEnd(Path.DirectorySeparatorChar));
        }
Beispiel #4
0
        private static bool TryGetRepositoryPath(CommandLineParameters parameters, ILogger logger, [NotNullWhen(true)] out string?repositoryPath)
        {
            if (!String.IsNullOrEmpty(parameters.RepositoryPath))
            {
                repositoryPath = Path.GetFullPath(parameters.RepositoryPath);
                return(true);
            }

            if (RepositoryLocator.TryGetRepositoryPath(Environment.CurrentDirectory, out repositoryPath))
            {
                logger.LogInformation($"Found git repository at '{repositoryPath}'");
                return(true);
            }
            else
            {
                logger.LogError($"No git repository found in '{Environment.CurrentDirectory}' or any of its parent directories");
                repositoryPath = default;
                return(false);
            }
        }