/// <summary> /// Processes all commits. /// </summary> private void ProcessCommits() { // We are working only in a topological-reverse order (from parent commits to child) var commitFilter = new CommitFilter() { FirstParentOnly = false, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse }; // If a revision range is specified, try to use it if (RevisionRange != null) { var revSpec = RevSpec.Parse(repo, RevisionRange); if (revSpec.Type == RevSpecType.Single) { commitFilter.Since = revSpec.From.Id; } else if (revSpec.Type == RevSpecType.Range) { commitFilter.Range = RevisionRange; } } // Gets all commits in topological reverse order var commits = repo.Commits.QueryBy(commitFilter).ToList(); // Process commits for (int i = 0; i < commits.Count; i++) { var commit = GetSimpleCommit(commits[i]); OutputWriter.Write("Rewrite {0} ({1}/{2}){3}", commit.Id, i + 1, commits.Count, (i + 1) == commits.Count ? string.Empty : "\r"); ProcessCommit(commit); } if (commits.Count == 0) { OutputWriter.WriteLine("Nothing to rewrite."); } else { OutputWriter.WriteLine(" in {0:#.###}s", clock.Elapsed.TotalSeconds); } }
/// <summary> /// This method Validates the parameters. /// </summary> /// <exception cref="GitRocketFilter.RocketException"> /// No valid git repository path found at [{0}] /// or /// Branch name is required and cannot be null /// or /// The branch [{0}] already exist. Cannot overwrite without force option /// or /// Invalid revspec [{0}]. Reason: {1} /// </exception> private void ValidateParameters() { if (!Repository.IsValid(RepositoryPath)) { throw new RocketException("No valid git repository path found at [{0}]", RepositoryPath); } repo = new Repository(RepositoryPath); if (string.IsNullOrWhiteSpace(BranchName)) { throw new RocketException("Branch name is required and cannot be null"); } branchRef = "refs/heads/" + BranchName; if (repo.Refs[branchRef] != null && !BranchOverwrite) { throw new RocketException("The branch [{0}] already exist. Cannot overwrite without force option", BranchName); } // Validate the revision range if (!string.IsNullOrWhiteSpace(RevisionRange)) { string errorMessage = null; try { revisionSpec = RevSpec.Parse(repo, RevisionRange); if (revisionSpec.Type == RevSpecType.MergeBase) { errorMessage = "Merge base revspec are not supported"; } } catch (LibGit2SharpException libGitException) { errorMessage = libGitException.Message; } if (errorMessage != null) { throw new RocketException("Invalid revspec [{0}]. Reason: {1}", RevisionRange, errorMessage); } } }