public void testNonRecursiveFiltering()
        {
            var ow = new ObjectWriter(db);
            ObjectId aSth = ow.WriteBlob("a.sth".getBytes());
            ObjectId aTxt = ow.WriteBlob("a.txt".getBytes());
            DirCache dc = DirCache.read(db);
            DirCacheBuilder builder = dc.builder();
            var aSthEntry = new DirCacheEntry("a.sth");
            aSthEntry.setFileMode(FileMode.RegularFile);
            aSthEntry.setObjectId(aSth);
            var aTxtEntry = new DirCacheEntry("a.txt");
            aTxtEntry.setFileMode(FileMode.RegularFile);
            aTxtEntry.setObjectId(aTxt);
            builder.add(aSthEntry);
            builder.add(aTxtEntry);
            builder.finish();
            ObjectId treeId = dc.writeTree(ow);


            var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);
            tw.setFilter(PathSuffixFilter.create(".txt"));
            tw.addTree(treeId);

            var paths = new LinkedList<string>();
            while (tw.next())
            {
                paths.AddLast(tw.getPathString());
            }

            var expected = new LinkedList<string>();
            expected.AddLast("a.txt");

            Assert.AreEqual(expected, paths);
        }
Example #2
0
		///	<summary>
		/// Persist this commit object
		/// </summary>
		/// <exception cref="IOException"></exception>
		public void Save() // [henon] was Commit() in java, but c# won't allow it
		{
			if (CommitId != null)
			{
				throw new InvalidOperationException("exists " + CommitId);
			}

			CommitId = new ObjectWriter(Repository).WriteCommit(this);
		}
Example #3
0
 public string HashAndInsertObject(string filename)
 {
     var writer = new ObjectWriter(_repository);
     var objectId = writer.WriteBlob(new FileInfo(filename));
     return objectId.ToString();
 }
        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 Core.Tree(db);

                                            Core.Tree subA = root.AddTree("sub-a");
                                     		subA.AddFile("empty").Id = aFileId;
                                     		subA.Id = ow.WriteTree(subA);

                                            Core.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 Core.Tree(db);

                                            Core.Tree subA = root.AddTree("sub-a");
                                     		subA.AddFile("empty").Id = aFileId;
                                     		subA.Id = ow.WriteTree(subA);

                                            Core.Tree subB = root.AddTree("sub-b");
                                     		subB.AddFile("empty").Id = bFileId;
                                     		subB.Id = ow.WriteTree(subB);

                                            Core.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());
        }
Example #5
0
 public void test025_computeSha1NoStore()
 {
     byte[] data = "test025 some data, more than 16 bytes to get good coverage".getBytes("ISO-8859-1");
     ObjectId id = new ObjectWriter(db).ComputeBlobSha1(data.Length, new MemoryStream(data));
     Assert.AreEqual("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.Name);
 }
Example #6
0
        public void Write_Blob()
        {
            ObjectId id = new ObjectWriter(db).WriteBlob(new FileInfo("Resources/single_file_commit/i-am-a-file"));
            Assert.AreEqual("95ea6a6859af6791464bd8b6de76ad5a6f9fad81", id.ToString());
            Assert.AreEqual(Inspector.Inspect("Resources/single_file_commit", "95ea6a6859af6791464bd8b6de76ad5a6f9fad81"), new Inspector(db).Inspect(id));

            writeTrashFile("i-am-a-file", "and this is the data in me\r\n\r\n");
            id = new ObjectWriter(db).WriteBlob(new FileInfo(trash+"/i-am-a-file"));
            Assert.AreEqual("95ea6a6859af6791464bd8b6de76ad5a6f9fad81", id.ToString());
        }
Example #7
0
 private ObjectId GenSha1(string data)
 {
     var input = new MemoryStream(data.getBytes());
     var writer = new ObjectWriter(db);
     try
     {
         return writer.WriteObject(ObjectType.Blob, data.getBytes().Length, input, true);
     }
     catch (IOException exception)
     {
         Assert.Fail(exception.ToString());
     }
     return null;
 }
Example #8
0
        public void test023_createCommitNonAnullii()
        {
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            var almostEmptyTree = new Tree(db);
            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
            ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);

            var commit = new Commit(db)
                         	{
                         		TreeId = almostEmptyTreeId,
                         		Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L, 60),
                         		Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L, 60),
                                Encoding = Constants.CHARSET,
                         		Message = "\u00dcbergeeks"
                         	};

            ObjectId cid = new ObjectWriter(db).WriteCommit(commit);
            Assert.AreEqual("4680908112778718f37e686cbebcc912730b3154", cid.Name);
        }
