Beispiel #1
0
		/// <exception cref="System.IO.IOException"></exception>
		internal virtual void SetupCase(Dictionary<string, string> headEntries, Dictionary
			<string, string> mergeEntries, Dictionary<string, string> indexEntries)
		{
			theHead = BuildTree(headEntries);
			theMerge = BuildTree(mergeEntries);
			BuildIndex(indexEntries);
		}
 public virtual void TestEmpty()
 {
     Tree tree = new Tree(db);
     TreeIterator i = MakeIterator(tree);
     NUnit.Framework.Assert.IsTrue(i.HasNext());
     NUnit.Framework.Assert.AreEqual(string.Empty, i.Next().GetFullName());
     NUnit.Framework.Assert.IsFalse(i.HasNext());
 }
		/// <exception cref="System.IO.IOException"></exception>
		public virtual void StartVisitTree(Tree t)
		{
			stack.AddItem(currentDirectory);
			if (!t.IsRoot())
			{
				currentDirectory = new FilePath(currentDirectory, t.GetName());
			}
		}
 public virtual void TestSimpleF1()
 {
     Tree tree = new Tree(db);
     tree.AddFile("x");
     TreeIterator i = MakeIterator(tree);
     NUnit.Framework.Assert.IsTrue(i.HasNext());
     NUnit.Framework.Assert.AreEqual("x", i.Next().GetName());
 }
		/// <summary>Construct a walker for the index and one tree.</summary>
		/// <remarks>Construct a walker for the index and one tree.</remarks>
		/// <param name="index"></param>
		/// <param name="tree"></param>
		/// <param name="root"></param>
		/// <param name="visitor"></param>
		public IndexTreeWalker(GitIndex index, Tree tree, FilePath root, IndexTreeVisitor
			 visitor)
		{
			//import org.eclipse.jgit.JGitText;
			this.mainTree = tree;
			this.root = root;
			this.visitor = visitor;
			this.newTree = null;
			threeTrees = false;
			indexMembers = index.GetMembers();
		}
Beispiel #6
0
		/// <exception cref="System.InvalidOperationException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public override void PrescanTwoTrees(Tree head, Tree merge)
		{
			DirCache dc = db.LockDirCache();
			try
			{
				dco = new DirCacheCheckout(db, head.GetId(), dc, merge.GetId());
				dco.PreScanTwoTrees();
			}
			finally
			{
				dc.Unlock();
			}
		}
 public virtual void TestBoth()
 {
     GitIndex index = new GitIndex(db);
     Tree tree = new Tree(db);
     index.Add(trash, WriteTrashFile("a", "a"));
     tree.AddFile("b/b");
     index.Add(trash, WriteTrashFile("c", "c"));
     tree.AddFile("c");
     new IndexTreeWalker(index, tree, trash, new IndexTreeWalkerTest.TestIndexTreeVisitor
         (this)).Walk();
     NUnit.Framework.Assert.IsTrue(indexOnlyEntriesVisited.Contains("a"));
     NUnit.Framework.Assert.IsTrue(treeOnlyEntriesVisited.Contains("b/b"));
     NUnit.Framework.Assert.IsTrue(bothVisited.Contains("c"));
 }
Beispiel #8
0
		public virtual void TestRules1thru3_NoIndexEntry()
		{
			Tree head = new Tree(db);
			head = BuildTree(Mk("foo"));
			ObjectId objectId = head.FindBlobMember("foo").GetId();
			Tree merge = new Tree(db);
			PrescanTwoTrees(head, merge);
			NUnit.Framework.Assert.IsTrue(GetRemoved().Contains("foo"));
			PrescanTwoTrees(merge, head);
			NUnit.Framework.Assert.AreEqual(objectId, GetUpdated().Get("foo"));
			merge = BuildTree(Mkmap("foo", "a"));
			ObjectId anotherId = merge.FindBlobMember("foo").GetId();
			PrescanTwoTrees(head, merge);
			NUnit.Framework.Assert.AreEqual(anotherId, GetUpdated().Get("foo"));
		}
