Skip to content

Restrict potential reference targets of HistoryRewriter #942

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 1 commit into from
May 27, 2015
Merged
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion LibGit2Sharp.Tests/FilterBranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public void CanRewriteAuthorOfCommits()

AssertSucceedingButNotError();

var nonBackedUpRefs = repo.Refs.Where(x => !x.CanonicalName.StartsWith("refs/original"));
var nonBackedUpRefs = repo.Refs.Where(
x => !x.CanonicalName.StartsWith("refs/original/") && !x.CanonicalName.StartsWith("refs/notes/"));
Assert.Empty(repo.Commits.QueryBy(new CommitFilter { Since = nonBackedUpRefs })
.Where(c => c.Author.Name != "Ben Straub"));
}
Expand Down Expand Up @@ -801,6 +802,26 @@ public void HandlesNameRewritingOfChainedTags()
Assert.Equal(annotationB, backedUpTag.ResolveToDirectReference().Target);
}

[Fact]
public void RewritingNotesHasNoEffect()
{
var notesRefsRetriever = new Func<IEnumerable<Reference>>(() => repo.Refs.Where(r => r.CanonicalName.StartsWith("refs/notes/")));
var originalNotesRefs = notesRefsRetriever().ToList();
var commits = repo.Commits.QueryBy(new CommitFilter { Since = originalNotesRefs }).ToArray();

repo.Refs.RewriteHistory(new RewriteHistoryOptions
{
OnError = OnError,
OnSucceeding = OnSucceeding,
CommitHeaderRewriter =
c => CommitRewriteInfo.From(c, author: Constants.Signature),
}, commits);

AssertSucceedingButNotError();

Assert.Equal(originalNotesRefs.OrderBy(r => r.CanonicalName), notesRefsRetriever().OrderBy(r => r.CanonicalName));
}

private static string TagNameRewriter(string name, bool isAnnotated, string target)
{
const string tagPrefix = "refs/tags/";
Expand Down
6 changes: 5 additions & 1 deletion LibGit2Sharp/Core/HistoryRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public void Execute()
// before A.
foreach (var reference in refsToRewrite.OrderBy(ReferenceDepth))
{
// TODO: Check how rewriting of notes actually behaves
// TODO: Rewrite refs/notes/* properly
if (reference.CanonicalName.StartsWith("refs/notes/"))
{
continue;
}

RewriteReference(reference);
}
Expand Down