예제 #1
0
        public void CacheKeyForWorktree()
        {
            var versionAndBranchFinder = new ExecuteCore(fileSystem, environment);

            RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
            {
                var worktreePath = Path.Combine(Directory.GetParent(fixture.RepositoryPath).FullName, Guid.NewGuid().ToString());
                try
                {
                    // create a branch and a new worktree for it
                    var repo = new Repository(fixture.RepositoryPath);
                    repo.Worktrees.Add("worktree", worktreePath, false);

                    var targetUrl         = "https://github.com/GitTools/GitVersion.git";
                    var gitPreparer       = new GitPreparer(targetUrl, null, new Authentication(), false, worktreePath);
                    var configFileLocator = new DefaultConfigFileLocator();
                    var cacheKey          = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null, configFileLocator);
                    cacheKey.Value.ShouldNotBeEmpty();
                }
                finally
                {
                    DirectoryHelper.DeleteDirectory(worktreePath);
                }
            });
        }
예제 #2
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 WriteVariablesToDiskCache(GitPreparer gitPreparer, GitVersionCacheKey cacheKey, VersionVariables variablesFromCache)
        {
            var cacheDir      = PrepareCacheDirectory(gitPreparer);
            var cacheFileName = GetCacheFileName(cacheKey, cacheDir);

            variablesFromCache.FileName = cacheFileName;

            Dictionary <string, string> dictionary;

            using (log.IndentLog("Creating dictionary"))
            {
                dictionary = variablesFromCache.ToDictionary(x => x.Key, x => x.Value);
            }

            void WriteCacheOperation()
            {
                using (var stream = fileSystem.OpenWrite(cacheFileName))
                {
                    using (var sw = new StreamWriter(stream))
                    {
                        using (log.IndentLog("Storing version variables to cache file " + cacheFileName))
                        {
                            var serializer = new Serializer();
                            serializer.Serialize(sw, dictionary);
                        }
                    }
                }
            }

            var retryOperation = new OperationWithExponentialBackoff <IOException>(new ThreadSleep(), log, WriteCacheOperation, maxRetries: 6);

            retryOperation.ExecuteAsync().Wait();
        }
        public static string GetCacheDirectory(GitPreparer gitPreparer)
        {
            var gitDir   = gitPreparer.GetDotGitDirectory();
            var cacheDir = Path.Combine(gitDir, "gitversion_cache");

            return(cacheDir);
        }
예제 #5
0
        public void CacheKeyForWorktree()
        {
            RepositoryScope((fixture, vv) =>
            {
                var worktreePath = Path.Combine(Directory.GetParent(fixture.RepositoryPath).FullName, Guid.NewGuid().ToString());
                try
                {
                    // create a branch and a new worktree for it
                    var repo = new Repository(fixture.RepositoryPath);
                    repo.Worktrees.Add("worktree", worktreePath, false);

                    var targetUrl = "https://github.com/GitTools/GitVersion.git";

                    var arguments = new Arguments
                    {
                        TargetUrl  = targetUrl,
                        TargetPath = worktreePath
                    };

                    var gitPreparer   = new GitPreparer(log, environment, Options.Create(arguments));
                    configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
                    var cacheKey      = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, configFileLocator, null);
                    cacheKey.Value.ShouldNotBeEmpty();
                }
                finally
                {
                    DirectoryHelper.DeleteDirectory(worktreePath);
                }
            });
        }
        public void FindsGitDirectoryInParent()
        {
            var childDir = Path.Combine(workDirectory, "child");

            Directory.CreateDirectory(childDir);

            try
            {
                var arguments = new Arguments {
                    TargetPath = childDir, NoFetch = true
                };
                var options = Options.Create(arguments);

                var gitPreparer               = new GitPreparer(log, environment, options);
                var configurationProvider     = new ConfigProvider(testFileSystem, log, configFileLocator, gitPreparer, configInitWizard);
                var baseVersionCalculator     = new BaseVersionCalculator(log, null);
                var mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator);
                var nextVersionCalculator     = new NextVersionCalculator(log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator);
                var variableProvider          = new VariableProvider(nextVersionCalculator, environment);

                var gitVersionCalculator = new GitVersionCalculator(testFileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, gitPreparer, variableProvider, options);

                gitVersionCalculator.CalculateVersionVariables();
            }
            catch (Exception ex)
            {
                // TODO I think this test is wrong.. It throws a different exception
                // `RepositoryNotFoundException` means that it couldn't find the .git directory,
                // any other exception means that the .git was found but there was some other issue that this test doesn't care about.
                Assert.IsNotAssignableFrom <RepositoryNotFoundException>(ex);
            }
        }
