Exemplo n.º 1
0
    public static VersionVariables GetVersion(string directory, Authentication authentication, bool noFetch, IFileSystem fileSystem)
    {
        var gitDir = GitDirFinder.TreeWalkForDotGitDir(directory);

        using (var repo = RepositoryLoader.GetRepo(gitDir))
        {
            var ticks = DirectoryDateFinder.GetLastDirectoryWrite(directory);
            var key   = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);

            CachedVersion result;
            if (versionCacheVersions.TryGetValue(key, out result))
            {
                if (result.Timestamp != ticks)
                {
                    Logger.WriteInfo("Change detected. flushing cache.");
                    result.VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null);
                }
                return(result.VersionVariables);
            }
            Logger.WriteInfo("Version not in cache. Calculating version.");

            return((versionCacheVersions[key] = new CachedVersion
            {
                VersionVariables = ExecuteCore.ExecuteGitVersion(fileSystem, null, null, authentication, null, noFetch, directory, null),
                Timestamp = ticks
            }).VersionVariables);
        }
    }
Exemplo n.º 2
0
    public static CachedVersion GetVersion(string gitDirectory, Config configuration)
    {
        using (var repo = RepositoryLoader.GetRepo(gitDirectory))
        {
            var           versionFinder = new GitVersionFinder();
            var           context       = new GitVersionContext(repo, configuration);
            var           ticks         = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory);
            var           key           = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);
            CachedVersion cachedVersion;
            if (versionCacheVersions.TryGetValue(key, out cachedVersion))
            {
                if (cachedVersion.Timestamp != ticks)
                {
                    Logger.WriteInfo("Change detected. flushing cache.");
                    cachedVersion.SemanticVersion   = versionFinder.FindVersion(context);
                    cachedVersion.MasterReleaseDate = LastMinorVersionFinder.Execute(repo, new Config(), repo.Head.Tip);
                }
                return(cachedVersion);
            }
            Logger.WriteInfo("Version not in cache. Calculating version.");

            return(versionCacheVersions[key] = new CachedVersion
            {
                SemanticVersion = versionFinder.FindVersion(context),
                MasterReleaseDate = LastMinorVersionFinder.Execute(repo, new Config(), repo.Head.Tip),
                Timestamp = ticks
            });
        }
    }
Exemplo n.º 3
0
    public static CachedVersion GetVersion(string gitDirectory)
    {
        using (var repo = RepositoryLoader.GetRepo(gitDirectory))
        {
            var           ticks = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory);
            var           key   = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);
            CachedVersion cachedVersion;
            if (versionCacheVersions.TryGetValue(key, out cachedVersion))
            {
                if (cachedVersion.Timestamp != ticks)
                {
                    Logger.WriteInfo("Change detected. flushing cache.");
                    cachedVersion.SemanticVersion   = GitVersionFinder.GetSemanticVersion(repo);
                    cachedVersion.MasterReleaseDate = LastVersionOnMasterFinder.Execute(repo, repo.Head.Tip);
                }
                return(cachedVersion);
            }
            Logger.WriteInfo("Version not in cache. Calculating version.");

            //TODO: cope with githubflow
            //if (GitVersionFinder.ShouldGitHubFlowVersioningSchemeApply(repo))
            //{
            //    return rd;
            //}
            return(versionCacheVersions[key] = new CachedVersion
            {
                SemanticVersion = GitVersionFinder.GetSemanticVersion(repo),
                MasterReleaseDate = LastVersionOnMasterFinder.Execute(repo, repo.Head.Tip),
                Timestamp = ticks
            });
        }
    }
Exemplo n.º 4
0
    public static Tuple <CachedVersion, GitVersionContext> GetVersion(string gitDirectory, Config configuration)
    {
        using (var repo = RepositoryLoader.GetRepo(gitDirectory))
        {
            var versionFinder = new GitVersionFinder();
            var context       = new GitVersionContext(repo, configuration);
            var ticks         = DirectoryDateFinder.GetLastDirectoryWrite(gitDirectory);
            var key           = string.Format("{0}:{1}:{2}", repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);

            Tuple <CachedVersion, GitVersionContext> result;
            if (versionCacheVersions.TryGetValue(key, out result))
            {
                if (result.Item1.Timestamp != ticks)
                {
                    Logger.WriteInfo("Change detected. flushing cache.");
                    result.Item1.SemanticVersion = versionFinder.FindVersion(context);
                }
                return(result);
            }
            Logger.WriteInfo("Version not in cache. Calculating version.");

            return(versionCacheVersions[key] = Tuple.Create(new CachedVersion
            {
                SemanticVersion = versionFinder.FindVersion(context),
                Timestamp = ticks
            }, context));
        }
    }
