Skip to content

Commit

Permalink
Add tests for TreeDefinition with non-filesystem paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Bellot authored and carlosmn committed Apr 27, 2016
1 parent 1fb7fc5 commit 78500f6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
46 changes: 45 additions & 1 deletion LibGit2Sharp.Tests/TreeDefinitionFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ public void CanAddAnExistingGitLinkTreeEntryDefinition()
}
}

private const string StringOf40Chars = "0123456789012345678901234567890123456789";

/// <summary>
/// Used to verify that windows path limitation to 260 chars is not limiting the size of
/// the keys present in the object database.
/// </summary>
private const string StringOf600Chars =
StringOf40Chars + StringOf40Chars + StringOf40Chars + StringOf40Chars + StringOf40Chars
+ StringOf40Chars + StringOf40Chars + StringOf40Chars + StringOf40Chars + StringOf40Chars
+ StringOf40Chars + StringOf40Chars + StringOf40Chars + StringOf40Chars + StringOf40Chars;

[Theory]
[InlineData("README", "README_TOO")]
[InlineData("README", "1/README")]
Expand All @@ -152,7 +163,10 @@ public void CanAddAnExistingGitLinkTreeEntryDefinition()
[InlineData("1/branch_file.txt", "1/2/3/another_one.txt")]
[InlineData("1", "2")]
[InlineData("1", "2/3")]
public void CanAddAnExistingTreeEntry(string sourcePath, string targetPath)
[InlineData("1", "C:\\/10")]
[InlineData("1", " : * ? \" < > |")]
[InlineData("1", StringOf600Chars)]
public void CanAddAndRemoveAnExistingTreeEntry(string sourcePath, string targetPath)
{
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
Expand All @@ -168,6 +182,36 @@ public void CanAddAnExistingTreeEntry(string sourcePath, string targetPath)
Assert.NotNull(fetched);

Assert.Equal(te.Target.Id, fetched.TargetId);

// Ensuring that the object database can handle uncommon paths.
var newTree = repo.ObjectDatabase.CreateTree(td);
Assert.Equal(newTree[targetPath].Target.Id, te.Target.Id);

td.Remove(targetPath);
Assert.Null(td[targetPath]);
}
}

[Theory]
[InlineData("C:\\")]
[InlineData(" : * ? \" \n < > |")]
[InlineData("a\\b")]
[InlineData("\\\\b\a")]
[InlineData("éàµ")]
[InlineData(StringOf600Chars)]
public void TreeNamesCanContainCharsForbiddenOnSomeOS(string targetName)
{
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
var pointedItem = repo.Head.Tip.Tree;

var td = new TreeDefinition();
td.Add(targetName, pointedItem);

var newTree = repo.ObjectDatabase.CreateTree(td);
Assert.Equal(newTree[targetName].Target.Sha, pointedItem.Sha);
Assert.Equal(newTree[targetName].Name, targetName);
}
}

Expand Down
14 changes: 13 additions & 1 deletion LibGit2Sharp.Tests/TreeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ public void TreeDataIsPresent()
}
}

[Fact]
public void TreeUsesPosixStylePaths()
{
using (var repo = new Repository(BareTestRepoPath))
{
/* From a commit tree */
var commitTree = repo.Lookup<Commit>("4c062a6").Tree;
Assert.NotNull(commitTree["1/branch_file.txt"]);
Assert.Null(commitTree["1\\branch_file.txt"]);
}
}

[Fact]
public void CanRetrieveTreeEntryPath()
{
Expand All @@ -180,7 +192,7 @@ public void CanRetrieveTreeEntryPath()
TreeEntry treeTreeEntry = commitTree["1"];
Assert.Equal("1", treeTreeEntry.Path);

string completePath = Path.Combine("1", "branch_file.txt");
string completePath = "1/branch_file.txt";

TreeEntry blobTreeEntry = commitTree["1/branch_file.txt"];
Assert.Equal(completePath, blobTreeEntry.Path);
Expand Down

0 comments on commit 78500f6

Please sign in to comment.