예제 #7
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));
            }
        }
    }
예제 #8
0
        private void RepositoryScope(ILog log, Action <EmptyRepositoryFixture, VersionVariables> fixtureAction = null)
        {
            // Make sure GitVersion doesn't trigger build server mode when we are running the tests
            environment.SetEnvironmentVariable(AppVeyor.EnvironmentVariableName, null);
            environment.SetEnvironmentVariable(TravisCi.EnvironmentVariableName, null);
            environment.SetEnvironmentVariable(AzurePipelines.EnvironmentVariableName, null);

            using var fixture = new EmptyRepositoryFixture();

            var arguments = new Arguments {
                TargetPath = fixture.RepositoryPath
            };
            var options = Options.Create(arguments);

            var gitPreparer               = new GitPreparer(log, environment, options);
            var stepFactory               = new ConfigInitStepFactory();
            var configInitWizard          = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
            var configurationProvider     = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);
            var baseVersionCalculator     = new BaseVersionCalculator(this.log, null);
            var mainlineVersionCalculator = new MainlineVersionCalculator(this.log, metaDataCalculator);
            var nextVersionCalculator     = new NextVersionCalculator(this.log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator);
            var variableProvider          = new VariableProvider(nextVersionCalculator, new TestEnvironment());
            var gitVersionCalculator      = new GitVersionCalculator(fileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, gitPreparer, variableProvider, options);

            fixture.Repository.MakeACommit();
            var vv = gitVersionCalculator.CalculateVersionVariables();

            vv.AssemblySemVer.ShouldBe("0.1.0.0");
            vv.FileName.ShouldNotBeNullOrEmpty();

            fixtureAction?.Invoke(fixture, vv);
        }
예제 #9
0
        public void GetDotGitDirectoryWorktree()
        {
            RepositoryScope((fixture, vv) =>
            {
                var worktreePath = Path.Combine(Directory.GetParent(fixture.RepositoryPath).FullName, Guid.NewGuid().ToString());
                try
                {
                    // create a branch and a new worktree for it
                    var repo = new Repository(fixture.RepositoryPath);
                    repo.Worktrees.Add("worktree", worktreePath, false);

                    var targetUrl = "https://github.com/GitTools/GitVersion.git";

                    var arguments = new Arguments
                    {
                        TargetUrl  = targetUrl,
                        TargetPath = worktreePath
                    };

                    var gitPreparer  = new GitPreparer(log, environment, Options.Create(arguments));
                    var expectedPath = Path.Combine(fixture.RepositoryPath, ".git");
                    gitPreparer.GetDotGitDirectory().ShouldBe(expectedPath);
                }
                finally
                {
                    DirectoryHelper.DeleteDirectory(worktreePath);
                }
            });
        }
예제 #10
0
        public void CanSetNextVersion()
        {
            ILog        log         = new NullLog();
            IFileSystem fileSystem  = new TestFileSystem();
            IConsole    testConsole = new TestConsole("3", "2.0.0", "0");

            var serviceCollections = new ServiceCollection();

            serviceCollections.AddModule(new GitVersionInitModule());

            serviceCollections.AddSingleton(log);
            serviceCollections.AddSingleton(fileSystem);
            serviceCollections.AddSingleton(testConsole);

            var serviceProvider = serviceCollections.BuildServiceProvider();

            var stepFactory       = new ConfigInitStepFactory(serviceProvider);
            var configInitWizard  = new ConfigInitWizard(testConsole, stepFactory);
            var configFileLocator = new DefaultConfigFileLocator(fileSystem, log);
            var workingDirectory  = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\proj" : "/proj";

            var gitPreparer = new GitPreparer(log, new TestEnvironment(), Options.Create(new Arguments {
                TargetPath = workingDirectory
            }));
            var configurationProvider = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);

            configurationProvider.Init(workingDirectory);

            fileSystem.ReadAllText(Path.Combine(workingDirectory, "GitVersion.yml")).ShouldMatchApproved();
        }
예제 #11
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()))
            {
                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);
        }
    }
예제 #12
0
    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);
                gitPreparer.InitialiseDynamicRepositoryIfNeeded();
                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);
            }
        }
    }
예제 #13
0
    public void WorksCorrectlyWithLocalRepository()
    {
        var tempDir               = Path.GetTempPath();
        var gitPreparer           = new GitPreparer(null, null, null, false, tempDir);
        var dynamicRepositoryPath = gitPreparer.GetDotGitDirectory();

        dynamicRepositoryPath.ShouldBe(null);
        gitPreparer.IsDynamicGitRepository.ShouldBe(false);
    }
        private string PrepareCacheDirectory(GitPreparer gitPreparer)
        {
            var cacheDir = GetCacheDirectory(gitPreparer);

            // If the cacheDir already exists, CreateDirectory just won't do anything (it won't fail). @asbjornu
            fileSystem.CreateDirectory(cacheDir);

            return(cacheDir);
        }