Beispiel #9
0
 public virtual void TestAdded()
 {
     GitIndex index = new GitIndex(db);
     WriteTrashFile("file1", "file1");
     WriteTrashFile("dir/subfile", "dir/subfile");
     Tree tree = new Tree(db);
     tree.SetId(InsertTree(tree));
     index.Add(trash, new FilePath(trash, "file1"));
     index.Add(trash, new FilePath(trash, "dir/subfile"));
     index.Write();
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetAdded().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("file1"));
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("dir/subfile"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
 }
        /// <summary>Adds a new or existing file with the specified name to this tree.</summary>
        /// <remarks>
        /// Adds a new or existing file with the specified name to this tree.
        /// Trees are added if necessary as the name may contain '/':s.
        /// </remarks>
        /// <param name="s">an array containing the name</param>
        /// <param name="offset">when the name starts in the tree.</param>
        /// <returns>
        /// a
        /// <see cref="FileTreeEntry">FileTreeEntry</see>
        /// for the added file.
        /// </returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual FileTreeEntry AddFile(byte[] s, int offset)
        {
            int slash;
            int p;

            for (slash = offset; slash < s.Length && s[slash] != '/'; slash++)
            {
            }
            // search for path component terminator
            EnsureLoaded();
            byte xlast = slash < s.Length ? unchecked ((byte)(byte)('/')) : (byte)0;

            p = BinarySearch(contents, s, xlast, offset, slash);
            if (p >= 0 && slash < s.Length && contents[p] is NGit.Tree)
            {
                return(((NGit.Tree)contents[p]).AddFile(s, slash + 1));
            }
            byte[] newName = Substring(s, offset, slash);
            if (p >= 0)
            {
                throw new EntryExistsException(RawParseUtils.Decode(newName));
            }
            else
            {
                if (slash < s.Length)
                {
                    NGit.Tree t = new NGit.Tree(this, newName);
                    InsertEntry(p, t);
                    return(t.AddFile(s, slash + 1));
                }
                else
                {
                    FileTreeEntry f = new FileTreeEntry(this, null, newName, false);
                    InsertEntry(p, f);
                    return(f);
                }
            }
        }
