Esempio n. 1
0
        public VersionVariables CalculateVersionVariables()
        {
            var arguments   = options.Value;
            var buildServer = buildServerResolver.Resolve();

            // Normalize if we are running on build server
            var normalizeGitDirectory = !arguments.NoNormalize && buildServer != null;
            var shouldCleanUpRemotes  = buildServer != null && buildServer.ShouldCleanUpRemotes();

            var currentBranch = ResolveCurrentBranch(buildServer, arguments.TargetBranch, !string.IsNullOrWhiteSpace(arguments.DynamicRepositoryLocation));

            gitPreparer.Prepare(normalizeGitDirectory, currentBranch, shouldCleanUpRemotes);

            var dotGitDirectory = gitPreparer.GetDotGitDirectory();
            var projectRoot     = gitPreparer.GetProjectRootDirectory();

            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 '{arguments.TargetPath}'.");
            }

            return(GetCachedGitVersionInfo(arguments.TargetBranch, arguments.CommitId, arguments.OverrideConfig, arguments.NoCache));
        }
Esempio n. 2
0
        private string GetGitSystemHash()
        {
            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()));
        }
Esempio n. 3
0
        public string GetCacheDirectory()
        {
            var gitDir   = gitPreparer.GetDotGitDirectory();
            var cacheDir = Path.Combine(gitDir, "gitversion_cache");

            return(cacheDir);
        }
Esempio n. 4
0
        private static string GetRepositorySnapshotHash(IGitPreparer gitPreparer)
        {
            var repositorySnapshot = gitPreparer.GetDotGitDirectory().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));
        }