예제 #15
0
    public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDynamicallyCalculatedWithoutSavingInCache()
    {
        const string versionCacheFileContent = @"
Major: 4
Minor: 10
Patch: 3
PreReleaseTag: test.19
PreReleaseTagWithDash: -test.19
PreReleaseLabel: test
PreReleaseNumber: 19
BuildMetaData: 
BuildMetaDataPadded: 
FullBuildMetaData: Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
MajorMinorPatch: 4.10.3
SemVer: 4.10.3-test.19
LegacySemVer: 4.10.3-test19
LegacySemVerPadded: 4.10.3-test0019
AssemblySemVer: 4.10.3.0
AssemblySemFileVer: 4.10.3.0
FullSemVer: 4.10.3-test.19
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
BranchName: feature/test
Sha: dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
ShortSha: dd2a29af
NuGetVersionV2: 4.10.3-test0019
NuGetVersion: 4.10.3-test0019
NuGetPreReleaseTagV2: test0019
NuGetPreReleaseTag: test0019
CommitsSinceVersionSource: 19
CommitsSinceVersionSourcePadded: 0019
CommitDate: 2015-11-10
";

        var versionAndBranchFinder = new ExecuteCore(fileSystem);

        RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
        {
            fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);

            var gitPreparer    = new GitPreparer(null, null, null, false, fixture.RepositoryPath);
            var cacheDirectory = GitVersionCache.GetCacheDirectory(gitPreparer);

            var cacheDirectoryTimestamp = fileSystem.GetLastDirectoryWrite(cacheDirectory);

            vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null, new Config()
            {
                TagPrefix = "prefix"
            });

            vv.AssemblySemVer.ShouldBe("0.1.0.0");

            var cachedDirectoryTimestampAfter = fileSystem.GetLastDirectoryWrite(cacheDirectory);
            cachedDirectoryTimestampAfter.ShouldBe(cacheDirectoryTimestamp, () => "Cache was updated when override config was set");
        });

        // TODO info.ShouldContain("Override config from command line", () => info);
    }
        static string GetGitSystemHash(GitPreparer gitPreparer)
        {
            var dotGitDirectory = gitPreparer.GetDotGitDirectory();

            // traverse the directory and get a list of files, use that for GetHash
            var contents = CalculateDirectoryContents(Path.Combine(dotGitDirectory, "refs"));

            return(GetHash(contents.ToArray()));
        }
예제 #17
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);
                }
            }
        }
    }
        public static GitVersionCacheKey Create(IFileSystem fileSystem, GitPreparer gitPreparer, Config overrideConfig, ConfigFileLocator configFileLocator)
        {
            var gitSystemHash          = GetGitSystemHash(gitPreparer);
            var configFileHash         = GetConfigFileHash(fileSystem, gitPreparer, configFileLocator);
            var repositorySnapshotHash = GetRepositorySnapshotHash(gitPreparer);
            var overrideConfigHash     = GetOverrideConfigHash(overrideConfig);

            var compositeHash = GetHash(gitSystemHash, configFileHash, repositorySnapshotHash, overrideConfigHash);

            return(new GitVersionCacheKey(compositeHash));
        }
예제 #19
0
        public string SelectConfigFilePath(GitPreparer gitPreparer, IFileSystem fileSystem)
        {
            var workingDirectory     = gitPreparer.WorkingDirectory;
            var projectRootDirectory = gitPreparer.GetProjectRootDirectory();

            if (HasConfigFileAt(workingDirectory, fileSystem))
            {
                return(GetConfigFilePath(workingDirectory, fileSystem));
            }

            return(GetConfigFilePath(projectRootDirectory, fileSystem));
        }
        public static Config Provide(GitPreparer gitPreparer, IFileSystem fileSystem, ConfigFileLocator configFileLocator, bool applyDefaults = true, Config overrideConfig = null, string configFilePath = null)
        {
            var workingDirectory     = gitPreparer.WorkingDirectory;
            var projectRootDirectory = gitPreparer.GetProjectRootDirectory();

            if (configFileLocator.HasConfigFileAt(workingDirectory, fileSystem))
            {
                return(Provide(workingDirectory, fileSystem, configFileLocator, applyDefaults, overrideConfig));
            }

            return(Provide(projectRootDirectory, fileSystem, configFileLocator, applyDefaults, overrideConfig));
        }