Beispiel #11
0
 public virtual void TestAdded()
 {
     WriteTrashFile("file1", "file1");
     WriteTrashFile("dir/subfile", "dir/subfile");
     Tree tree = new Tree(db);
     tree.SetId(InsertTree(tree));
     DirCache index = db.LockDirCache();
     DirCacheEditor editor = index.Editor();
     editor.Add(Add(db, trash, "file1"));
     editor.Add(Add(db, trash, "dir/subfile"));
     editor.Commit();
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetAdded().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("file1"));
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("dir/subfile"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
        /// <summary>Adds a new or existing Tree with the specified name to this tree.</summary>
        /// <remarks>
        /// Adds a new or existing Tree with the specified name to this tree.
        /// Trees are added if necessary as the name may contain '/':s.
        /// </remarks>
        /// <param name="s">an array containing the name</param>
        /// <param name="offset">when the name starts in the tree.</param>
        /// <returns>
        /// a
        /// <see cref="FileTreeEntry">FileTreeEntry</see>
        /// for the added tree.
        /// </returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual NGit.Tree AddTree(byte[] s, int offset)
        {
            int slash;
            int p;

            for (slash = offset; slash < s.Length && s[slash] != '/'; slash++)
            {
            }
            // search for path component terminator
            EnsureLoaded();
            p = BinarySearch(contents, s, unchecked ((byte)'/'), offset, slash);
            if (p >= 0 && slash < s.Length && contents[p] is NGit.Tree)
            {
                return(((NGit.Tree)contents[p]).AddTree(s, slash + 1));
            }
            byte[] newName = Substring(s, offset, slash);
            if (p >= 0)
            {
                throw new EntryExistsException(RawParseUtils.Decode(newName));
            }
            NGit.Tree t = new NGit.Tree(this, newName);
            InsertEntry(p, t);
            return(slash == s.Length ? t : t.AddTree(s, slash + 1));
        }
		/// <summary>Create a checkout class for merging and checking our two trees and the index.
		/// 	</summary>
		/// <remarks>Create a checkout class for merging and checking our two trees and the index.
		/// 	</remarks>
		/// <param name="repo"></param>
		/// <param name="root">workdir</param>
		/// <param name="head"></param>
		/// <param name="index"></param>
		/// <param name="merge"></param>
		public WorkDirCheckout(Repository repo, FilePath root, Tree head, GitIndex index, 
			Tree merge) : this(repo, root, index, merge)
		{
			this.head = head;
		}
 public virtual void TestEmpty()
 {
     Tree tree = new Tree(db);
     TreeIterator i = MakeIterator(tree);
     NUnit.Framework.Assert.IsFalse(i.HasNext());
 }
Beispiel #15
0
        /// <summary>Construct and write tree out of index.</summary>
        /// <remarks>Construct and write tree out of index.</remarks>
        /// <returns>SHA-1 of the constructed tree</returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual ObjectId WriteTree()
        {
            CheckWriteOk();
            ObjectInserter inserter = db.NewObjectInserter();

            try
            {
                Tree         current = new Tree(db);
                Stack <Tree> trees   = new Stack <Tree>();
                trees.Push(current);
                string[] prevName = new string[0];
                foreach (GitIndex.Entry e in entries.Values)
                {
                    if (e.GetStage() != 0)
                    {
                        continue;
                    }
                    string[] newName = SplitDirPath(e.GetName());
                    int      c       = LongestCommonPath(prevName, newName);
                    while (c < trees.Count - 1)
                    {
                        current.SetId(inserter.Insert(Constants.OBJ_TREE, current.Format()));
                        trees.Pop();
                        current = trees.IsEmpty() ? null : (Tree)trees.Peek();
                    }
                    while (trees.Count < newName.Length)
                    {
                        if (!current.ExistsTree(newName[trees.Count - 1]))
                        {
                            current = new Tree(current, Constants.Encode(newName[trees.Count - 1]));
                            current.GetParent().AddEntry(current);
                            trees.Push(current);
                        }
                        else
                        {
                            current = (Tree)current.FindTreeMember(newName[trees.Count - 1]);
                            trees.Push(current);
                        }
                    }
                    FileTreeEntry ne = new FileTreeEntry(current, e.sha1, Constants.Encode(newName[newName
                                                                                                   .Length - 1]), (e.mode & FileMode.EXECUTABLE_FILE.GetBits()) == FileMode.EXECUTABLE_FILE
                                                         .GetBits());
                    current.AddEntry(ne);
                }
                while (!trees.IsEmpty())
                {
                    current.SetId(inserter.Insert(Constants.OBJ_TREE, current.Format()));
                    trees.Pop();
                    if (!trees.IsEmpty())
                    {
                        current = trees.Peek();
                    }
                }
                inserter.Flush();
                return(current.GetId());
            }
            finally
            {
                inserter.Release();
            }
        }
Beispiel #16
0
 public virtual void TestIndexOnlySubDirs()
 {
     GitIndex index = new GitIndex(db);
     Tree tree = new Tree(db);
     index.Add(trash, WriteTrashFile("foo/bar/baz", "foobar"));
     index.Add(trash, WriteTrashFile("asdf", "asdf"));
     new IndexTreeWalker(index, tree, trash, new IndexTreeWalkerTest.TestIndexTreeVisitor
         (this)).Walk();
     NUnit.Framework.Assert.AreEqual("asdf", indexOnlyEntriesVisited[0]);
     NUnit.Framework.Assert.AreEqual("foo/bar/baz", indexOnlyEntriesVisited[1]);
 }
 /// <summary>Construct a Tree with a known SHA-1 under another tree.</summary>
 /// <remarks>
 /// Construct a Tree with a known SHA-1 under another tree. Data is not yet
 /// specified and will have to be loaded on demand.
 /// </remarks>
 /// <param name="parent"></param>
 /// <param name="id"></param>
 /// <param name="nameUTF8"></param>
 protected internal Tree(NGit.Tree parent, ObjectId id, byte[] nameUTF8) : base(parent
                                                                                , id, nameUTF8)
 {
     db = parent.GetRepository();
 }
Beispiel #18
0
 /// <exception cref="System.IO.IOException"></exception>
 private ObjectId InsertTree(Tree tree)
 {
     ObjectInserter oi = db.NewObjectInserter();
     try
     {
         ObjectId id = oi.Insert(Constants.OBJ_TREE, tree.Format());
         oi.Flush();
         return id;
     }
     finally
     {
         oi.Release();
     }
 }
Beispiel #19
0
 public virtual void Test023_createCommitNonAnullii()
 {
     ObjectId emptyId = InsertEmptyBlob();
     Tree almostEmptyTree = new Tree(db);
     almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, Sharpen.Runtime.GetBytesForString
         ("empty"), false));
     ObjectId almostEmptyTreeId = InsertTree(almostEmptyTree);
     NGit.CommitBuilder commit = new NGit.CommitBuilder();
     commit.TreeId = almostEmptyTreeId;
     commit.Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L
         , 60);
     commit.Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L
         , 60);
     commit.SetEncoding("UTF-8");
     commit.Message = "\u00dcbergeeks";
     ObjectId cid = InsertCommit(commit);
     NUnit.Framework.Assert.AreEqual("4680908112778718f37e686cbebcc912730b3154", cid.Name
         );
     RevCommit loadedCommit = ParseCommit(cid);
     NUnit.Framework.Assert.AreEqual(commit.Message, loadedCommit.GetFullMessage());
 }
