Exemplo n.º 1
0
    public void WorksCorrectlyWithRemoteRepository(string branchName, string expectedBranchName)
    {
        var tempDir = Path.GetTempPath();

        using (var fixture = new EmptyRepositoryFixture(new Config()))
        {
            fixture.Repository.MakeCommits(5);
            fixture.Repository.CreateBranch("feature/foo");
            var arguments = new Arguments
            {
                TargetPath = tempDir,
                TargetUrl  = fixture.RepositoryPath
            };

            if (!string.IsNullOrWhiteSpace(branchName))
            {
                arguments.TargetBranch = branchName;
            }

            var gitPreparer           = new GitPreparer(arguments);
            var dynamicRepositoryPath = gitPreparer.Prepare();

            Assert.AreEqual(Path.Combine(tempDir, "_dynamicrepository", ".git"), dynamicRepositoryPath);
            Assert.IsTrue(gitPreparer.IsDynamicGitRepository);

            using (var repository = new Repository(dynamicRepositoryPath))
            {
                var currentBranch = repository.Head.CanonicalName;

                Assert.IsTrue(currentBranch.EndsWith(expectedBranchName));
            }
        }
    }
Exemplo n.º 2
0
    public void WorksCorrectlyWithRemoteRepository(string branchName, string expectedBranchName, bool checkConfig)
    {
        var tempDir = Path.GetTempPath();

        using (var fixture = new EmptyRepositoryFixture(new Config()))
        {
            fixture.Repository.MakeCommits(5);

            if (checkConfig)
            {
                fixture.Repository.CreateFileAndCommit("GitVersionConfig.yaml");
            }

            fixture.Repository.CreateBranch(SpecificBranchName);

            if (checkConfig)
            {
                fixture.Repository.Refs.UpdateTarget(fixture.Repository.Refs.Head, fixture.Repository.Refs["refs/heads/" + SpecificBranchName]);

                fixture.Repository.CreateFileAndCommit("GitVersionConfig.yaml");

                fixture.Repository.Refs.UpdateTarget(fixture.Repository.Refs.Head, fixture.Repository.Refs["refs/heads/" + DefaultBranchName]);
            }

            var arguments = new Arguments
            {
                TargetPath = tempDir,
                TargetUrl  = fixture.RepositoryPath
            };

            if (!string.IsNullOrWhiteSpace(branchName))
            {
                arguments.TargetBranch = branchName;
            }

            var gitPreparer           = new GitPreparer(arguments);
            var dynamicRepositoryPath = gitPreparer.Prepare();

            dynamicRepositoryPath.ShouldBe(Path.Combine(tempDir, "_dynamicrepository", ".git"));
            gitPreparer.IsDynamicGitRepository.ShouldBe(true);

            using (var repository = new Repository(dynamicRepositoryPath))
            {
                var currentBranch = repository.Head.CanonicalName;

                currentBranch.EndsWith(expectedBranchName).ShouldBe(true);

                if (checkConfig)
                {
                    var expectedConfigPath = Path.Combine(dynamicRepositoryPath, "..\\GitVersionConfig.yaml");
                    File.Exists(expectedConfigPath).ShouldBe(true);
                }
            }
        }
    }
Exemplo n.º 3
0
        public void CacheKeySameAfterReNormalizing()
        {
            RepositoryScope((fixture, vv) =>
            {
                var targetUrl    = "https://github.com/GitTools/GitVersion.git";
                var targetBranch = "refs/head/master";

                var arguments = new Arguments
                {
                    TargetUrl  = targetUrl,
                    TargetPath = fixture.RepositoryPath
                };
                var gitPreparer   = new GitPreparer(log, environment, Options.Create(arguments));
                configFileLocator = new DefaultConfigFileLocator(fileSystem, log);

                gitPreparer.Prepare(true, targetBranch);
                var cacheKey1 = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, configFileLocator, null);
                gitPreparer.Prepare(true, targetBranch);
                var cacheKey2 = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, configFileLocator, null);

                cacheKey2.Value.ShouldBe(cacheKey1.Value);
            });
        }
Exemplo n.º 4
0
    public void WorksCorrectlyWithLocalRepository()
    {
        var tempDir = Path.GetTempPath();

        var arguments = new Arguments
        {
            TargetPath = tempDir
        };

        var gitPreparer           = new GitPreparer(arguments);
        var dynamicRepositoryPath = gitPreparer.Prepare();

        Assert.AreEqual(null, dynamicRepositoryPath);
        Assert.IsFalse(gitPreparer.IsDynamicGitRepository);
    }
Exemplo n.º 5
0
    public void WorksCorrectlyWithLocalRepository()
    {
        var tempDir = Path.GetTempPath();

        var arguments = new Arguments
        {
            TargetPath = tempDir
        };

        var gitPreparer           = new GitPreparer(arguments);
        var dynamicRepositoryPath = gitPreparer.Prepare();

        dynamicRepositoryPath.ShouldBe(null);
        gitPreparer.IsDynamicGitRepository.ShouldBe(false);
    }