Exemple #1
0
    public void UsingDynamicRepositoryWithFeatureBranchWorks()
    {
        var repoName = Guid.NewGuid().ToString();
        var tempPath = Path.GetTempPath();
        var tempDir  = Path.Combine(tempPath, repoName);

        Directory.CreateDirectory(tempDir);

        try
        {
            using (var mainRepositoryFixture = new EmptyRepositoryFixture(new Config()))
            {
                mainRepositoryFixture.Repository.MakeACommit();

                var gitPreparer = new GitPreparer(mainRepositoryFixture.RepositoryPath, null, new Authentication(), false, tempDir);
                gitPreparer.Initialise(true, "feature1");

                mainRepositoryFixture.Repository.Checkout(mainRepositoryFixture.Repository.CreateBranch("feature1"));

                Should.NotThrow(() => gitPreparer.Initialise(true, "feature1"));
            }
        }
        finally
        {
            Directory.Delete(tempDir, true);
        }
    }
    public void UsingDynamicRepositoryWithFeatureBranchWorks()
    {
        var repoName = Guid.NewGuid().ToString();
        var tempPath = Path.GetTempPath();
        var tempDir  = Path.Combine(tempPath, repoName);

        Directory.CreateDirectory(tempDir);

        try
        {
            using (var mainRepositoryFixture = new EmptyRepositoryFixture(new Config()))
            {
                var commitId = mainRepositoryFixture.Repository.MakeACommit().Id.Sha;

                var arguments = new Arguments
                {
                    TargetPath   = tempDir,
                    TargetUrl    = mainRepositoryFixture.RepositoryPath,
                    TargetBranch = "feature1",
                    CommitId     = commitId
                };

                var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
                gitPreparer.Initialise(true);

                mainRepositoryFixture.Repository.CreateBranch("feature1").Checkout();

                Assert.DoesNotThrow(() => gitPreparer.Initialise(true));
            }
        }
        finally
        {
            Directory.Delete(tempDir, true);
        }
    }