Beispiel #20
0
 public virtual void Test021_createTreeTag()
 {
     ObjectId emptyId = InsertEmptyBlob();
     Tree almostEmptyTree = new Tree(db);
     almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, Sharpen.Runtime.GetBytesForString
         ("empty"), false));
     ObjectId almostEmptyTreeId = InsertTree(almostEmptyTree);
     TagBuilder t = new TagBuilder();
     t.SetObjectId(almostEmptyTreeId, Constants.OBJ_TREE);
     t.SetTag("test021");
     t.SetTagger(new PersonIdent(author, 1154236443000L, -4 * 60));
     t.SetMessage("test021 tagged\n");
     ObjectId actid = InsertTag(t);
     NUnit.Framework.Assert.AreEqual("b0517bc8dbe2096b419d42424cd7030733f4abe5", actid
         .Name);
     RevTag mapTag = ParseTag(actid);
     NUnit.Framework.Assert.AreEqual(Constants.OBJ_TREE, mapTag.GetObject().Type);
     NUnit.Framework.Assert.AreEqual("test021 tagged\n", mapTag.GetFullMessage());
     NUnit.Framework.Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60),
         mapTag.GetTaggerIdent());
     NUnit.Framework.Assert.AreEqual("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag
         .GetObject().Id.Name);
 }
 public virtual void TestSimpleT()
 {
     Tree tree = new Tree(db);
     tree.AddTree("a");
     TreeIterator i = MakeIterator(tree);
     NUnit.Framework.Assert.IsFalse(i.HasNext());
 }
Beispiel #22
0
 public virtual void Test012_SubtreeExternalSorting()
 {
     ObjectId emptyBlob = InsertEmptyBlob();
     Tree t = new Tree(db);
     FileTreeEntry e0 = t.AddFile("a-");
     FileTreeEntry e1 = t.AddFile("a-b");
     FileTreeEntry e2 = t.AddFile("a/b");
     FileTreeEntry e3 = t.AddFile("a=");
     FileTreeEntry e4 = t.AddFile("a=b");
     e0.SetId(emptyBlob);
     e1.SetId(emptyBlob);
     e2.SetId(emptyBlob);
     e3.SetId(emptyBlob);
     e4.SetId(emptyBlob);
     Tree a = (Tree)t.FindTreeMember("a");
     a.SetId(InsertTree(a));
     NUnit.Framework.Assert.AreEqual(ObjectId.FromString("b47a8f0a4190f7572e11212769090523e23eb1ea"
         ), InsertTree(t));
 }
			/// <exception cref="System.IO.IOException"></exception>
			public override void FinishVisitTree(Tree tree, Tree auxTree, string curDir)
			{
				if (curDir.Length == 0)
				{
					return;
				}
				if (auxTree != null)
				{
					if (this._enclosing.index.GetEntry(curDir) != null)
					{
						this._enclosing.removed.AddItem(curDir);
					}
				}
			}
Beispiel #24
0
 public virtual void Test022_createCommitTag()
 {
     ObjectId emptyId = InsertEmptyBlob();
     Tree almostEmptyTree = new Tree(db);
     almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, Sharpen.Runtime.GetBytesForString
         ("empty"), false));
     ObjectId almostEmptyTreeId = InsertTree(almostEmptyTree);
     NGit.CommitBuilder almostEmptyCommit = new NGit.CommitBuilder();
     almostEmptyCommit.Author = new PersonIdent(author, 1154236443000L, -2 * 60);
     // not exactly the same
     almostEmptyCommit.Committer = new PersonIdent(author, 1154236443000L, -2 * 60);
     almostEmptyCommit.Message = "test022\n";
     almostEmptyCommit.TreeId = almostEmptyTreeId;
     ObjectId almostEmptyCommitId = InsertCommit(almostEmptyCommit);
     TagBuilder t = new TagBuilder();
     t.SetObjectId(almostEmptyCommitId, Constants.OBJ_COMMIT);
     t.SetTag("test022");
     t.SetTagger(new PersonIdent(author, 1154236443000L, -4 * 60));
     t.SetMessage("test022 tagged\n");
     ObjectId actid = InsertTag(t);
     NUnit.Framework.Assert.AreEqual("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", actid
         .Name);
     RevTag mapTag = ParseTag(actid);
     NUnit.Framework.Assert.AreEqual(Constants.OBJ_COMMIT, mapTag.GetObject().Type);
     NUnit.Framework.Assert.AreEqual("test022 tagged\n", mapTag.GetFullMessage());
     NUnit.Framework.Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60),
         mapTag.GetTaggerIdent());
     NUnit.Framework.Assert.AreEqual("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag
         .GetObject().Id.Name);
 }
		/// <exception cref="System.IO.IOException"></exception>
		private bool HasParentBlob(Tree t, string name)
		{
			if (name.IndexOf("/") == -1)
			{
				return false;
			}
			string parent = Sharpen.Runtime.Substring(name, 0, name.LastIndexOf("/"));
			if (t.FindBlobMember(parent) != null)
			{
				return true;
			}
			return HasParentBlob(t, parent);
		}
