public static async Task <IEnumerable <string> > GetCommitMessagesFromTagAsync(
            this IRepository repository,
            TagFilter filter)
        {
            var tag = repository.Tags.From(filter);

            if (tag is null)
            {
                throw new NullReferenceException("No tag was found with provided name.");
            }

            var commit = repository.Commits.FirstOrDefault(x => x.Sha.Equals(tag.PeeledTarget.Sha));

            if (commit is null)
            {
                throw new NullReferenceException("No commits were found from provided tag.");
            }

            var exclusionList = new List <Commit>(commit.Parents)
            {
                commit
            };
            var commitFilter = new CommitFilter()
            {
                ExcludeReachableFrom = exclusionList
            };

            return(await repository.GetCommitMessagesByFilterAsync(commitFilter));
        }
示例#2
0
        /// <summary>
        /// Returns the list of commits of the repository representing the history of a file beyond renames.
        /// </summary>
        /// <param name="path">The file's path.</param>
        /// <param name="filter">The options used to control which commits will be returned.</param>
        /// <returns>A list of file history entries, ready to be enumerated.</returns>
        public IEnumerable <LogEntry> QueryBy(string path, CommitFilter filter)
        {
            Ensure.ArgumentNotNull(path, "path");
            Ensure.ArgumentNotNull(filter, "filter");

            return(new FileHistory(repo, path, filter));
        }
        public IActionResult Get(string repositoryId)
        {
            var operation = TableOperation.Retrieve<Repository>("1", repositoryId);
            var result = _storage.Repositories.Execute(operation);

            var repositoryEntity = result.Result as Repository;
            if (repositoryEntity == null)
            {
                return new ObjectResult(_errorFactory.RepositoryNotFound());
            }

            using (var repo = new LibGit2Sharp.Repository(repositoryEntity.Path))
            {
                var filter = new CommitFilter {Since = repo.Branches["master"], Until = repo.Branches["development"]};

                var commits = repo.Commits.QueryBy(filter);

                var repositoryLogs = new RepositoryLogCollection(
                    repositoryId,
                    commits.Select(c => new RepositoryLog
                    {
                        RepositoryId = repositoryId,
                        Sha = c.Sha,
                        ShortMessage = c.MessageShort,
                        Author = c.Author.Name
                    }).ToList());

                return new ObjectResult(repositoryLogs);
            }
        }
        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;
        }
示例#5
0
        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;
        }
示例#6
0
        /// <summary>
        /// Returns the list of commits of the repository matching the specified <paramref name="filter"/>.
        /// </summary>
        /// <param name="filter">The options used to control which commits will be returned.</param>
        /// <returns>A list of commits, ready to be enumerated.</returns>
        public ICommitLog QueryBy(CommitFilter filter)
        {
            Ensure.ArgumentNotNull(filter, "filter");
            Ensure.ArgumentNotNull(filter.IncludeReachableFrom, "filter.IncludeReachableFrom");
            Ensure.ArgumentNotNullOrEmptyString(filter.IncludeReachableFrom.ToString(), "filter.IncludeReachableFrom");

            return(new CommitLog(repo, filter));
        }
示例#7
0
        /// <summary>
        /// Returns the list of commits of the repository matching the specified <paramref name="filter"/>.
        /// </summary>
        /// <param name="filter">The options used to control which commits will be returned.</param>
        /// <returns>A list of commits, ready to be enumerated.</returns>
        public virtual ICommitLog QueryBy(CommitFilter filter)
        {
            Ensure.ArgumentNotNull(filter, "filter");
            Ensure.ArgumentNotNull(filter.Since, "filter.Since");
            Ensure.ArgumentNotNullOrEmptyString(filter.Since.ToString(), "filter.Since");

            return(new CommitLog(repo, filter));
        }
示例#8
0
            public CommitEnumerator(Repository repo, CommitFilter filter)
            {
                this.repo = repo;
                handle    = Proxy.git_revwalk_new(repo.Handle);
                repo.RegisterForCleanup(handle);

                Sort(filter.SortBy);
                Push(filter.SinceList);
                Hide(filter.UntilList);
            }
示例#9
0
        internal CommitFilter ToCommitFilter()
        {
            var cf = new CommitFilter
                         {
                             Since = Since,
                             SortBy = (CommitSortStrategies) SortBy,
                             Until = Until
                         };

            return cf;
        }
示例#10
0
        public List<string> GetCommitHistory()
        {
            using (var repo = new Repository(_basePath))
            {
                // Get the revisions in reverse order
                // git log --topo-order --reverse
                var filter = new CommitFilter { SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse };

                return repo.Commits.QueryBy(filter).Select(c => string.Format("{0} {1}<{2}> - {3}", c.Sha.Substring(0, 7), c.Author.Name, c.Author.Email, c.MessageShort)).ToList();
            }
        }
示例#11
0
        internal CommitFilter ToCommitFilter()
        {
            var cf = new CommitFilter
            {
                Since  = Since,
                SortBy = (CommitSortStrategies)SortBy,
                Until  = Until
            };

            return(cf);
        }
