本文整理汇总了C#中GitSharp.Core.Tree.AddTree方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.AddTree方法的具体用法?C# Tree.AddTree怎么用?C# Tree.AddTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GitSharp.Core.Tree
的用法示例。
在下文中一共展示了Tree.AddTree方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testTwoSuccessiveCommitsLinkedToHead
public void testTwoSuccessiveCommitsLinkedToHead()
{
var repo = createNewEmptyRepo();
var workingDirectory = repo.WorkingDirectory;
repo.Create();
var objectWriter = new ObjectWriter(repo);
FileInfo project1_a_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/A.txt"), "A.txt - first version\n");
FileInfo project1_b_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/B.txt"), "B.txt - first version\n");
var tree = new Tree(repo);
Tree projectTree = tree.AddTree("Project-1");
addFile(projectTree, project1_a_txt, objectWriter);
projectTree.Id = (objectWriter.WriteTree(projectTree));
addFile(projectTree, project1_b_txt, objectWriter);
projectTree.Id = (objectWriter.WriteTree(projectTree));
tree.Id = (objectWriter.WriteTree(tree));
var commit = new Commit(repo)
{
Author = new PersonIdent(jauthor, (0L), 60),
Committer = new PersonIdent(jcommitter, (0L), 60),
Message = "Foo\n\nMessage",
TreeEntry = tree
};
commit.Save();
var commitId = commit.CommitId;
FileInfo project1_b_v2_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/B.txt"), "B.txt - second version\n");
tree = new Tree(repo);
projectTree = tree.AddTree("Project-1");
addFile(projectTree, project1_a_txt, objectWriter);
projectTree.Id = (objectWriter.WriteTree(projectTree));
addFile(projectTree, project1_b_v2_txt, objectWriter);
projectTree.Id = (objectWriter.WriteTree(projectTree));
tree.Id = (objectWriter.WriteTree(tree));
commit = new Commit(repo)
{
Author = new PersonIdent(jauthor, (0L), 60),
Committer = new PersonIdent(jcommitter, (0L), 60),
Message = "Modified",
ParentIds = new[] { commitId },
TreeEntry = tree
};
commit.Save();
commitId = commit.CommitId;
RefUpdate lck = repo.UpdateRef("refs/heads/master");
Assert.IsNotNull(lck, "obtained lock");
lck.NewObjectId = commitId;
Assert.AreEqual(RefUpdate.RefUpdateResult.New, lck.ForceUpdate());
}
示例2: AddTree
/// <summary>
/// Adds a new or existing Tree with the specified name to this tree.
/// Trees are added if necessary as the name may contain '/':s.
/// </summary>
/// <param name="s"> an array containing the name </param>
/// <param name="offset"> when the name starts in the tree.</param>
/// <returns>A <seealso cref="FileTreeEntry"/> for the added tree.</returns>
/// <exception cref="IOException"></exception>
public Tree AddTree(byte[] s, int offset)
{
int slash;
for (slash = offset; slash < s.Length && s[slash] != '/'; slash++)
{
// search for path component terminator
}
EnsureLoaded();
int p = BinarySearch(_contents, s, (byte)'/', offset, slash);
if (p >= 0 && slash < s.Length && _contents[p] is Tree)
{
return ((Tree)_contents[p]).AddTree(s, slash + 1);
}
byte[] newName = SubString(s, offset, slash);
if (p >= 0)
{
throw new EntryExistsException(RawParseUtils.decode(newName));
}
Tree t = new Tree(this, newName);
InsertEntry(p, t);
return slash == s.Length ? t : t.AddTree(s, slash + 1);
}
示例3: test006_addDeepTree
public void test006_addDeepTree()
{
var t = new Tree(db);
Tree e = t.AddTree("e");
Assert.IsNotNull(e);
Assert.IsTrue(e.Parent == t);
Tree f = t.AddTree("f");
Assert.IsNotNull(f);
Assert.IsTrue(f.Parent == t);
Tree g = f.AddTree("g");
Assert.IsNotNull(g);
Assert.IsTrue(g.Parent == f);
Tree h = g.AddTree("h");
Assert.IsNotNull(h);
Assert.IsTrue(h.Parent == g);
h.Id = SomeFakeId;
Assert.IsTrue(!h.IsModified);
g.Id = SomeFakeId;
Assert.IsTrue(!g.IsModified);
f.Id = SomeFakeId;
Assert.IsTrue(!f.IsModified);
e.Id = SomeFakeId;
Assert.IsTrue(!e.IsModified);
t.Id = SomeFakeId;
Assert.IsTrue(!t.IsModified);
Assert.AreEqual("f/g/h", h.FullName);
Assert.IsTrue(t.findTreeMember(h.FullName) == h);
Assert.IsTrue(t.FindBlobMember("f/z") == null);
Assert.IsTrue(t.FindBlobMember("y/z") == null);
FileTreeEntry i = h.AddFile("i");
Assert.IsNotNull(i);
Assert.AreEqual("f/g/h/i", i.FullName);
Assert.IsTrue(t.FindBlobMember(i.FullName) == i);
Assert.IsTrue(h.IsModified);
Assert.IsTrue(g.IsModified);
Assert.IsTrue(f.IsModified);
Assert.IsTrue(!e.IsModified);
Assert.IsTrue(t.IsModified);
Assert.IsTrue(h.Id == null);
Assert.IsTrue(g.Id == null);
Assert.IsTrue(f.Id == null);
Assert.IsTrue(e.Id != null);
Assert.IsTrue(t.Id == null);
}
示例4: test008_SubtreeInternalSorting
public void test008_SubtreeInternalSorting()
{
var t = new Tree(db);
FileTreeEntry e0 = t.AddFile("a-b");
FileTreeEntry e1 = t.AddFile("a-");
FileTreeEntry e2 = t.AddFile("a=b");
Tree e3 = t.AddTree("a");
FileTreeEntry e4 = t.AddFile("a=");
TreeEntry[] ents = t.Members;
Assert.AreSame(e1, ents[0]);
Assert.AreSame(e0, ents[1]);
Assert.AreSame(e3, ents[2]);
Assert.AreSame(e4, ents[3]);
Assert.AreSame(e2, ents[4]);
}
示例5: test005_addRecursiveTree
public void test005_addRecursiveTree()
{
var t = new Tree(db);
Tree f = t.AddTree("a/b/c");
Assert.IsNotNull(f);
Assert.AreEqual(f.Name, "c");
Assert.AreEqual(f.Parent.Name, "b");
Assert.AreEqual(f.Parent.Parent.Name, "a");
Assert.IsTrue(t == f.Parent.Parent.Parent, "t is great-grandparent");
}
示例6: test004_addTree
public void test004_addTree()
{
var t = new Tree(db) {Id = SomeFakeId};
Assert.IsTrue(t.Id != null);
Assert.IsFalse(t.IsModified);
const string n = "bob";
Tree f = t.AddTree(n);
Assert.IsNotNull(f);
Assert.AreEqual(n, f.Name);
Assert.AreEqual(f.Name, Constants.CHARSET.GetString(f.NameUTF8));
Assert.AreEqual(n, f.FullName);
Assert.IsTrue(f.Id == null);
Assert.IsTrue(f.Parent == t);
Assert.IsTrue(f.Repository == db);
Assert.IsTrue(f.IsLoaded);
Assert.IsFalse(f.Members.Length > 0);
Assert.IsFalse(f.IsRoot);
Assert.IsTrue(f.TreeEntry == f);
Assert.IsTrue(t.IsModified);
Assert.IsTrue(t.Id == null);
Assert.IsTrue(t.findTreeMember(f.Name) == f);
TreeEntry[] i = t.Members;
Assert.IsTrue(i.Length > 0);
Assert.IsTrue(i[0] == f);
Assert.IsTrue(i.Length == 1);
}
示例7: testSimpleT
public void testSimpleT()
{
Tree tree = new Tree(db);
tree.AddTree("a");
TreeIterator i = MakeIterator(tree);
Assert.IsFalse(i.hasNext());
}
示例8: testSimpleT
public void testSimpleT()
{
Tree tree = new Tree(db);
tree.AddTree("a");
TreeIterator i = makeIterator(tree);
Assert.IsTrue(i.hasNext());
Assert.AreEqual("a", i.next().FullName);
Assert.IsTrue(i.hasNext());
Assert.AreEqual("", i.next().FullName);
Assert.IsFalse(i.hasNext());
}
示例9: testMissingSubtree_DetectFileAdded_FileModified
public void testMissingSubtree_DetectFileAdded_FileModified()
{
var ow = new ObjectWriter(db);
ObjectId aFileId = ow.WriteBlob(Constants.CHARSET.GetBytes("a"));
ObjectId bFileId = ow.WriteBlob(Constants.CHARSET.GetBytes("b"));
ObjectId cFileId1 = ow.WriteBlob(Constants.CHARSET.GetBytes("c-1"));
ObjectId cFileId2 = ow.WriteBlob(Constants.CHARSET.GetBytes("c-2"));
// Create sub-a/empty, sub-c/empty = hello.
Func<ObjectId> oldTree = () =>
{
var root = new Tree(db);
Tree subA = root.AddTree("sub-a");
subA.AddFile("empty").Id = aFileId;
subA.Id = ow.WriteTree(subA);
Tree subC = root.AddTree("sub-c");
subC.AddFile("empty").Id = cFileId1;
subC.Id = ow.WriteTree(subC);
return ow.WriteTree(root);
};
// Create sub-a/empty, sub-b/empty, sub-c/empty.
Func<ObjectId> newTree = () =>
{
var root = new Tree(db);
Tree subA = root.AddTree("sub-a");
subA.AddFile("empty").Id = aFileId;
subA.Id = ow.WriteTree(subA);
Tree subB = root.AddTree("sub-b");
subB.AddFile("empty").Id = bFileId;
subB.Id = ow.WriteTree(subB);
Tree subC = root.AddTree("sub-c");
subC.AddFile("empty").Id = cFileId2;
subC.Id = ow.WriteTree(subC);
return ow.WriteTree(root);
};
var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);
tw.reset(new[] { oldTree.Invoke(), newTree.Invoke() });
tw.Recursive = true;
tw.setFilter(TreeFilter.ANY_DIFF);
Assert.IsTrue(tw.next());
Assert.AreEqual("sub-b/empty", tw.getPathString());
Assert.AreEqual(FileMode.Missing, tw.getFileMode(0));
Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(1));
Assert.AreEqual(ObjectId.ZeroId, tw.getObjectId(0));
Assert.AreEqual(bFileId, tw.getObjectId(1));
Assert.IsTrue(tw.next());
Assert.AreEqual("sub-c/empty", tw.getPathString());
Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(0));
Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(1));
Assert.AreEqual(cFileId1, tw.getObjectId(0));
Assert.AreEqual(cFileId2, tw.getObjectId(1));
Assert.IsFalse(tw.next());
}