From bdef11a805eb5c5afbadbb4923e8b77f7aece98e Mon Sep 17 00:00:00 2001 From: Vogel612 Date: Tue, 8 Sep 2015 00:42:12 +0200 Subject: [PATCH 1/2] Adjusted Commit indexer xml doc see and fixes #966 --- LibGit2Sharp/Commit.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibGit2Sharp/Commit.cs b/LibGit2Sharp/Commit.cs index d878655ef..ea7844477 100644 --- a/LibGit2Sharp/Commit.cs +++ b/LibGit2Sharp/Commit.cs @@ -54,7 +54,7 @@ internal Commit(Repository repo, ObjectId id) /// /// Gets the pointed at by the in the . /// - /// The relative path to the from the working directory. + /// Path to the from the tree in this /// null if nothing has been found, the otherwise. public virtual TreeEntry this[string relativePath] { From 80cb2af9aeaa59a41463dc4903da3446f5b062e9 Mon Sep 17 00:00:00 2001 From: Vogel612 Date: Tue, 8 Sep 2015 13:52:47 +0200 Subject: [PATCH 2/2] Added Prettifying Option to RewriteHistoryOptions see #621. The default prettifying behabiour now is: do not prettify Documentation for the new property of RewriteHistoryOptions --- LibGit2Sharp.Tests/FilterBranchFixture.cs | 10 +++++----- LibGit2Sharp/Core/HistoryRewriter.cs | 6 +++--- LibGit2Sharp/RewriteHistoryOptions.cs | 8 ++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/LibGit2Sharp.Tests/FilterBranchFixture.cs b/LibGit2Sharp.Tests/FilterBranchFixture.cs index 2199cea4c..d71cb22d8 100644 --- a/LibGit2Sharp.Tests/FilterBranchFixture.cs +++ b/LibGit2Sharp.Tests/FilterBranchFixture.cs @@ -191,10 +191,10 @@ public void CanRewriteAuthorOfCommitsOnlyBeingPointedAtByTags() AssertSucceedingButNotError(); var lightweightTag = repo.Tags["so-lonely"]; - Assert.Equal("Bam!\n", ((Commit)lightweightTag.Target).Message); + Assert.Equal("Bam!", ((Commit)lightweightTag.Target).Message); var annotatedTag = repo.Tags["so-lonely-but-annotated"]; - Assert.Equal("Bam!\n", ((Commit)annotatedTag.Target).Message); + Assert.Equal("Bam!", ((Commit)annotatedTag.Target).Message); } [Fact] @@ -495,7 +495,7 @@ public void DoesNotRewriteRefsThatDontChange() var parents = repo.Branches["br2"].Tip.Parents.ToList(); Assert.Equal(2, parents.Count()); Assert.NotEmpty(parents.Where(c => c.Sha.StartsWith("9fd738e"))); - Assert.Equal("abc\n", parents.Single(c => !c.Sha.StartsWith("9fd738e")).Message); + Assert.Equal("abc", parents.Single(c => !c.Sha.StartsWith("9fd738e")).Message); } [Fact] @@ -530,7 +530,7 @@ public void CanNotOverWriteBackedUpReferences() AssertErrorFired(ex); AssertSucceedingNotFired(); - Assert.Equal("abc\n", repo.Head.Tip.Message); + Assert.Equal("abc", repo.Head.Tip.Message); var newOriginalRefs = repo.Refs.FromGlob("refs/original/*").OrderBy(r => r.CanonicalName).ToArray(); Assert.Equal(originalRefs, newOriginalRefs); @@ -791,7 +791,7 @@ public void HandlesNameRewritingOfChainedTags() var newCommit = newAnnotationC.Target as Commit; Assert.NotNull(newCommit); Assert.NotEqual(newCommit, theCommit); - Assert.Equal("Rewrote\n", newCommit.Message); + Assert.Equal("Rewrote", newCommit.Message); // Ensure the original tag doesn't exist anymore Assert.Null(repo.Tags["lightweightA"]); diff --git a/LibGit2Sharp/Core/HistoryRewriter.cs b/LibGit2Sharp/Core/HistoryRewriter.cs index a805a6a1a..c4cc2be8b 100644 --- a/LibGit2Sharp/Core/HistoryRewriter.cs +++ b/LibGit2Sharp/Core/HistoryRewriter.cs @@ -52,7 +52,7 @@ public void Execute() var commits = repo.Commits.QueryBy(filter); foreach (var commit in commits) { - RewriteCommit(commit); + RewriteCommit(commit, options); } // Ordering matters. In the case of `A -> B -> commit`, we need to make sure B is rewritten @@ -199,7 +199,7 @@ private Reference RewriteReference( return refMap[oldRef] = movedRef; } - private void RewriteCommit(Commit commit) + private void RewriteCommit(Commit commit, RewriteHistoryOptions options) { var newHeader = CommitRewriteInfo.From(commit); var newTree = commit.Tree; @@ -248,7 +248,7 @@ private void RewriteCommit(Commit commit) newHeader.Message, newTree, mappedNewParents, - true); + options.PrettifyMessages); // Record the rewrite objectMap[commit] = newCommit; diff --git a/LibGit2Sharp/RewriteHistoryOptions.cs b/LibGit2Sharp/RewriteHistoryOptions.cs index 031839c38..59a982dc2 100644 --- a/LibGit2Sharp/RewriteHistoryOptions.cs +++ b/LibGit2Sharp/RewriteHistoryOptions.cs @@ -77,5 +77,13 @@ public RewriteHistoryOptions() /// /// public Action OnError { get; set; } + + /// + /// Specifies Commit message prettifying behavior during rewrite. + /// NOTE: Prettifying may result in losing one or multiple lines in the commit message. + /// As such it is recommended to leave this set to false. + /// + /// true if Commit messages are prettified; otherwise, false. + public bool PrettifyMessages { get; set; } } }