Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6f9e97

Browse files
committed
Merge pull request #1185 from Vogel612/HistoryRewriting_and_Documentaton
History rewriting and documentaton
2 parents 4ba6b9d + 80cb2af commit e6f9e97

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

LibGit2Sharp.Tests/FilterBranchFixture.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ public void CanRewriteAuthorOfCommitsOnlyBeingPointedAtByTags()
191191
AssertSucceedingButNotError();
192192

193193
var lightweightTag = repo.Tags["so-lonely"];
194-
Assert.Equal("Bam!\n", ((Commit)lightweightTag.Target).Message);
194+
Assert.Equal("Bam!", ((Commit)lightweightTag.Target).Message);
195195

196196
var annotatedTag = repo.Tags["so-lonely-but-annotated"];
197-
Assert.Equal("Bam!\n", ((Commit)annotatedTag.Target).Message);
197+
Assert.Equal("Bam!", ((Commit)annotatedTag.Target).Message);
198198
}
199199

200200
[Fact]
@@ -495,7 +495,7 @@ public void DoesNotRewriteRefsThatDontChange()
495495
var parents = repo.Branches["br2"].Tip.Parents.ToList();
496496
Assert.Equal(2, parents.Count());
497497
Assert.NotEmpty(parents.Where(c => c.Sha.StartsWith("9fd738e")));
498-
Assert.Equal("abc\n", parents.Single(c => !c.Sha.StartsWith("9fd738e")).Message);
498+
Assert.Equal("abc", parents.Single(c => !c.Sha.StartsWith("9fd738e")).Message);
499499
}
500500

501501
[Fact]
@@ -530,7 +530,7 @@ public void CanNotOverWriteBackedUpReferences()
530530
AssertErrorFired(ex);
531531
AssertSucceedingNotFired();
532532

533-
Assert.Equal("abc\n", repo.Head.Tip.Message);
533+
Assert.Equal("abc", repo.Head.Tip.Message);
534534

535535
var newOriginalRefs = repo.Refs.FromGlob("refs/original/*").OrderBy(r => r.CanonicalName).ToArray();
536536
Assert.Equal(originalRefs, newOriginalRefs);
@@ -791,7 +791,7 @@ public void HandlesNameRewritingOfChainedTags()
791791
var newCommit = newAnnotationC.Target as Commit;
792792
Assert.NotNull(newCommit);
793793
Assert.NotEqual(newCommit, theCommit);
794-
Assert.Equal("Rewrote\n", newCommit.Message);
794+
Assert.Equal("Rewrote", newCommit.Message);
795795

796796
// Ensure the original tag doesn't exist anymore
797797
Assert.Null(repo.Tags["lightweightA"]);

LibGit2Sharp/Commit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal Commit(Repository repo, ObjectId id)
5454
/// <summary>
5555
/// Gets the <see cref="TreeEntry"/> pointed at by the <paramref name="relativePath"/> in the <see cref="Tree"/>.
5656
/// </summary>
57-
/// <param name="relativePath">The relative path to the <see cref="TreeEntry"/> from the <see cref="Commit"/> working directory.</param>
57+
/// <param name="relativePath">Path to the <see cref="TreeEntry"/> from the tree in this <see cref="Commit"/></param>
5858
/// <returns><c>null</c> if nothing has been found, the <see cref="TreeEntry"/> otherwise.</returns>
5959
public virtual TreeEntry this[string relativePath]
6060
{

LibGit2Sharp/Core/HistoryRewriter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void Execute()
5252
var commits = repo.Commits.QueryBy(filter);
5353
foreach (var commit in commits)
5454
{
55-
RewriteCommit(commit);
55+
RewriteCommit(commit, options);
5656
}
5757

5858
// Ordering matters. In the case of `A -> B -> commit`, we need to make sure B is rewritten
@@ -199,7 +199,7 @@ private Reference RewriteReference<TRef, TTarget>(
199199
return refMap[oldRef] = movedRef;
200200
}
201201

202-
private void RewriteCommit(Commit commit)
202+
private void RewriteCommit(Commit commit, RewriteHistoryOptions options)
203203
{
204204
var newHeader = CommitRewriteInfo.From(commit);
205205
var newTree = commit.Tree;
@@ -248,7 +248,7 @@ private void RewriteCommit(Commit commit)
248248
newHeader.Message,
249249
newTree,
250250
mappedNewParents,
251-
true);
251+
options.PrettifyMessages);
252252

253253
// Record the rewrite
254254
objectMap[commit] = newCommit;

LibGit2Sharp/RewriteHistoryOptions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,13 @@ public RewriteHistoryOptions()
7777
/// </para>
7878
/// </summary>
7979
public Action<Exception> OnError { get; set; }
80+
81+
/// <summary>
82+
/// Specifies Commit message prettifying behavior during rewrite.
83+
/// NOTE: Prettifying may result in losing one or multiple lines in the commit message.
84+
/// As such it is recommended to leave this set to false.
85+
/// </summary>
86+
/// <value><c>true</c> if Commit messages are prettified; otherwise, <c>false</c>.</value>
87+
public bool PrettifyMessages { get; set; }
8088
}
8189
}

0 commit comments

Comments
 (0)