Beispiel #26
0
 public virtual void Test024_createCommitNonAscii()
 {
     ObjectId emptyId = InsertEmptyBlob();
     Tree almostEmptyTree = new Tree(db);
     almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, Sharpen.Runtime.GetBytesForString
         ("empty"), false));
     ObjectId almostEmptyTreeId = InsertTree(almostEmptyTree);
     NGit.CommitBuilder commit = new NGit.CommitBuilder();
     commit.TreeId = almostEmptyTreeId;
     commit.Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L
         , 60);
     commit.Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L
         , 60);
     commit.SetEncoding("ISO-8859-1");
     commit.Message = "\u00dcbergeeks";
     ObjectId cid = InsertCommit(commit);
     NUnit.Framework.Assert.AreEqual("2979b39d385014b33287054b87f77bcb3ecb5ebf", cid.Name
         );
 }
		/// <exception cref="System.IO.IOException"></exception>
		internal WorkDirCheckout(Repository repo, FilePath workDir, GitIndex oldIndex, GitIndex
			 newIndex)
		{
			this.root = workDir;
			this.index = oldIndex;
			this.merge = repo.MapTree(newIndex.WriteTree());
		}
 /// <summary>Construct a new Tree under another Tree</summary>
 /// <param name="parent"></param>
 /// <param name="nameUTF8"></param>
 public Tree(NGit.Tree parent, byte[] nameUTF8) : base(parent, null, nameUTF8)
 {
     db       = parent.GetRepository();
     contents = EMPTY_TREE;
 }
Beispiel #29
0
		/// <summary>Construct a named tree entry.</summary>
		/// <remarks>Construct a named tree entry.</remarks>
		/// <param name="myParent"></param>
		/// <param name="myId"></param>
		/// <param name="myNameUTF8"></param>
		protected internal TreeEntry(Tree myParent, ObjectId myId, byte[] myNameUTF8)
		{
			nameUTF8 = myNameUTF8;
			parent = myParent;
			id = myId;
		}
Beispiel #30
0
		/// <summary>Detach this entry from it's parent.</summary>
		/// <remarks>Detach this entry from it's parent.</remarks>
		public virtual void DetachParent()
		{
			parent = null;
		}
