-
Notifications
You must be signed in to change notification settings - Fork 899
Duplicate Filepaths in a commit causes failure when performing Diff between commit tree and its parent #1004
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
Conversation
A commit can't have duplicate file paths. Do you have repro steps? |
Under: https://android.googlesource.com/platform/ndk/ |
Actually, I think I've been able to repro this by tweeking an actual test. diff --git a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
index 99603b6..51fa4e0 100644
--- a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
+++ b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
@@ -911,7 +911,7 @@ public void CanHandleTwoTreeEntryChangesWithTheSamePath()
using (var repo = new Repository(repoPath))
{
- Blob mainContent = OdbHelper.CreateBlob(repo, "awesome content\n");
+ Blob mainContent = OdbHelper.CreateBlob(repo, "awesome content\n" + new string('b', 4096));
Blob linkContent = OdbHelper.CreateBlob(repo, "../../objc/Nu.h");
string path = string.Format("include{0}Nu{0}Nu.h", Path.DirectorySeparatorChar);
@@ -930,7 +930,7 @@ public void CanHandleTwoTreeEntryChangesWithTheSamePath()
var changes = repo.Diff.Compare<TreeChanges>(treeOld, treeNew,
compareOptions: new CompareOptions
{
- Similarity = SimilarityOptions.None,
+ Similarity = SimilarityOptions.Default,
});
/* Applying the patch above generates the following
|
@SinghVarun Can you please confirm the use case and the call stack? |
FWIW, this test (ported from #201) passes [Fact]
public void CanHandleTwoStatusEntryChangesWithTheSamePath()
{
var path = InitNewRepository();
using (Repository repo = new Repository(path))
{
Blob mainContent = OdbHelper.CreateBlob(repo, "awesome content\n");
Blob linkContent = OdbHelper.CreateBlob(repo, "../../objc/Nu.h");
const string filePath = "include/Nu/Nu.h";
var tdOld = new TreeDefinition()
.Add(filePath, linkContent, Mode.SymbolicLink)
.Add("objc/Nu.h", mainContent, Mode.NonExecutableFile);
Tree tree = repo.ObjectDatabase.CreateTree(tdOld);
Commit commit = repo.ObjectDatabase.CreateCommit(Constants.Signature, Constants.Signature, "A symlink", tree, Enumerable.Empty<Commit>(), false);
repo.Refs.UpdateTarget("HEAD", commit.Id.Sha);
repo.Reset(ResetMode.Mixed);
string parentPath = Path.Combine(repo.Info.WorkingDirectory, "include/Nu");
Touch(parentPath, "Nu.h", "awesome content\n");
RepositoryStatus status = repo.RetrieveStatus();
Assert.Equal(2, status.Count());
Assert.Equal(Path.Combine("include", "Nu", "Nu.h"), status.Modified.Single().FilePath);
Assert.Equal(Path.Combine("objc", "Nu.h"), status.Missing.Single().FilePath);
}
} |
In order to move forward on this topic, I've added the hopefully failing tests. Let's see how the CI servers think of them. |
CanHandleTwoTreeEntryChangesWithTheSamePath(SimilarityOptions.Default, | ||
(path, changes) => | ||
{ | ||
// TODO: What should we assert there? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ethomson What should we assert there?
d36e843
to
3b9e919
Compare
3b9e919
to
1a26946
Compare
@SinghVarun @ethomson I've pushed a proposal. A breaking one. Thoughts? |
1a26946
to
a032ac2
Compare
{ | ||
// $ git diff-tree --name-status --find-renames -r 2ccccf8 e829333 | ||
// T include/Nu/Nu.h | ||
// D objc/Nu.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
if (IsRunningOnUnix()) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not. Which one is the expected output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno. They both seem to be valid but expressed in different ways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to move this test its strange output to a different PR in order keep this one scoped.
6a462c0
to
205a221
Compare
@SinghVarun Any feedback? |
@nulltoken Sorry for delay in response. Was testing this fix on multiple repository. Things look great. |
205a221
to
2e3b534
Compare
Published as pre-release NuGet package |
Duplicate FilePaths in a commit causes failure when trying to perform Diff between commit tree and its parent
This happens in TreeChanges.cs class in AddChanges method, as Dictionary prevents addition of same key.