Example #9
0
        private RevObject WriteBlob(Core.Repository repo, string data)
        {
            var revWalk = new GitSharp.Core.RevWalk.RevWalk(repo);
            byte[] bytes = Constants.encode(data);
            var ow = new ObjectWriter(repo);
            ObjectId id = ow.WriteBlob(bytes);
            try
            {
                Parse(id);
                Assert.Fail("Object " + id.Name + " should not exist in test repository");
            }
            catch (MissingObjectException)
            {
                // Ok
            }

            return revWalk.lookupBlob(id);
        }
Example #10
0
        // [henon] was Commit() in java, but c# won't allow it
        ///	<summary>
        /// Persist this commit object
        /// </summary>
        /// <exception cref="IOException"></exception>
        public void Save()
        {
            if (CommitId != null)
            {
                throw new InvalidOperationException("exists " + CommitId);
            }

            CommitId = new ObjectWriter(Repository).WriteCommit(this);
        }
Example #11
0
		public void TestPick()
		{
			// B---O
			// \----P---T
			//
			// Cherry-pick "T" onto "O". This shouldn't introduce "p-fail", which
			// was created by "P", nor should it modify "a", which was done by "P".
			//
			DirCache treeB = DirCache.read(db);
			DirCache treeO = DirCache.read(db);
			DirCache treeP = DirCache.read(db);
			DirCache treeT = DirCache.read(db);
			{
				DirCacheBuilder b = treeB.builder();
				DirCacheBuilder o = treeO.builder();
				DirCacheBuilder p = treeP.builder();
				DirCacheBuilder t = treeT.builder();

				b.add(MakeEntry("a", FileMode.RegularFile));

				o.add(MakeEntry("a", FileMode.RegularFile));
				o.add(MakeEntry("o", FileMode.RegularFile));

				p.add(MakeEntry("a", FileMode.RegularFile, "q"));
				p.add(MakeEntry("p-fail", FileMode.RegularFile));

				t.add(MakeEntry("a", FileMode.RegularFile));
				t.add(MakeEntry("t", FileMode.RegularFile));

				b.finish();
				o.finish();
				p.finish();
				t.finish();
			}

			var ow = new ObjectWriter(db);
			ObjectId B = Commit(ow, treeB, new ObjectId[] { });
			ObjectId O = Commit(ow, treeO, new[] { B });
			ObjectId P = Commit(ow, treeP, new[] { B });
			ObjectId T = Commit(ow, treeT, new[] { P });

			var twm = (ThreeWayMerger)MergeStrategy.SimpleTwoWayInCore.NewMerger(db);
			twm.SetBase(P);
			bool merge = twm.Merge(new[] { O, T });
			Assert.IsTrue(merge);

			var tw = new GitSharp.Core.TreeWalk.TreeWalk(db) { Recursive = true };
			tw.reset(twm.GetResultTreeId());

			Assert.IsTrue(tw.next());
			Assert.AreEqual("a", tw.getPathString());
			AssertCorrectId(treeO, tw);

			Assert.IsTrue(tw.next());
			Assert.AreEqual("o", tw.getPathString());
			AssertCorrectId(treeO, tw);

			Assert.IsTrue(tw.next());
			Assert.AreEqual("t", tw.getPathString());
			AssertCorrectId(treeT, tw);

			Assert.IsFalse(tw.next());
		}