示例#12
0
 protected static List<Commit> GetCommits(Repository repo, string since = null)
 {
     var filter = new CommitFilter() {SortBy = CommitSortStrategies.Topological};
     if (since != null)
     {
         filter.Since = since;
     }
     return
         repo.Commits.QueryBy(filter)
             .ToList();
 }
        int NumberOfCommitsOnBranchSinceCommit(GitVersionContext context, Commit commit)
        {
            var qf = new CommitFilter
            {
                Since = context.CurrentBranch,
                Until = commit,
                SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time
            };

            return context.Repository.Commits
                .QueryBy(qf)
                .Count();
        }
示例#14
0
        public void Get(string path)
        {
            using (var repo = new Repository(path))
            {
                var filter = new CommitFilter { Since = repo.Branches["master"], Until = repo.Branches["development"] };

                var commits = repo.Commits.QueryBy(filter);

                foreach (var commit in commits)
                {
                    Console.WriteLine(commit.Id);   // Of course the output can be prettified ;-)
                }
            }
        }
        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;
        }
示例#16
0
        public SemanticVersionBuildMetaData Create(Commit baseVersionSource, GitVersionContext context)
        {
            var qf = new CommitFilter
            {
                Since = context.CurrentCommit,
                Until = baseVersionSource,
                SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time
            };

            var commitLog = context.Repository.Commits.QueryBy(qf);
            var commitsSinceTag = commitLog.Count();

            return new SemanticVersionBuildMetaData(
                commitsSinceTag,
                context.CurrentBranch.Name,
                context.CurrentCommit.Sha,
                context.CurrentCommit.When());
        }
示例#17
0
        public SemanticVersionBuildMetaData Create(Commit baseVersionSource, GitVersionContext context)
        {
            var qf = new CommitFilter
            {
                IncludeReachableFrom = context.CurrentCommit,
                ExcludeReachableFrom = baseVersionSource,
                SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time
            };

            var commitLog = context.Repository.Commits.QueryBy(qf);
            var commitsSinceTag = commitLog.Count();
            Logger.WriteInfo(string.Format("{0} commits found between {1} and {2}", commitsSinceTag, baseVersionSource.Sha, context.CurrentCommit.Sha));

            return new SemanticVersionBuildMetaData(
                commitsSinceTag,
                context.CurrentBranch.FriendlyName,
                context.CurrentCommit.Sha,
                context.CurrentCommit.When());
        }
        /// <summary>
        /// Returns a list of commit messages based on commit filter.
        /// </summary>
        /// <param name="repository">Repository to obtain the commit messages.</param>
        /// <param name="commitFilter">Commit filter to be used as query criteria.</param>
        /// <returns>A list of commit messages.</returns>
        private static Task <IEnumerable <string> > GetCommitMessagesByFilterAsync(
            this IRepository repository,
            CommitFilter commitFilter)
        {
            IEnumerable <Commit> commits = repository.Commits.QueryBy(commitFilter);

            var remote = repository.Network.Remotes.FirstOrDefault();

            return(Task.FromResult(commits.Select(
                                       x =>
            {
                var url = string.Empty;

                if (remote is object)
                {
                    if (remote.Url.IndexOf("@") > 0)
                    {
                        url = $"{remote.Url.Substring(0, remote.Url.IndexOf("//") + 2)}{remote.Url.Substring(remote.Url.IndexOf("@") + 1)}";
                    }
                    else
                    {
                        url = remote.Url;
                    }
                }

                var commitSha = $"\nSha: {x.Sha}";
                var commitAuthor = $"Author Name: {x.Author.Name}";
                var commitAuthorEmail = $"Author Email: {x.Author.Email}";
                var commitDate = $"Date: {x.Author.When}";
                var commitUrl = $"Url: {url}/commit/{x.Sha}";

                return string.Join("\n",
                                   x.Message,
                                   commitSha,
                                   commitAuthor,
                                   commitAuthorEmail,
                                   commitDate,
                                   commitUrl);
            })));
        }
示例#19
0
        public string FindCommitHashByChangesetId(long changesetId)
        {
            Trace.WriteLine("Looking for changeset " + changesetId + " in git repository...");

            var patternToFind = "git-tfs-id: .*;C" + changesetId + "[^0-9]";
            var regex = new Regex(patternToFind);

            var reachableFromRemoteBranches = new CommitFilter
            {
                Since = _repository.Branches.Where(p => p.IsRemote),
                SortBy = CommitSortStrategies.None
            };

            var commitsFromRemoteBranches = _repository.Commits.QueryBy(reachableFromRemoteBranches);

            var commit = commitsFromRemoteBranches.FirstOrDefault(c => regex.IsMatch(c.Message));
            if (commit != null)
            {
                Trace.WriteLine(" => Commit found! hash: " + commit.Sha);
                return commit.Sha;
            }

            Trace.WriteLine(" => Commit not found!");
            return null;
        }
        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;
            }
        }
        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);
        }