Exemple #3
0
    public void CacheKeySameAfterReNormalizing()
    {
        var versionAndBranchFinder = new ExecuteCore(fileSystem);

        RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
        {
            var targetUrl    = "https://github.com/GitTools/GitVersion.git";
            var targetBranch = "refs/head/master";
            var gitPreparer  = new GitPreparer(targetUrl, null, new Authentication(), false, fixture.RepositoryPath);
            gitPreparer.Initialise(true, targetBranch);
            var cacheKey1 = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null);
            gitPreparer.Initialise(true, targetBranch);
            var cacheKey2 = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null);

            cacheKey2.Value.ShouldBe(cacheKey1.Value);
        });
    }
    public void UpdatesExistingDynamicRepository()
    {
        var repoName = Guid.NewGuid().ToString();
        var tempPath = Path.GetTempPath();
        var tempDir  = Path.Combine(tempPath, repoName);

        Directory.CreateDirectory(tempDir);
        string dynamicRepositoryPath = null;

        try
        {
            using (var mainRepositoryFixture = new EmptyRepositoryFixture(new Config()))
            {
                mainRepositoryFixture.Repository.MakeCommits(1);

                var arguments = new Arguments
                {
                    TargetPath   = tempDir,
                    TargetUrl    = mainRepositoryFixture.RepositoryPath,
                    TargetBranch = "master"
                };

                var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
                gitPreparer.Initialise(false);
                dynamicRepositoryPath = gitPreparer.GetDotGitDirectory();

                var newCommit = mainRepositoryFixture.Repository.MakeACommit();
                gitPreparer.Initialise(false);

                using (var repository = new Repository(dynamicRepositoryPath))
                {
                    mainRepositoryFixture.Repository.DumpGraph();
                    repository.DumpGraph();
                    repository.Commits.ShouldContain(c => c.Sha == newCommit.Sha);
                }
            }
        }
        finally
        {
            Directory.Delete(tempDir, true);
            if (dynamicRepositoryPath != null)
            {
                DeleteHelper.DeleteGitRepository(dynamicRepositoryPath);
            }
        }
    }
    public void WorksCorrectlyWithRemoteRepository(string branchName, string expectedBranchName)
    {
        var repoName = Guid.NewGuid().ToString();
        var tempPath = Path.GetTempPath();
        var tempDir  = Path.Combine(tempPath, repoName);

        Directory.CreateDirectory(tempDir);
        string dynamicRepositoryPath = null;

        try
        {
            using (var fixture = new EmptyRepositoryFixture(new Config()))
            {
                var expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split('\\').Last());

                fixture.Repository.MakeCommits(5);
                fixture.Repository.CreateFileAndCommit("TestFile.txt");

                fixture.Repository.CreateBranch(SpecificBranchName);

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

                // Copy contents into working directory
                File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt"));

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

                var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
                gitPreparer.Initialise(false);
                dynamicRepositoryPath = gitPreparer.GetDotGitDirectory();

                gitPreparer.IsDynamicGitRepository.ShouldBe(true);
                gitPreparer.DynamicGitRepositoryPath.ShouldBe(expectedDynamicRepoLocation + "\\.git");

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

                    currentBranch.EndsWith(expectedBranchName).ShouldBe(true);
                }
            }
        }
        finally
        {
            Directory.Delete(tempDir, true);
            if (dynamicRepositoryPath != null)
            {
                DeleteHelper.DeleteGitRepository(dynamicRepositoryPath);
            }
        }
    }
    public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
    {
        var repoName = Guid.NewGuid().ToString();
        var tempPath = Path.GetTempPath();
        var tempDir  = Path.Combine(tempPath, repoName);

        Directory.CreateDirectory(tempDir);
        string expectedDynamicRepoLocation = null;

        try
        {
            using (var fixture = new EmptyRepositoryFixture(new Config()))
            {
                fixture.Repository.CreateFileAndCommit("TestFile.txt");
                File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt"));
                expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split('\\').Last());
                Directory.CreateDirectory(expectedDynamicRepoLocation);

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

                var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
                gitPreparer.Initialise(false);

                gitPreparer.IsDynamicGitRepository.ShouldBe(true);
                gitPreparer.DynamicGitRepositoryPath.ShouldBe(expectedDynamicRepoLocation + "_1\\.git");
            }
        }
        finally
        {
            Directory.Delete(tempDir, true);
            if (expectedDynamicRepoLocation != null)
            {
                Directory.Delete(expectedDynamicRepoLocation, true);
            }
            if (expectedDynamicRepoLocation != null)
            {
                DeleteHelper.DeleteGitRepository(expectedDynamicRepoLocation + "_1");
            }
        }
    }
Exemple #7
0
    public void TestErrorThrownForInvalidRepository()
    {
        var repoName = Guid.NewGuid().ToString();
        var tempPath = Path.GetTempPath();
        var tempDir  = Path.Combine(tempPath, repoName);

        Directory.CreateDirectory(tempDir);

        try
        {
            var gitPreparer = new GitPreparer("http://127.0.0.1/testrepo.git", null, new Authentication(), false, tempDir);

            Should.Throw <Exception>(() => gitPreparer.Initialise(true, "master"));
        }
        finally
        {
            Directory.Delete(tempDir, true);
        }
    }
Exemple #8
0
    public void TestErrorThrownForInvalidRepository()
    {
        var repoName = Guid.NewGuid().ToString();
        var tempPath = Path.GetTempPath();
        var tempDir = Path.Combine(tempPath, repoName);
        Directory.CreateDirectory(tempDir);

        try
        {
            var arguments = new Arguments
            {
                TargetPath = tempDir,
                TargetUrl = "http://127.0.0.1/testrepo.git"
            };

            var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);

            Assert.Throws<Exception>(() => gitPreparer.Initialise(true));
        }
        finally
        {
            Directory.Delete(tempDir, true);
        }
    }