Beispiel #31
0
		internal virtual void AttachParent(Tree p)
		{
			parent = p;
		}
        /// <exception cref="System.IO.IOException"></exception>
        private void ReadTree(byte[] raw)
        {
            int rawSize = raw.Length;
            int rawPtr  = 0;

            TreeEntry[] temp;
            int         nextIndex = 0;

            while (rawPtr < rawSize)
            {
                while (rawPtr < rawSize && raw[rawPtr] != 0)
                {
                    rawPtr++;
                }
                rawPtr++;
                rawPtr += Constants.OBJECT_ID_LENGTH;
                nextIndex++;
            }
            temp      = new TreeEntry[nextIndex];
            rawPtr    = 0;
            nextIndex = 0;
            while (rawPtr < rawSize)
            {
                int c = raw[rawPtr++];
                if (c < '0' || c > '7')
                {
                    throw new CorruptObjectException(GetId(), JGitText.Get().corruptObjectInvalidEntryMode
                                                     );
                }
                int mode = c - '0';
                for (; ;)
                {
                    c = raw[rawPtr++];
                    if (' ' == c)
                    {
                        break;
                    }
                    else
                    {
                        if (c < '0' || c > '7')
                        {
                            throw new CorruptObjectException(GetId(), JGitText.Get().corruptObjectInvalidMode
                                                             );
                        }
                    }
                    mode <<= 3;
                    mode  += c - '0';
                }
                int nameLen = 0;
                while (raw[rawPtr + nameLen] != 0)
                {
                    nameLen++;
                }
                byte[] name = new byte[nameLen];
                System.Array.Copy(raw, rawPtr, name, 0, nameLen);
                rawPtr += nameLen + 1;
                ObjectId id = ObjectId.FromRaw(raw, rawPtr);
                rawPtr += Constants.OBJECT_ID_LENGTH;
                TreeEntry ent;
                if (FileMode.REGULAR_FILE.Equals(mode))
                {
                    ent = new FileTreeEntry(this, id, name, false);
                }
                else
                {
                    if (FileMode.EXECUTABLE_FILE.Equals(mode))
                    {
                        ent = new FileTreeEntry(this, id, name, true);
                    }
                    else
                    {
                        if (FileMode.TREE.Equals(mode))
                        {
                            ent = new NGit.Tree(this, id, name);
                        }
                        else
                        {
                            if (FileMode.SYMLINK.Equals(mode))
                            {
                                ent = new SymlinkTreeEntry(this, id, name);
                            }
                            else
                            {
                                if (FileMode.GITLINK.Equals(mode))
                                {
                                    ent = new GitlinkTreeEntry(this, id, name);
                                }
                                else
                                {
                                    throw new CorruptObjectException(GetId(), MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode2
                                                                                                   , Sharpen.Extensions.ToOctalString(mode)));
                                }
                            }
                        }
                    }
                }
                temp[nextIndex++] = ent;
            }
            contents = temp;
        }
 public virtual void TestTricky()
 {
     Tree tree = new Tree(db);
     tree.AddFile("a.b");
     tree.AddFile("a.c");
     tree.AddFile("a/b.b/b");
     tree.AddFile("a/b");
     tree.AddFile("a/c");
     tree.AddFile("a=c");
     tree.AddFile("a=d");
     TreeIterator i = MakeIterator(tree);
     NUnit.Framework.Assert.IsTrue(i.HasNext());
     NUnit.Framework.Assert.AreEqual("a.b", i.Next().GetFullName());
     NUnit.Framework.Assert.IsTrue(i.HasNext());
     NUnit.Framework.Assert.AreEqual("a.c", i.Next().GetFullName());
     NUnit.Framework.Assert.IsTrue(i.HasNext());
     NUnit.Framework.Assert.AreEqual("a/b", i.Next().GetFullName());
     NUnit.Framework.Assert.IsTrue(i.HasNext());
     NUnit.Framework.Assert.AreEqual("a/b.b/b", i.Next().GetFullName());
     NUnit.Framework.Assert.IsTrue(i.HasNext());
     NUnit.Framework.Assert.AreEqual("a/c", i.Next().GetFullName());
     NUnit.Framework.Assert.IsTrue(i.HasNext());
     NUnit.Framework.Assert.AreEqual("a=c", i.Next().GetFullName());
     NUnit.Framework.Assert.IsTrue(i.HasNext());
     NUnit.Framework.Assert.AreEqual("a=d", i.Next().GetFullName());
     NUnit.Framework.Assert.IsFalse(i.HasNext());
 }
Beispiel #34
0
 /// <exception cref="System.IO.IOException"></exception>
 public override void FinishVisitTree(Tree tree, int i, string curDir)
 {
     if (tree.MemberCount() == 0)
     {
         NUnit.Framework.Assert.Fail();
     }
     if (i == 0)
     {
         NUnit.Framework.Assert.Fail();
     }
 }
 private TreeIterator MakeIterator(Tree tree)
 {
     return new TreeIterator(tree);
 }
Beispiel #36
0
 public virtual void TestIndexOnlyOneLevel()
 {
     GitIndex index = new GitIndex(db);
     Tree tree = new Tree(db);
     index.Add(trash, WriteTrashFile("foo", "foo"));
     index.Add(trash, WriteTrashFile("bar", "bar"));
     new IndexTreeWalker(index, tree, trash, new IndexTreeWalkerTest.TestIndexTreeVisitor
         (this)).Walk();
     NUnit.Framework.Assert.IsTrue(indexOnlyEntriesVisited[0].Equals("bar"));
     NUnit.Framework.Assert.IsTrue(indexOnlyEntriesVisited[1].Equals("foo"));
 }
Beispiel #37
0
 /// <summary>Read a Tree recursively into the index</summary>
 /// <param name="t">The tree to read</param>
 /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 public virtual void ReadTree(Tree t)
 {
     entries.Clear();
     ReadTree(string.Empty, t);
 }