예제 #21
0
        public void GetDotGitDirectory_NoWorktree()
        {
            var versionAndBranchFinder = new ExecuteCore(fileSystem, environment);

            RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
            {
                var targetUrl    = "https://github.com/GitTools/GitVersion.git";
                var gitPreparer  = new GitPreparer(targetUrl, null, new Authentication(), false, fixture.RepositoryPath);
                var expectedPath = Path.Combine(fixture.RepositoryPath, ".git");
                gitPreparer.GetDotGitDirectory().ShouldBe(expectedPath);
            });
        }
예제 #22
0
    public void WorksCorrectlyWithLocalRepository()
    {
        using (var fixture = new EmptyRepositoryFixture(new Config()))
        {
            var targetPath = Path.Combine(fixture.RepositoryPath, "tools\\gitversion\\");
            Directory.CreateDirectory(targetPath);
            var gitPreparer     = new GitPreparer(null, null, null, false, targetPath);
            var dotGitDirectory = gitPreparer.GetDotGitDirectory();
            var projectRoot     = gitPreparer.GetProjectRootDirectory();

            dotGitDirectory.ShouldBe(Path.Combine(fixture.RepositoryPath, ".git"));
            projectRoot.ShouldBe(fixture.RepositoryPath);
        }
    }
예제 #23
0
        public void Verify(GitPreparer gitPreparer, IFileSystem fileSystem)
        {
            if (!string.IsNullOrWhiteSpace(gitPreparer.TargetUrl))
            {
                // Assuming this is a dynamic repository. At this stage it's unsure whether we have
                // any .git info so we need to skip verification
                return;
            }

            var workingDirectory     = gitPreparer.WorkingDirectory;
            var projectRootDirectory = gitPreparer.GetProjectRootDirectory();

            Verify(workingDirectory, projectRootDirectory, fileSystem);
        }
        private static string GetRepositorySnapshotHash(GitPreparer gitPreparer)
        {
            var repositorySnapshot = gitPreparer.WithRepository(repo => {
                var head = repo.Head;
                if (head.Tip == null)
                {
                    return(head.CanonicalName);
                }
                var hash = string.Join(":", head.CanonicalName, head.Tip.Sha);
                return(hash);
            });

            return(GetHash(repositorySnapshot));
        }
예제 #25
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);
    }
예제 #26
0
    public void WorksCorrectlyWithLocalRepository()
    {
        var tempDir = Path.GetTempPath();

        var arguments = new Arguments
        {
            TargetPath = tempDir
        };

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

        dynamicRepositoryPath.ShouldBe(null);
        gitPreparer.IsDynamicGitRepository.ShouldBe(false);
    }
예제 #27
0
    public void WorksCorrectlyWithLocalRepository()
    {
        var tempDir = Path.GetTempPath();

        var arguments = new Arguments
        {
            TargetPath = tempDir
        };

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

        dynamicRepositoryPath.ShouldBe(null);
        gitPreparer.IsDynamicGitRepository.ShouldBe(false);
    }
        private static string GetConfigFileHash(IFileSystem fileSystem, GitPreparer gitPreparer, ConfigFileLocator configFileLocator)
        {
            // will return the same hash even when config file will be moved
            // from workingDirectory to rootProjectDirectory. It's OK. Config essentially is the same.
            var configFilePath = configFileLocator.SelectConfigFilePath(gitPreparer, fileSystem);

            if (!fileSystem.Exists(configFilePath))
            {
                return(string.Empty);
            }

            var configFileContent = fileSystem.ReadAllText(configFilePath);

            return(GetHash(configFileContent));
        }
예제 #29
0
        private GitVersionCalculator GetGitVersionCalculator(Arguments arguments)
        {
            var options = Options.Create(arguments);

            var gitPreparer               = new GitPreparer(log, environment, options);
            var stepFactory               = new ConfigInitStepFactory();
            var configInitWizard          = new ConfigInitWizard(new ConsoleAdapter(), stepFactory);
            var configurationProvider     = new ConfigProvider(fileSystem, log, configFileLocator, gitPreparer, configInitWizard);
            var baseVersionCalculator     = new BaseVersionCalculator(log, null);
            var mainlineVersionCalculator = new MainlineVersionCalculator(log, metaDataCalculator);
            var nextVersionCalculator     = new NextVersionCalculator(log, metaDataCalculator, baseVersionCalculator, mainlineVersionCalculator);
            var variableProvider          = new VariableProvider(nextVersionCalculator, new TestEnvironment());
            var gitVersionCalculator      = new GitVersionCalculator(fileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, gitPreparer, variableProvider, options);

            return(gitVersionCalculator);
        }
예제 #30
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);
        });
    }