Skip to content

History rewriting and documentaton #1185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 26, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions LibGit2Sharp.Tests/FilterBranchFixture.cs
Original file line number Diff line number Diff line change
@@ -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"]);
2 changes: 1 addition & 1 deletion LibGit2Sharp/Commit.cs
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ internal Commit(Repository repo, ObjectId id)
/// <summary>
/// Gets the <see cref="TreeEntry"/> pointed at by the <paramref name="relativePath"/> in the <see cref="Tree"/>.
/// </summary>
/// <param name="relativePath">The relative path to the <see cref="TreeEntry"/> from the <see cref="Commit"/> working directory.</param>
/// <param name="relativePath">Path to the <see cref="TreeEntry"/> from the tree in this <see cref="Commit"/></param>
/// <returns><c>null</c> if nothing has been found, the <see cref="TreeEntry"/> otherwise.</returns>
public virtual TreeEntry this[string relativePath]
{
6 changes: 3 additions & 3 deletions LibGit2Sharp/Core/HistoryRewriter.cs
Original file line number Diff line number Diff line change
@@ -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<TRef, TTarget>(
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;
8 changes: 8 additions & 0 deletions LibGit2Sharp/RewriteHistoryOptions.cs
Original file line number Diff line number Diff line change
@@ -77,5 +77,13 @@ public RewriteHistoryOptions()
/// </para>
/// </summary>
public Action<Exception> OnError { get; set; }

/// <summary>
/// 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.
/// </summary>
/// <value><c>true</c> if Commit messages are prettified; otherwise, <c>false</c>.</value>
public bool PrettifyMessages { get; set; }
}
}