Create() public static method

public static Create ( IFileSystem fileSystem, GitVersion.GitPreparer gitPreparer, Config overrideConfig ) : GitVersion.GitVersionCacheKey
fileSystem IFileSystem
gitPreparer GitVersion.GitPreparer
overrideConfig Config
return GitVersion.GitVersionCacheKey
コード例 #1
0
        private VersionVariables GetCachedGitVersionInfo(string targetBranch, string commitId, Config overrideConfig, bool noCache)
        {
            var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, configFileLocator, overrideConfig);

            var versionVariables = noCache ? default : gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey);

                                   if (versionVariables == null)
                                   {
                                       versionVariables = ExecuteInternal(targetBranch, commitId, overrideConfig);

                                       if (!noCache)
                                       {
                                           try
                                           {
                                               gitVersionCache.WriteVariablesToDiskCache(gitPreparer, cacheKey, versionVariables);
                                           }
                                           catch (AggregateException e)
                                           {
                                               log.Warning($"One or more exceptions during cache write:{System.Environment.NewLine}{e}");
                                           }
                                       }
                                   }

                                   return(versionVariables);
        }
コード例 #2
0
        public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null, bool noCache = false, bool noNormalize = false)
        {
            BuildServerList.Init(environment, log);

            // Normalize if we are running on build server
            var applicableBuildServers = BuildServerList.GetApplicableBuildServers(log);
            var buildServer            = applicableBuildServers.FirstOrDefault();
            var normalizeGitDirectory  = !noNormalize && buildServer != null;
            var fetch = noFetch || buildServer != null && buildServer.PreventFetch();
            var shouldCleanUpRemotes = buildServer != null && buildServer.ShouldCleanUpRemotes();
            var gitPreparer          = new GitPreparer(log, targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory);

            gitPreparer.Initialise(normalizeGitDirectory, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation)), shouldCleanUpRemotes);
            var dotGitDirectory = gitPreparer.GetDotGitDirectory();
            var projectRoot     = gitPreparer.GetProjectRootDirectory();

            // TODO Can't use this, it still needs work
            //var gitRepository = GitRepositoryFactory.CreateRepository(new RepositoryInfo
            //{
            //    Url = targetUrl,
            //    Branch = targetBranch,
            //    Authentication = new AuthenticationInfo
            //    {
            //        Username = authentication.Username,
            //        Password = authentication.Password
            //    },
            //    Directory = workingDirectory
            //});
            log.Info($"Project root is: {projectRoot}");
            log.Info($"DotGit directory is: {dotGitDirectory}");
            if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot))
            {
                // TODO Link to wiki article
                throw new Exception($"Failed to prepare or find the .git directory in path '{workingDirectory}'.");
            }

            var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, overrideConfig, configFileLocator);

            var versionVariables = noCache ? default : gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey);

                                   if (versionVariables == null)
                                   {
                                       versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, overrideConfig);

                                       if (!noCache)
                                       {
                                           try
                                           {
                                               gitVersionCache.WriteVariablesToDiskCache(gitPreparer, cacheKey, versionVariables);
                                           }
                                           catch (AggregateException e)
                                           {
                                               log.Warning($"One or more exceptions during cache write:{Environment.NewLine}{e}");
                                           }
                                       }
                                   }

                                   return(versionVariables);
        }
コード例 #3
0
        public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null)
        {
            // Normalise if we are running on build server
            var applicableBuildServers = BuildServerList.GetApplicableBuildServers();
            var buildServer            = applicableBuildServers.FirstOrDefault();
            var fetch       = noFetch || (buildServer != null && buildServer.PreventFetch());
            var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory);

            gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation)));
            var dotGitDirectory = gitPreparer.GetDotGitDirectory();
            var projectRoot     = gitPreparer.GetProjectRootDirectory();

            // TODO Can't use this, it still needs work
            //var gitRepository = GitRepositoryFactory.CreateRepository(new RepositoryInfo
            //{
            //    Url = targetUrl,
            //    Branch = targetBranch,
            //    Authentication = new AuthenticationInfo
            //    {
            //        Username = authentication.Username,
            //        Password = authentication.Password
            //    },
            //    Directory = workingDirectory
            //});
            Logger.WriteInfo(string.Format("Project root is: {0}", projectRoot));
            Logger.WriteInfo(string.Format("DotGit directory is: {0}", dotGitDirectory));
            if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot))
            {
                // TODO Link to wiki article
                throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory));
            }

            var cacheKey         = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, overrideConfig);
            var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(gitPreparer, cacheKey);

            if (versionVariables == null)
            {
                versionVariables = ExecuteInternal(targetBranch, commitId, gitPreparer, buildServer, overrideConfig);

                try
                {
                    gitVersionCache.WriteVariablesToDiskCache(gitPreparer, cacheKey, versionVariables);
                }
                catch (AggregateException e)
                {
                    Logger.WriteWarning(string.Format("One or more exceptions during cache write:{0}{1}", Environment.NewLine, e));
                }
            }

            return(versionVariables);
        }