示例#22
0
        private Commit FindCommitByChangesetId(long changesetId, string remoteRef = null)
        {
            Trace.WriteLine("Looking for changeset " + changesetId + " in git repository...");

            var regex = new Regex("git-tfs-id: .*;C" + changesetId + "[^0-9]", RegexOptions.Singleline | RegexOptions.Compiled);

            var reachableFromRemoteBranches = new CommitFilter
            {
                Since = _repository.Branches.Where(p => p.IsRemote),
                SortBy = CommitSortStrategies.None
            };

            if (remoteRef != null)
                reachableFromRemoteBranches.Since = _repository.Branches.Where(p => p.IsRemote && p.CanonicalName.EndsWith(remoteRef));
            var commitsFromRemoteBranches = _repository.Commits.QueryBy(reachableFromRemoteBranches);

            var commit = commitsFromRemoteBranches.FirstOrDefault(c => regex.IsMatch(c.Message));
            Trace.WriteLine((commit == null) ? " => Commit not found!" : " => Commit found! hash: " + commit.Sha);
            return commit;
        }
示例#23
0
        private Commit FindCommitByChangesetId(long changesetId, string remoteRef = null)
        {
            Trace.WriteLine("Looking for changeset " + changesetId + " in git repository...");

            if (remoteRef == null)
            {
                string sha;
                if (changesetsCache.TryGetValue(changesetId, out sha))
                    return _repository.Lookup<Commit>(sha);
                if (cacheIsFull)
                    return null;
            }

            var reachableFromRemoteBranches = new CommitFilter
            {
                Since = _repository.Branches.Where(p => p.IsRemote),
                SortBy = CommitSortStrategies.Time
            };

            if (remoteRef != null)
                reachableFromRemoteBranches.Since = _repository.Branches.Where(p => p.IsRemote && p.CanonicalName.EndsWith(remoteRef));
            var commitsFromRemoteBranches = _repository.Commits.QueryBy(reachableFromRemoteBranches);

            Commit commit = null;
            foreach (var c in commitsFromRemoteBranches)
            {
                long id;
                if (TryParseChangesetId(c.Message, out id))
                {
                    changesetsCache[id] = c.Sha;
                    if (id == changesetId)
                    {
                        commit = c;
                        break;
                    }
                }
            }
            if (remoteRef == null && commit == null)
                cacheIsFull = true; // repository fully scanned
            Trace.WriteLine((commit == null) ? " => Commit not found!" : " => Commit found! hash: " + commit.Sha);
            return commit;
        }
        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 ErrorException(message);
            }

            var filter = new CommitFilter
                         {
                             Since = branch.Tip,
                             Until = ancestor,
                             SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time
                         };

            return repo.Commits.QueryBy(filter).Count();
        }
 public IEnumerable<LogEntry> QueryBy(string path, CommitFilter filter)
 {
     throw new NotImplementedException();
 }
示例#26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommitLog"/> class.
 /// </summary>
 /// <param name="repo">The repository.</param>
 /// <param name="queryFilter">The filter to use in querying commits</param>
 internal CommitLog(Repository repo, CommitFilter queryFilter)
 {
     this.repo        = repo;
     this.queryFilter = queryFilter;
 }
 public ICommitLog QueryBy(CommitFilter filter)
 {
     return this;
 }
        internal List<Commit> GetLatestCommits(int commitCount)
        {
            try
            {
                using (var repository = GetRepository())
                {
                    var filter = new CommitFilter { SortBy = CommitSortStrategies.Time };
                    return repository.Commits.QueryBy(filter)
                        .Take(commitCount)
                        .Select(commit => CreateCommit(commit)).ToList();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
示例#29
0
 private static VersionField FindMessageIncrement(
     GitVersionContext context, Commit mergeCommit, Commit mergedHead, Commit findMergeBase, List<Commit> commitLog)
 {
     var filter = new CommitFilter
     {
         IncludeReachableFrom = mergedHead,
         ExcludeReachableFrom = findMergeBase
     };
     var commits = mergeCommit == null ? 
         context.Repository.Commits.QueryBy(filter).ToList() : 
         new[] { mergeCommit }.Union(context.Repository.Commits.QueryBy(filter)).ToList();
     commitLog.RemoveAll(c => commits.Any(c1 => c1.Sha == c.Sha));
     return IncrementStrategyFinder.GetIncrementForCommits(context, commits) ?? VersionField.Patch;
 }
示例#30
0
        private int GetCommitsCountBetweenHeadAndCommit(Repository repository, GitObject target)
        {
            var filter = new CommitFilter();
            filter.Since = repository.Head.Commits.First();
            filter.Until = target;

            return repository.Commits.QueryBy(filter).Count();
        }
示例#31
0
 public ICommitLog QueryBy(CommitFilter filter)
 {
     throw new NotImplementedException();
 }