Exemplo n.º 5
0
        public static Context ParseArguments(List <string> commandLineArguments, IProviderManager providerManager)
        {
            var context = new Context(providerManager);

            if (commandLineArguments.Count == 0)
            {
                context.IsHelp = true;
                return(context);
            }

            var firstArgument = commandLineArguments.First();

            if (IsHelp(firstArgument))
            {
                context.IsHelp = true;
                return(context);
            }

            if (commandLineArguments.Count < 3 && commandLineArguments.Count != 1)
            {
                throw Log.ErrorAndCreateException <GitLinkException>("Invalid number of arguments");
            }

            context.SolutionDirectory = firstArgument;

            var namedArguments = commandLineArguments.Skip(1).ToList();

            for (var index = 0; index < namedArguments.Count; index++)
            {
                var name = namedArguments[index];

                // First check everything without values
                if (IsSwitch("debug", name))
                {
                    context.IsDebug = true;
                    continue;
                }

                if (IsSwitch("errorsaswarnings", name))
                {
                    context.ErrorsAsWarnings = true;
                    continue;
                }

                if (IsSwitch("skipverify", name))
                {
                    context.SkipVerify = true;
                    continue;
                }

                // After this point, all arguments should have a value
                index++;
                var valueInfo = GetValue(namedArguments, index);
                var value     = valueInfo.Key;
                index = index + (valueInfo.Value - 1);

                if (IsSwitch("l", name))
                {
                    context.LogFile = value;
                    continue;
                }

                if (IsSwitch("c", name))
                {
                    context.ConfigurationName = value;
                    continue;
                }

                if (IsSwitch("p", name))
                {
                    context.PlatformName = value;
                    continue;
                }

                if (IsSwitch("u", name))
                {
                    context.TargetUrl = value;
                    continue;
                }

                if (IsSwitch("b", name))
                {
                    context.TargetBranch = value;
                    continue;
                }

                if (IsSwitch("s", name))
                {
                    context.ShaHash = value;
                    continue;
                }

                if (IsSwitch("f", name))
                {
                    context.SolutionFile = value;
                    continue;
                }

                if (IsSwitch("d", name))
                {
                    context.PdbFilesDirectory = value;
                    continue;
                }

                if (IsSwitch("ignore", name))
                {
                    context.IgnoredProjects.AddRange(value.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()));
                    continue;
                }

                throw Log.ErrorAndCreateException <GitLinkException>("Could not parse command line parameter '{0}'.", name);
            }

            if (string.IsNullOrEmpty(context.TargetUrl))
            {
                Log.Info("No target url was specified, trying to determine the target url automatically");

                var gitDir = GitDirFinder.TreeWalkForGitDir(context.SolutionDirectory);
                if (gitDir != null)
                {
                    using (var repo = RepositoryLoader.GetRepo(gitDir))
                    {
                        var currentBranch = repo.Head;

                        if (string.IsNullOrEmpty(context.ShaHash))
                        {
                            context.ShaHash = currentBranch.Tip.Sha;
                        }

                        if (currentBranch.Remote == null || currentBranch.IsDetachedHead())
                        {
                            currentBranch = repo.GetBranchesContainingCommit(context.ShaHash).FirstOrDefault(b => b.Remote != null);
                        }

                        if (currentBranch != null && currentBranch.Remote != null)
                        {
                            var url = currentBranch.Remote.Url;
                            if (url.StartsWith("https://"))
                            {
                                context.TargetUrl = url.OptimizeUrl();

                                Log.Info("Automatically determine target url '{0}'", context.TargetUrl);
                            }
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(context.TargetUrl))
            {
                context.Provider = providerManager.GetProvider(context.TargetUrl);
            }

            return(context);
        }