public static int NumberOfCommitsSinceLastTagOrBranchPoint(GitVersionContext context, List <Tag> tagsInDescendingOrder, BranchType branchType, string baseBranchName) { if (!tagsInDescendingOrder.Any()) { return(NumberOfCommitsInBranchNotKnownFromBaseBranch(context.Repository, context.CurrentBranch, branchType, baseBranchName)); } var mostRecentTag = tagsInDescendingOrder.First(); var ancestor = mostRecentTag; if (mostRecentTag.Target == context.CurrentCommit) { var previousTag = tagsInDescendingOrder.Skip(1).FirstOrDefault(); if (previousTag != null) { ancestor = previousTag; } else { return(NumberOfCommitsInBranchNotKnownFromBaseBranch(context.Repository, context.CurrentBranch, BranchType.Release, baseBranchName)); } } var filter = new CommitFilter { Since = context.CurrentCommit, Until = ancestor.Target, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time }; return(context.Repository.Commits.QueryBy(filter).Count() - 1); }
int NumberOfCommitsInBranchNotKnownFromBaseBranch( IRepository repo, Branch branch, BranchType branchType, string baseBranchName) { var baseTip = repo.FindBranch(baseBranchName).Tip; if (branch.Tip == baseTip) { // The branch bears no additional commit return(0); } var ancestor = repo.Commits.FindMergeBase( baseTip, branch.Tip); if (ancestor == null) { var message = string.Format("A {0} branch is expected to branch off of '{1}'. However, branch '{1}' and '{2}' do not share a common ancestor.", branchType, baseBranchName, branch.Name); throw new WarningException(message); } var filter = new CommitFilter { Since = branch.Tip, Until = ancestor, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time }; return(repo.Commits.QueryBy(filter).Count()); }
private static IEnumerable <Commit> GetIntermediateCommits(IRepository repo, Commit baseCommit, Commit headCommit) { if (baseCommit == null) { yield break; } if (intermediateCommitCache == null || intermediateCommitCache.LastOrDefault() != headCommit) { var filter = new CommitFilter { IncludeReachableFrom = headCommit, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse }; intermediateCommitCache = repo.Commits.QueryBy(filter).ToList(); } var found = false; foreach (var commit in intermediateCommitCache) { if (found) { yield return(commit); } if (commit.Sha == baseCommit.Sha) { found = true; } } }
public SemanticVersion FindVersion(GitVersionContext context) { var versionOnMasterFinder = new VersionOnMasterFinder(); var tip = context.CurrentCommit; var versionFromMaster = versionOnMasterFinder.Execute(context, tip.When()); var f = new CommitFilter { Since = tip, Until = context.Repository.FindBranch("master").Tip, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time }; var c = context.Repository.Commits.QueryBy(f); var numberOfCommitsSinceRelease = c.Count(); var semanticVersion = new SemanticVersion { Major = versionFromMaster.Major, Minor = versionFromMaster.Minor + 1, Patch = 0, PreReleaseTag = context.Configuration.DevelopBranchTag + numberOfCommitsSinceRelease, BuildMetaData = new SemanticVersionBuildMetaData(numberOfCommitsSinceRelease, context.CurrentBranch.Name, tip.Sha, tip.When()), }; semanticVersion.OverrideVersionManuallyIfNeeded(context.Repository, context.Configuration); return(semanticVersion); }
public SemanticVersion FindVersion(GitVersionContext context) { var versionOnMasterFinder = new VersionOnMasterFinder(); var tip = context.CurrentBranch.Tip; var versionFromMaster = versionOnMasterFinder.Execute(context, tip.When()); var f = new CommitFilter { Since = tip, Until = context.Repository.FindBranch("master").Tip, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time }; var c = context.Repository.Commits.QueryBy(f); var numberOfCommitsSinceRelease = c.Count(); var releaseDate = ReleaseDateFinder.Execute(context.Repository, tip.Sha, 0); var semanticVersion = new SemanticVersion { Major = versionFromMaster.Major, Minor = versionFromMaster.Minor + 1, Patch = 0, PreReleaseTag = "unstable" + numberOfCommitsSinceRelease, BuildMetaData = new SemanticVersionBuildMetaData(numberOfCommitsSinceRelease, context.CurrentBranch.Name, releaseDate), }; return(semanticVersion); }
private static List <Commit> GetCommitsReacheableFromHead(IRepository repository, Commit headCommit) { var filter = new CommitFilter { IncludeReachableFrom = headCommit, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse }; return(repository.Commits.QueryBy(filter).ToList()); }
private static IEnumerable <ICommit> GetCommitsReacheableFromHead(IGitRepository repo, ICommit headCommit) { var filter = new CommitFilter { IncludeReachableFrom = headCommit, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse }; return(repo.Commits.QueryBy(filter)); }
public IEnumerable <ICommit> GetCommitsReacheableFrom(ICommit commit, IBranch branch) { var filter = new CommitFilter { IncludeReachableFrom = branch }; var commitCollection = Commits.QueryBy(filter); return(commitCollection.Where(c => c.Sha == commit.Sha)); }
private static IEnumerable <Commit> GetIntermediateCommits(IRepository repo, Commit baseCommit, Commit headCommit) { var filter = new CommitFilter { Since = headCommit, Until = baseCommit, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse }; return(repo.Commits.QueryBy(filter)); }
int NumberOfCommitsOnBranchSinceCommit(GitVersionContext context, Commit commit) { var qf = new CommitFilter { Since = context.CurrentCommit, Until = commit, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time }; return(context.Repository.Commits.QueryBy(qf).Count()); }
public IEnumerable <ICommit> GetCommitsReacheableFromHead(ICommit headCommit) { var filter = new CommitFilter { IncludeReachableFrom = headCommit, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse }; var commitCollection = Commits.QueryBy(filter); return(commitCollection.ToList()); }
public bool GetMatchingCommitBranch(ICommit baseVersionSource, IBranch branch, ICommit firstMatchingCommit) { var filter = new CommitFilter { IncludeReachableFrom = branch, ExcludeReachableFrom = baseVersionSource, FirstParentOnly = true, }; var commitCollection = Commits.QueryBy(filter); return(commitCollection.Contains(firstMatchingCommit)); }
public IEnumerable <ICommit> GetCommitLog(ICommit baseVersionSource, ICommit currentCommit) { var filter = new CommitFilter { IncludeReachableFrom = currentCommit, ExcludeReachableFrom = baseVersionSource, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time }; var commitCollection = Commits.QueryBy(filter); return(commitCollection); }
public ICommit?GetForwardMerge(ICommit commitToFindCommonBase, ICommit findMergeBase) { var filter = new CommitFilter { IncludeReachableFrom = commitToFindCommonBase, ExcludeReachableFrom = findMergeBase }; var commitCollection = Commits.QueryBy(filter); var forwardMerge = commitCollection .FirstOrDefault(c => c.Parents.Contains(findMergeBase)); return(forwardMerge); }
public IEnumerable <Commit> GetMergeBaseCommits(Commit mergeCommit, Commit mergedHead, Commit findMergeBase) { var filter = new CommitFilter { IncludeReachableFrom = mergedHead, ExcludeReachableFrom = findMergeBase }; var query = repository.Commits.QueryBy(filter); var commits = mergeCommit == null?query.ToList() : new[] { mergeCommit }.Union(query).ToList(); return(commits); }
public IEnumerable <ICommit> GetMainlineCommitLog(ICommit baseVersionSource, ICommit mainlineTip) { var filter = new CommitFilter { IncludeReachableFrom = mainlineTip, ExcludeReachableFrom = baseVersionSource, SortBy = CommitSortStrategies.Reverse, FirstParentOnly = true }; var commitCollection = Commits.QueryBy(filter); var mainlineCommitLog = commitCollection.ToList(); return(mainlineCommitLog); }
public bool IsThereAnyCommitOnTheBranch(IRepository repo, Branch branch) { var filter = new CommitFilter { Since = branch, Until = repo.FindBranch("develop") }; var commits = repo.Commits.QueryBy(filter); if (!commits.Any()) { return(false); } return(true); }
public IEnumerable <ICommit> GetMergeBaseCommits(ICommit?mergeCommit, ICommit mergedHead, ICommit findMergeBase) { var filter = new CommitFilter { IncludeReachableFrom = mergedHead, ExcludeReachableFrom = findMergeBase }; var commitCollection = Commits.QueryBy(filter); var commits = mergeCommit != null ? new[] { mergeCommit }.Union(commitCollection) : commitCollection; return(commits.ToList()); }
public ICommit GetBaseVersionSource(ICommit currentBranchTip) { try { var filter = new CommitFilter { IncludeReachableFrom = currentBranchTip }; var commitCollection = Commits.QueryBy(filter); var baseVersionSource = commitCollection.First(c => !c.Parents.Any()); return(baseVersionSource); } catch (NotFoundException exception) { throw new GitVersionException($"Cannot find commit {currentBranchTip}. Please ensure that the repository is an unshallow clone with `git fetch --unshallow`.", exception); } }