Esempio n. 1
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
            });
        }
    }
Esempio n. 2
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));
        }
    }
    public void TimingOnNSB()
    {
        var startNew = Stopwatch.StartNew();

        using (var repository = new Repository(@"C:\Code\NServiceBus"))
        {
            var branch = repository.Branches.First(x => x.Name == "develop");

            var finder = new GitVersionFinder();
            finder.FindVersion(new GitVersionContext
            {
                Repository    = repository,
                CurrentBranch = branch
            });
        }
        Debug.WriteLine(startNew.ElapsedMilliseconds);
        startNew = Stopwatch.StartNew();
        using (var repository = new Repository(@"C:\Code\NServiceBus"))
        {
            var branch = repository.Branches.First(x => x.Name == "develop");

            var finder = new GitVersionFinder();
            finder.FindVersion(new GitVersionContext
            {
                Repository    = repository,
                CurrentBranch = branch
            });
        }
        Debug.WriteLine(startNew.ElapsedMilliseconds);
    }
Esempio n. 4
0
    public void AReleaseBranchIsRequiredToBranchOffOfDevelopBranch()
    {
        var repoPath = Clone(ASBMTestRepoWorkingDirPath);

        using (var repo = new Repository(repoPath))
        {
            const string branchName = "release/1.2.0";

            // Create a new unborn release branch sharing no history with "develop"
            repo.Refs.UpdateTarget(repo.Refs.Head.CanonicalName, "refs/heads/" + branchName);

            var path = Path.Combine(repo.Info.WorkingDirectory, "README");
            File.AppendAllText(path, "Release\n");

            repo.Index.Stage(path);
            var sign = Constants.SignatureNow();
            repo.Commit("release unborn", sign, sign);

            var feature = repo.Branches[branchName];

            var finder = new GitVersionFinder();

            Assert.Throws <ErrorException>(() => finder.FindVersion(new GitVersionContext
            {
                Repository    = repo,
                CurrentBranch = feature,
            }));
        }
    }
        private static SemanticVersion ExecuteGitVersion(GitVersionContext context)
        {
            var log = new NullLog();
            var metadataCalculator        = new MetaDataCalculator();
            var baseVersionCalculator     = new TestBaseVersionStrategiesCalculator(log);
            var mainlineVersionCalculator = new MainlineVersionCalculator(log, metadataCalculator);
            var nextVersionCalculator     = new NextVersionCalculator(log, metadataCalculator, baseVersionCalculator, mainlineVersionCalculator);
            var vf = new GitVersionFinder(log, nextVersionCalculator);

            return(vf.FindVersion(context));
        }
    public void Foo()
    {
        using (var repository = new Repository(@"C:\Code\ServiceControl"))
        {
            var branch = repository.Branches.First(x => x.Name == "develop");

            var finder  = new GitVersionFinder();
            var version = finder.FindVersion(new GitVersionContext(repository, branch));
            Debug.WriteLine(version.Major);
            Debug.WriteLine(version.Minor);
            Debug.WriteLine(version.Patch);
            Debug.WriteLine(version.PreReleaseTag);
        }
    }
        public ExecutionResults ExecuteGitVersion(bool inProcess = true)
        {
            if (!inProcess)
            {
                return(GitVersionHelper.ExecuteIn(RepositoryPath));
            }

            var vf = new GitVersionFinder();
            var sv = vf.FindVersion(new GitVersionContext(Repository));

            var vars = VariableProvider.GetVariablesFor(sv);

            return(new InProcessExecutionResults(vars));
        }
Esempio n. 8
0
    public void RequiresALocalDevelopBranch()
    {
        var repoPath = Clone(ASBMTestRepoWorkingDirPath);

        using (var repo = new Repository(repoPath))
        {
            repo.Branches["feature/one"].ForceCheckout();

            repo.Branches.Remove("develop");

            var finder = new GitVersionFinder();

            Assert.Throws <WarningException>(() => finder.FindVersion(new GitVersionContext(repo)));
        }
    }
    public void NServiceBusNhibernate()
    {
        using (var repository = new Repository(@"C:\Code\NServiceBus.Nhibernate"))
        {
            var branch = repository.FindBranch("develop");

            var finder  = new GitVersionFinder();
            var version = finder.FindVersion(new GitVersionContext(repository, branch));
            Debug.WriteLine(version.Major);
            Debug.WriteLine(version.Minor);
            Debug.WriteLine(version.Patch);
            Debug.WriteLine(version.PreReleaseTag);
            Debug.WriteLine(version.BuildMetaData);
        }
    }
Esempio n. 10
0
    public void NServiceBusRelease()
    {
        using (var repository = new Repository(@"C:\Code\NServiceBus"))
        {
            var branch = repository.Branches.First(x => x.Name == "release-4.1.0");

            var finder  = new GitVersionFinder();
            var version = finder.FindVersion(new GitVersionContext(repository, branch));
            Debug.WriteLine(version.Major);
            Debug.WriteLine(version.Minor);
            Debug.WriteLine(version.Patch);
            Debug.WriteLine(version.PreReleaseTag);
            Debug.WriteLine(version.BuildMetaData);
        }
    }
