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); }
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 }); } }
public static ReleaseDate Execute(IRepository repo, string commitSha, int calculatedPatch) { var c = repo.Lookup <Commit>(commitSha); Debug.Assert(c != null); var rd = new ReleaseDate { OriginalDate = c.When(), OriginalCommitSha = c.Sha, Date = c.When(), CommitSha = c.Sha, }; if (GitVersionFinder.ShouldGitHubFlowVersioningSchemeApply(repo)) { return(rd); } if (calculatedPatch == 0) { return(rd); } var vp = new VersionOnMasterFinder().FindLatestStableTaggedCommitReachableFrom(repo, c); var latestStable = repo.Lookup <Commit>(vp.CommitSha); Debug.Assert(latestStable != null); rd.OriginalDate = latestStable.When(); rd.OriginalCommitSha = vp.CommitSha; return(rd); }
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 }); } }
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 CanDetermineTheVersionFromAFetchedFeature() { var gitDirectory = FakeTeamCityFetchAndCheckout(ASBMTestRepoWorkingDirPath, "refs/heads/feature/one"); var authentication = new Authentication(); GitHelper.NormalizeGitDirectory(gitDirectory, authentication); using (var repository = new Repository(gitDirectory)) { var semanticVersion = new GitVersionFinder().FindVersion(new GitVersionContext(repository)); Assert.IsNotNull(semanticVersion); } }
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)); }
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); } }
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 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); } }
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 CanDetermineTheVersionFromAFetchedDevelop() { var gitDirectory = FakeTeamCityFetchAndCheckout(ASBMTestRepoWorkingDirPath, "refs/heads/develop"); var arguments = new Arguments(); GitHelper.NormalizeGitDirectory(gitDirectory, arguments); using (var repository = new Repository(gitDirectory)) { var semanticVersion = new GitVersionFinder().FindVersion(new GitVersionContext { Repository = repository, CurrentBranch = repository.Head }); Assert.IsNotNull(semanticVersion); } }
public void CanDetermineTheVersionFromAPullRequest() { var repoPath = Clone(ASBMTestRepoWorkingDirPath); CreateFakePullRequest(repoPath, "1735"); var gitDirectory = FakeTeamCityFetchAndCheckout(repoPath, "refs/pull/1735/merge"); var authentication = new Authentication(); GitHelper.NormalizeGitDirectory(gitDirectory, authentication); using (var repository = new Repository(gitDirectory)) { var semanticVersion = new GitVersionFinder().FindVersion(new GitVersionContext(repository)); Assert.IsNotNull(semanticVersion); } }
public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer) { var root = Path.Combine(workDirectory, name); var dynamicDirectory = Path.Combine(root, "D"); // dynamic, keeping directory as short as possible var workingDirectory = Path.Combine(root, "W"); // working, keeping directory as short as possible var arguments = new Arguments { TargetUrl = url, DynamicRepositoryLocation = dynamicDirectory, TargetBranch = targetBranch, NoFetch = false, TargetPath = workingDirectory, CommitId = commitId }; var options = Options.Create(arguments); Directory.CreateDirectory(dynamicDirectory); Directory.CreateDirectory(workingDirectory); var testFileSystem = new TestFileSystem(); var log = new NullLog(); var configFileLocator = new DefaultConfigFileLocator(testFileSystem, log); var gitVersionCache = new GitVersionCache(testFileSystem, log); var buildServerResolver = new BuildServerResolver(null, log); var metadataCalculator = new MetaDataCalculator(); var baseVersionCalculator = new TestBaseVersionStrategiesCalculator(log); var mainlineVersionCalculator = new MainlineVersionCalculator(log, metadataCalculator); var nextVersionCalculator = new NextVersionCalculator(log, metadataCalculator, baseVersionCalculator, mainlineVersionCalculator); var gitVersionFinder = new GitVersionFinder(log, nextVersionCalculator); var gitPreparer = new GitPreparer(log, new TestEnvironment(), options); var stepFactory = new ConfigInitStepFactory(); var configInitWizard = new ConfigInitWizard(new ConsoleAdapter(), stepFactory); var configurationProvider = new ConfigProvider(testFileSystem, log, configFileLocator, gitPreparer, configInitWizard); var variableProvider = new VariableProvider(nextVersionCalculator, new TestEnvironment()); var gitVersionCalculator = new GitVersionCalculator(testFileSystem, log, configFileLocator, configurationProvider, buildServerResolver, gitVersionCache, gitVersionFinder, gitPreparer, variableProvider, options); var versionVariables = gitVersionCalculator.CalculateVersionVariables(); Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer); }
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, })); } }
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); } }
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); } }
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); } }
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))); } }
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))); } }
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, })); } }
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)); }