diff options
author | nulltoken <emeric.fermas@gmail.com> | 2015-05-27 21:02:43 +0300 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2015-05-27 21:02:43 +0300 |
commit | 63f8d6d90f06f4578604b57502f2c6b8aabf4479 (patch) | |
tree | 3df6281a0c8d286694ee2b29bbc5d2b39ec12e8d | |
parent | cc04c4342e9c518b21a4580f771f6a9985a90c67 (diff) | |
parent | 59eb6c80c110d0a1ecc6869ff093806f6c56df5c (diff) |
Merge pull request #942 from libgit2/ntk/history_rewriter_notes
Restrict potential reference targets of HistoryRewriter
-rw-r--r-- | LibGit2Sharp.Tests/FilterBranchFixture.cs | 23 | ||||
-rw-r--r-- | LibGit2Sharp/Core/HistoryRewriter.cs | 6 |
2 files changed, 27 insertions, 2 deletions
diff --git a/LibGit2Sharp.Tests/FilterBranchFixture.cs b/LibGit2Sharp.Tests/FilterBranchFixture.cs index dfe14329..aed628a1 100644 --- a/LibGit2Sharp.Tests/FilterBranchFixture.cs +++ b/LibGit2Sharp.Tests/FilterBranchFixture.cs @@ -162,7 +162,8 @@ namespace LibGit2Sharp.Tests 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")); } @@ -801,6 +802,26 @@ namespace LibGit2Sharp.Tests 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/"; diff --git a/LibGit2Sharp/Core/HistoryRewriter.cs b/LibGit2Sharp/Core/HistoryRewriter.cs index 15686ecc..d520b3c2 100644 --- a/LibGit2Sharp/Core/HistoryRewriter.cs +++ b/LibGit2Sharp/Core/HistoryRewriter.cs @@ -59,7 +59,11 @@ namespace LibGit2Sharp.Core // 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); } |