Example #12
0
 ///	<summary>
 /// Construct a WriteTree for a given directory
 ///	</summary>
 ///	<param name="sourceDirectory"> </param>
 ///	<param name="db"> </param>
 public WriteTree(DirectoryInfo sourceDirectory, Repository db)
     : base(sourceDirectory)
 {
     ow = new ObjectWriter(db);
 }
Example #13
0
        //renamed from Tag
        /**
         * Store a tag.
         * If author, message or type is set make the tag an annotated tag.
         *
         * @
         */
        public void Save()
        {
            if (TagId != null)
                throw new InvalidOperationException("exists " + TagId);
            ObjectId id;

            if (author != null || message != null || tagType != null)
            {
                ObjectId tagid = new ObjectWriter(Repository).WriteTag(this);
                TagId = tagid;
                id = tagid;
            }
            else
            {
                id = Id;
            }

            RefUpdate ru = Repository.UpdateRef(Constants.R_TAGS + TagName);
            ru.NewObjectId = id;
            ru.setRefLogMessage("tagged " + TagName, false);
            if (ru.forceUpdate() == RefUpdate.RefUpdateResult.LOCK_FAILURE)
                throw new ObjectWritingException("Unable to lock tag " + TagName);
        }
Example #14
0
        public void test021_createTreeTag()
        {
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            var almostEmptyTree = new Tree(db);
            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
            ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);

            var t = new Tag(db)
                        {
                            Id = almostEmptyTreeId,
                            TagType = "tree",
                            TagName = "test021",
                            Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                            Message = "test021 tagged\n"
                        };

            t.Save();
            Assert.AreEqual("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.TagId.Name);

            Tag MapTag = db.MapTag("test021");
            Assert.AreEqual("tree", MapTag.TagType);
            Assert.AreEqual("test021 tagged\n", MapTag.Message);
            Assert.AreEqual(new PersonIdent(jauthor, 1154236443000L, -4 * 60), MapTag.Author);
            Assert.AreEqual("417c01c8795a35b8e835113a85a5c0c1c77f67fb", MapTag.Id.Name);
        }
Example #15
0
 private static string HashWithGitSharp(Stream file)
 {
     var repository = new Repository(new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, ".git")));
     var writer = new ObjectWriter(repository);
     return writer.WriteBlob(file.Length, file).ToString();
 }
Example #16
0
        public void test022_createCommitTag()
        {
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            var almostEmptyTree = new Tree(db);
            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
            ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);

            var almostEmptyCommit = new Commit(db)
                                        {
                                            Author = new PersonIdent(jauthor, 1154236443000L, -2*60),
                                            Committer = new PersonIdent(jauthor, 1154236443000L, -2*60),
                                            Message = "test022\n",
                                            TreeId = almostEmptyTreeId
                                        };

            ObjectId almostEmptyCommitId = new ObjectWriter(db).WriteCommit(almostEmptyCommit);

            var t = new Tag(db)
                        {
                            Id = almostEmptyCommitId,
                            TagType = "commit",
                            TagName = "test022",
                            Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                            Message = "test022 tagged\n"
                        };

            t.Save();
            Assert.AreEqual("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", t.TagId.Name);

            Tag mapTag = db.MapTag("test022");
            Assert.AreEqual("commit", mapTag.TagType);
            Assert.AreEqual("test022 tagged\n", mapTag.Message);
            Assert.AreEqual(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.Author);
            Assert.AreEqual("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.Id.Name);
        }
Example #17
0
        public void testTrivialTwoWay_rightDFconflict2()
        {
            DirCache treeB = DirCache.read(db);
            DirCache treeO = DirCache.read(db);
            DirCache treeT = DirCache.read(db);
            {
                DirCacheBuilder b = treeB.builder();
                DirCacheBuilder o = treeO.builder();
                DirCacheBuilder t = treeT.builder();

                b.add(MakeEntry("d", FileMode.RegularFile));

                o.add(MakeEntry("d/o", FileMode.RegularFile));

                t.add(MakeEntry("d", FileMode.RegularFile, "t !"));

                b.finish();
                o.finish();
                t.finish();
            }

            var ow = new ObjectWriter(db);
            ObjectId B = Commit(ow, treeB, new ObjectId[] { });
            ObjectId O = Commit(ow, treeO, new[] { B });
            ObjectId T = Commit(ow, treeT, new[] { B });

            Merger ourMerger = MergeStrategy.SimpleTwoWayInCore.NewMerger(db);
            bool merge = ourMerger.Merge(new[] { O, T });
            Assert.IsFalse(merge);
        }
