Map rewritten parents to rewritten commits

This commit is contained in:
Keith Dahlby 2013-08-12 15:11:32 -05:00
Родитель dfadc13c80
Коммит 7b7aef0abf
2 изменённых файлов: 53 добавлений и 6 удалений

Просмотреть файл

@ -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()
{

Просмотреть файл

@ -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);