示例#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));
            }
        }
    }
    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);
                }
            }
        }
    }
        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);
            });
        }
示例#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);
    }
    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);
    }