Example #18
0
 public void test024_createCommitNonAscii()
 {
     ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
     var almostEmptyTree = new Tree(db);
     almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
     ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);
     var commit = new Commit(db)
                  	{
                  		TreeId = almostEmptyTreeId,
                  		Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L, 60),
                  		Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L, 60),
                  		Encoding = Encoding.GetEncoding("ISO-8859-1"),
                  		Message = "\u00dcbergeeks"
                  	};
     ObjectId cid = new ObjectWriter(db).WriteCommit(commit);
     var s = new Inspector(db).Inspect(cid);
     Assert.AreEqual("2979b39d385014b33287054b87f77bcb3ecb5ebf", cid.ToString());
 }
Example #19
0
 private ObjectId Commit(ObjectWriter ow, DirCache treeB, ObjectId[] parentIds)
 {
     var c = new Commit(db) { TreeId = treeB.writeTree(ow), Author = new PersonIdent("A U Thor", "a.u.thor", 1L, 0) };
     c.Committer = c.Author;
     c.ParentIds = parentIds;
     c.Message = "Tree " + c.TreeId.Name;
     return ow.WriteCommit(c);
 }
Example #20
0
        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());
        }
Example #21
0
        public void testTrivialTwoWay_concurrentSubtreeChange()
        {
            DirCache treeB = DirCache.read(db);
            DirCache treeO = DirCache.read(db);
            DirCache treeT = DirCache.read(db);
            {
                DirCacheBuilder b = treeB.builder();
                DirCacheBuilder o = treeO.builder();
                DirCacheBuilder t = treeT.builder();

                b.add(MakeEntry("d/o", FileMode.RegularFile));
                b.add(MakeEntry("d/t", FileMode.RegularFile));

                o.add(MakeEntry("d/o", FileMode.RegularFile, "o !"));
                o.add(MakeEntry("d/t", FileMode.RegularFile));

                t.add(MakeEntry("d/o", FileMode.RegularFile));
                t.add(MakeEntry("d/t", FileMode.RegularFile, "t !"));

                b.finish();
                o.finish();
                t.finish();
            }

            var ow = new ObjectWriter(db);
            ObjectId B = Commit(ow, treeB, new ObjectId[] { });
            ObjectId O = Commit(ow, treeO, new[] { B });
            ObjectId T = Commit(ow, treeT, new[] { B });

            Merger ourMerger = MergeStrategy.SimpleTwoWayInCore.NewMerger(db);
            bool merge = ourMerger.Merge(new[] { O, T });
            Assert.IsTrue(merge);

            var tw = new GitSharp.Core.TreeWalk.TreeWalk(db) { Recursive = true };
            tw.reset(ourMerger.GetResultTreeId());

            Assert.IsTrue(tw.next());
            Assert.AreEqual("d/o", tw.getPathString());
            AssertCorrectId(treeO, tw);

            Assert.IsTrue(tw.next());
            Assert.AreEqual("d/t", tw.getPathString());
            AssertCorrectId(treeT, tw);

            Assert.IsFalse(tw.next());
        }
Example #22
0
 private void addFile(Tree t, FileInfo f, ObjectWriter objectWriter)
 {
     ObjectId id = objectWriter.WriteBlob(f);
     t.AddEntry(new FileTreeEntry(t, id, f.Name.getBytes("UTF-8"), false));
 }