Esempio n. 11
0
    public void NServiceBusReleaseSpecificCommit()
    {
        using (var repository = new Repository(@"C:\Code\NServiceBus"))
        {
            var branch = repository.Branches.First(x => x.Name == "release-4.1.0");
            repository.Checkout("c0e0a5e13775552cd3e08e039f453e4cf1fd4235");

            var finder  = new GitVersionFinder();
            var version = finder.FindVersion(new GitVersionContext(repository, branch));
            Debug.WriteLine(version.Major);
            Debug.WriteLine(version.Minor);
            Debug.WriteLine(version.Patch);
            Debug.WriteLine(version.PreReleaseTag);
            Debug.WriteLine(version.BuildMetaData);
        }
    }
    public void NServiceBusHead()
    {
        using (var repository = new Repository(@"C:\Code\NServiceBus"))
        {
            var branch = repository.Head;

            var finder  = new GitVersionFinder();
            var version = finder.FindVersion(new GitVersionContext
            {
                Repository    = repository,
                CurrentBranch = branch
            });
            Debug.WriteLine(version.Major);
            Debug.WriteLine(version.Minor);
            Debug.WriteLine(version.Patch);
            Debug.WriteLine(version.PreReleaseTag);
            Debug.WriteLine(version.BuildMetaData);
        }
    }
Esempio n. 13
0
    public void RequiresALocalMasterBranch()
    {
        var repoPath = Clone(ASBMTestRepoWorkingDirPath);

        using (var repo = new Repository(repoPath))
        {
            repo.Branches["feature/one"].ForceCheckout();

            repo.Branches.Remove("master");

            var finder = new GitVersionFinder();

            Assert.Throws <ErrorException>(() => finder.FindVersion(new GitVersionContext
            {
                Repository    = repo,
                CurrentBranch = repo.Head,
            }));
        }
    }
Esempio n. 14
0
    public void APullRequestBranchIsRequiredToBranchOffOfDevelopBranch()
    {
        var repoPath = Clone(ASBMTestRepoWorkingDirPath);

        using (var repo = new Repository(repoPath))
        {
            const string branchName = "pull/1735/merge";

            // Create a new unborn pull request branch sharing no history with "develop"
            repo.Refs.UpdateTarget(repo.Refs.Head.CanonicalName, "refs/heads/" + branchName);

            AddOneCommitToHead(repo, "code");

            var pull = repo.Branches[branchName];

            var finder = new GitVersionFinder();

            Assert.Throws <WarningException>(() => finder.FindVersion(new GitVersionContext(repo, pull)));
        }
    }
Esempio n. 15
0
    public void AFeatureBranchDoesNotRequireASpecificPrefix()
    {
        var repoPath = Clone(ASBMTestRepoWorkingDirPath);

        using (var repo = new Repository(repoPath))
        {
            repo.Branches["develop"].ForceCheckout();

            const string branchName = "every-feature-is-welcome";
            repo.Branches.Add(branchName, repo.Head.Tip).ForceCheckout();

            AddOneCommitToHead(repo, "code");

            var finder = new GitVersionFinder();

            var versionAndBranch = finder.FindVersion(new GitVersionContext(repo));

            ObjectApprover.VerifyWithJson(versionAndBranch, Scrubbers.GuidAndDateScrubber);
        }
    }
Esempio n. 16
0
    public void AFeatureBranchPrefixIsNotIncludedInTag()
    {
        var repoPath = Clone(ASBMTestRepoWorkingDirPath);

        using (var repo = new Repository(repoPath))
        {
            repo.Branches["develop"].ForceCheckout();

            const string branchName = "feature/ABC-1234_SomeDescription";
            repo.Branches.Add(branchName, repo.Head.Tip).ForceCheckout();

            AddOneCommitToHead(repo, "code");

            var finder = new GitVersionFinder();

            var versionAndBranch = finder.FindVersion(new GitVersionContext(repo));

            ObjectApprover.VerifyWithJson(versionAndBranch, Scrubbers.GuidAndDateScrubber);
        }
    }
Esempio n. 17
0
    public void AHotfixBranchIsRequiredToBranchOffOfMasterBranch()
    {
        var repoPath = Clone(ASBMTestRepoWorkingDirPath);

        using (var repo = new Repository(repoPath))
        {
            const string branchName = "hotfix/1.0.2";

            // Create a new unborn hotfix branch sharing no history with "master"
            repo.Refs.UpdateTarget(repo.Refs.Head.CanonicalName, "refs/heads/" + branchName);

            AddOneCommitToHead(repo, "hotfix");

            var feature = repo.Branches[branchName];

            var finder = new GitVersionFinder();

            Assert.Throws <WarningException>(() => finder.FindVersion(new GitVersionContext(repo, feature)));
        }
    }
Esempio n. 18
0
    public void AFeatureBranchIsRequiredToBranchOffOfDevelopBranch()
    {
        var repoPath = Clone(ASBMTestRepoWorkingDirPath);

        using (var repo = new Repository(repoPath))
        {
            const string branchName = "feature/unborn";

            // Create a new unborn feature branch sharing no history with "develop"
            repo.Refs.UpdateTarget(repo.Refs.Head.CanonicalName, "refs/heads/" + branchName);

            AddOneCommitToHead(repo, "feature");

            var feature = repo.Branches[branchName];

            var finder = new GitVersionFinder();

            Assert.Throws <ErrorException>(() => finder.FindVersion(new GitVersionContext
            {
                Repository    = repo,
                CurrentBranch = feature,
            }));
        }
    }
Esempio n. 19
0
    public SemanticVersion ExecuteGitVersion(IRepository repository = null)
    {
        var vf = new GitVersionFinder();

        return(vf.FindVersion(new GitVersionContext(repository ?? Repository, configuration, IsForTrackedBranchOnly)));
    }
    public SemanticVersion ExecuteGitVersion()
    {
        var vf = new GitVersionFinder();

        return(vf.FindVersion(new GitVersionContext(Repository)));
    }
        static SemanticVersion ExecuteGitVersion(GitVersionContext context)
        {
            var vf = new GitVersionFinder();

            return(vf.FindVersion(context));
        }