Hi Folks, This isn't a bug report but a question I have regarding calling the RewriteHistory method on the same commit.
public class Tests
{
Repository Repository;
DirectoryInfo RepositoryDirectoryInfo;
private static void CopyDirectoryContents(string sourcePath, string targetPath)
{
// copies repository, containg .git and repository content to a temp path. not important for this.
}
private static Repository LoadRepository(string repositoryAbsolutePath)
{
return new Repository(repositoryAbsolutePath);
}
[SetUp]
public void Setup()
{
// Create a temporary directory
string temporaryGitRepositoryAbsPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
RepositoryDirectoryInfo = Directory.CreateDirectory(temporaryGitRepositoryAbsPath);
// Create a copy of the git Repository fixture as testing will modify the fixture itself
string fixtureGitRepositoryRelPath = "Fixtures\\SampleGitRepository";
CopyDirectoryContents(fixtureGitRepositoryRelPath, RepositoryDirectoryInfo.FullName);
Repository = LoadRepository(RepositoryDirectoryInfo.FullName);
}
[Test]
public void Test1()
{
// Get the commits and grab the first one
List<Commit> firstCommits = Repository.Commits.ToList();
Commit firstChangeToFirstCommit = firstCommits.First();
// Rewrite commit. Change commit message.
GitRewriter.RewriteCommit(
repository: Repository,
commit: firstChangeToFirstCommit,
author: firstChangeToFirstCommit.Author,
committer: firstChangeToFirstCommit.Committer,
commitMessage: "first change to commit message"
);
// Not sure if required (I dont think it is)
Repository.Reset(ResetMode.Hard, Repository.Head.Tip);
// Reload Repository thats changed.
// a.k.a return new Repository("the abs path of the repository");
Repository = LoadRepository(RepositoryDirectoryInfo.FullName);
// Get the commits again, and grab the first one like before
List<Commit> secondCommits = Repository.Commits.ToList();
Commit secondChangeToFirstCommit = secondCommits.First();
// Rewrite a second time
GitRewriter.RewriteCommit(
repository: Repository,
commit: secondChangeToFirstCommit,
author: secondChangeToFirstCommit.Author,
committer: secondChangeToFirstCommit.Committer,
commitMessage: "second change to commit message"
);
}
}
I'm aware that when a commit is changed, a new SHA is allocated to that changed commit, and when after I've changed the commit the first time, the SHA does indeed change, but when I attempt to change it the second time, using the changed SHA, I recieve the error as described above.
I've checked the examples of LibGit2 and I could not find anything specific regarding this use-case of changing the same commit twice.
I've tried 'reloading' the repository by created a new Repository but no dice.
Any help, tips or pointers to documentation would be greatly appreciated. Thank you,
Hi Folks, This isn't a bug report but a question I have regarding calling the
RewriteHistory
method on the same commit.If you look at my test case
Test1
, I'm trying to useRewriteHistory
on the same commit, twice.The first rewrite works fine.
On the second attempt, I get the exception:
Can't back up reference 'refs/heads/master' - 'refs/original/heads/master' already exists
I'm aware that when a commit is changed, a new SHA is allocated to that changed commit, and when after I've changed the commit the first time, the SHA does indeed change, but when I attempt to change it the second time, using the changed SHA, I recieve the error as described above.
I've checked the examples of LibGit2 and I could not find anything specific regarding this use-case of changing the same commit twice.
I've tried 'reloading' the repository by created a new
Repository
but no dice.Any help, tips or pointers to documentation would be greatly appreciated. Thank you,