Example #23
0
        public void test003_WriteShouldBeEmptyTree()
        {
            Tree t = new Tree(db);
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            t.AddFile("should-be-empty").Id = emptyId;
            t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
            Assert.AreEqual("7bb943559a305bdd6bdee2cef6e5df2413c3d30a", t.Id.Name);

            var o = new FileInfo(trash_git + "/objects/7b/b943559a305bdd6bdee2cef6e5df2413c3d30a");
            Assert.IsTrue(o.IsFile(), "Exists " + o);
            Assert.IsTrue(o.IsReadOnly, "Read-only " + o);

            o = new FileInfo(trash_git + "/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391");
            Assert.IsTrue(o.IsFile(), "Exists " + o);
            Assert.IsTrue(o.IsReadOnly, "Read-only " + o);
        }
Example #24
0
 public string HashAndInsertObject(Stream file, long length)
 {
     var writer = new ObjectWriter(_repository);
     var objectId = writer.WriteBlob(length, file);
     return objectId.Name;
 }
Example #25
0
        public void test012_SubtreeExternalSorting()
        {
            ObjectId emptyBlob = new ObjectWriter(db).WriteBlob(new byte[0]);
            var 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.Id = emptyBlob;
            e1.Id = emptyBlob;
            e2.Id = emptyBlob;
            e3.Id = emptyBlob;
            e4.Id = emptyBlob;

            t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
            Assert.AreEqual(ObjectId.FromString("b47a8f0a4190f7572e11212769090523e23eb1ea"), t.Id);
        }
Example #26
0
        public void testEmptyTreeCorruption()
        {
            ObjectId bId = ObjectId.FromString("abbbfafe3129f85747aba7bfac992af77134c607");
            RevTree tree_root, tree_A, tree_AB;
            RevCommit b;
            {
                global::GitSharp.Core.Tree root = new global::GitSharp.Core.Tree(db);
                global::GitSharp.Core.Tree A = root.AddTree("A");
                FileTreeEntry B = root.AddFile("B");
                B.Id = (bId);

                global::GitSharp.Core.Tree A_A = A.AddTree("A");
                global::GitSharp.Core.Tree A_B = A.AddTree("B");

                var ow = new ObjectWriter(db);
                A_A.Id = (ow.WriteTree(A_A));
                A_B.Id = (ow.WriteTree(A_B));
                A.Id = (ow.WriteTree(A));
                root.Id = (ow.WriteTree(root));

                tree_root = rw.parseTree(root.Id);
                tree_A = rw.parseTree(A.Id);
                tree_AB = rw.parseTree(A_A.Id);
                Assert.AreSame(tree_AB, rw.parseTree(A_B.Id));
                b = Commit(rw.parseTree(root.Id));
            }

            MarkStart(b);

            AssertCommit(b, objw.next());
            Assert.IsNull(objw.next());

            Assert.AreSame(tree_root, objw.nextObject());
            Assert.AreSame(tree_A, objw.nextObject());
            Assert.AreSame(tree_AB, objw.nextObject());
            Assert.AreSame(rw.lookupBlob(bId), objw.nextObject());
            Assert.IsNull(objw.nextObject());
        }
Example #27
0
        public void test020_createBlobTag()
        {
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            var t = new Tag(db)
                        {
                            Id = emptyId,
                            TagType = "blob",
                            TagName = "test020",
                            Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                            Message = "test020 tagged\n"
                        };
            t.Save();
            Assert.AreEqual("6759556b09fbb4fd8ae5e315134481cc25d46954", t.TagId.Name);

            Tag MapTag = db.MapTag("test020");
            Assert.AreEqual("blob", MapTag.TagType);
            Assert.AreEqual("test020 tagged\n", MapTag.Message);
            Assert.AreEqual(new PersonIdent(jauthor, 1154236443000L, -4 * 60), MapTag.Author);
            Assert.AreEqual("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", MapTag.Id.Name);
        }
Example #28
0
 public string HashAndInsertObject(Stream file)
 {
     var writer = new ObjectWriter(_repository);
     var objectId = writer.WriteBlob(file.Length, file);
     return objectId.ToString();
 }
Example #29
0
 private static string HashWithGitSharp(Stream file)
 {
     var repository = new Repository(new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, GitHelpers.ResolveRepositoryLocation().FullName)));
     var writer = new ObjectWriter(repository);
     return writer.WriteBlob(file.Length, file).ToString();
 }