Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Dahlby <dahlbyk@gmail.com>2013-08-13 00:11:32 +0400
committerKeith Dahlby <dahlbyk@gmail.com>2013-08-17 07:55:16 +0400
commit7b7aef0abfaca5c1b9374c9cdda46635b1c53d67 (patch)
tree36e6176c3fee7e251a7af560568fa59db0800d28
parentdfadc13c80b77121e8ae7a83f5b28ac5098078a2 (diff)
Map rewritten parents to rewritten commits
-rw-r--r--LibGit2Sharp.Tests/FilterBranchFixture.cs45
-rw-r--r--LibGit2Sharp/Core/HistoryRewriter.cs14
2 files changed, 53 insertions, 6 deletions
diff --git a/LibGit2Sharp.Tests/FilterBranchFixture.cs b/LibGit2Sharp.Tests/FilterBranchFixture.cs
index ec86da1a..5f195a56 100644
--- a/LibGit2Sharp.Tests/FilterBranchFixture.cs
+++ b/LibGit2Sharp.Tests/FilterBranchFixture.cs
@@ -315,6 +315,51 @@ namespace LibGit2Sharp.Tests
Assert.True(hasBeenCalled);
}
+ // Graft the orphan "test" branch to the tip of "packed"
+ //
+ // Before:
+ // * e90810b (test, lw, e90810b, test)
+ // |
+ // * 6dcf9bf
+ // <------------------ note: no connection
+ // * 41bc8c6 (packed)
+ // |
+ // * 5001298
+ //
+ // ... and after:
+ //
+ // * f558880 (test, lw, e90810b, test)
+ // |
+ // * 0c25efa
+ // | <------------------ add this link
+ // * 41bc8c6 (packed)
+ // |
+ // * 5001298
+ [Fact]
+ public void CanRewriteParentWithRewrittenCommit()
+ {
+ var commitToRewrite = repo.Lookup<Commit>("6dcf9bf");
+ var newParent = repo.Lookup<Commit>("41bc8c6");
+
+ repo.Refs.RewriteHistory(new RewriteHistoryOptions
+ {
+ CommitHeaderRewriter =
+ c =>
+ c.Id != newParent.Id
+ ? null
+ : CommitRewriteInfo.From(c, message: "changed"),
+ CommitParentsRewriter =
+ c =>
+ c.Id != commitToRewrite.Id
+ ? c.Parents
+ : new[] { newParent }
+ }, commitToRewrite, newParent);
+
+ var rewrittenParent = repo.Lookup<Commit>("refs/heads/test~").Parents.Single();
+ Assert.Equal(newParent.Tree, rewrittenParent.Tree);
+ Assert.NotEqual(newParent, rewrittenParent);
+ }
+
[Fact]
public void WritesCorrectReflogMessagesForSimpleRewrites()
{
diff --git a/LibGit2Sharp/Core/HistoryRewriter.cs b/LibGit2Sharp/Core/HistoryRewriter.cs
index c4b3c7f0..f70ea9c4 100644
--- a/LibGit2Sharp/Core/HistoryRewriter.cs
+++ b/LibGit2Sharp/Core/HistoryRewriter.cs
@@ -127,12 +127,7 @@ namespace LibGit2Sharp.Core
var newTree = commit.Tree;
// Find the new parents
- var newParents = commit.Parents
- .Select(oldParent =>
- shaMap.ContainsKey(oldParent.Id)
- ? shaMap[oldParent.Id]
- : oldParent.Id)
- .Select(id => repo.Lookup<Commit>(id));
+ var newParents = commit.Parents;
if (targetedCommits.Contains(commit))
{
@@ -157,6 +152,13 @@ namespace LibGit2Sharp.Core
}
// Create the new commit
+ newParents = newParents
+ .Select(oldParent =>
+ shaMap.ContainsKey(oldParent.Id)
+ ? shaMap[oldParent.Id]
+ : oldParent.Id)
+ .Select(id => repo.Lookup<Commit>(id));
+
var newCommit = repo.ObjectDatabase.CreateCommit(newHeader.Message, newHeader.Author,
newHeader.Committer, newTree,
newParents);