public virtual void TestIsModifiedFileSmudged()
        {
            FilePath f   = WriteTrashFile("file", "content");
            Git      git = new Git(db);

            // The idea of this test is to check the smudged handling
            // Hopefully fsTick will make sure our entry gets smudged
            FsTick(f);
            WriteTrashFile("file", "content");
            git.Add().AddFilepattern("file").Call();
            WriteTrashFile("file", "conten2");
            DirCacheEntry    dce = db.ReadDirCache().GetEntry("file");
            FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig
                                                                                )db.GetConfig()).Get(WorkingTreeOptions.KEY));

            while (!fti.EntryPathString.Equals("file"))
            {
                fti.Next(1);
            }
            // If the fsTick trick does not work we could skip the compareMetaData
            // test and hope that we are usually testing the intended code path.
            NUnit.Framework.Assert.AreEqual(WorkingTreeIterator.MetadataDiff.SMUDGED, fti.CompareMetadata
                                                (dce));
            NUnit.Framework.Assert.IsTrue(fti.IsModified(dce, false));
        }
        public virtual void TestDirCacheMatchingId()
        {
            FilePath f   = WriteTrashFile("file", "content");
            Git      git = new Git(db);

            WriteTrashFile("file", "content");
            FsTick(f);
            git.Add().AddFilepattern("file").Call();
            DirCacheEntry    dce = db.ReadDirCache().GetEntry("file");
            TreeWalk         tw  = new TreeWalk(db);
            FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig
                                                                                )db.GetConfig()).Get(WorkingTreeOptions.KEY));

            tw.AddTree(fti);
            DirCacheIterator dci = new DirCacheIterator(db.ReadDirCache());

            tw.AddTree(dci);
            fti.SetDirCacheIterator(tw, 1);
            while (tw.Next() && !tw.PathString.Equals("file"))
            {
            }
            //
            NUnit.Framework.Assert.AreEqual(WorkingTreeIterator.MetadataDiff.EQUAL, fti.CompareMetadata
                                                (dce));
            ObjectId fromRaw = ObjectId.FromRaw(fti.IdBuffer, fti.IdOffset);

            NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", fromRaw
                                            .GetName());
            NUnit.Framework.Assert.IsFalse(fti.IsModified(dce, false));
        }
        public virtual void IdOffset()
        {
            Git git = new Git(db);

            WriteTrashFile("fileAinfsonly", "A");
            FilePath fileBinindex = WriteTrashFile("fileBinindex", "B");

            FsTick(fileBinindex);
            git.Add().AddFilepattern("fileBinindex").Call();
            WriteTrashFile("fileCinfsonly", "C");
            TreeWalk         tw           = new TreeWalk(db);
            DirCacheIterator indexIter    = new DirCacheIterator(db.ReadDirCache());
            FileTreeIterator workTreeIter = new FileTreeIterator(db);

            tw.AddTree(indexIter);
            tw.AddTree(workTreeIter);
            workTreeIter.SetDirCacheIterator(tw, 0);
            AssertEntry("d46c305e85b630558ee19cc47e73d2e5c8c64cdc", "a,", tw);
            AssertEntry("58ee403f98538ec02409538b3f80adf610accdec", "a,b", tw);
            AssertEntry("0000000000000000000000000000000000000000", "a", tw);
            AssertEntry("b8d30ff397626f0f1d3538d66067edf865e201d6", "a0b", tw);
            // The reason for adding this test. Check that the id is correct for
            // mixed
            AssertEntry("8c7e5a667f1b771847fe88c01c3de34413a1b220", "fileAinfsonly", tw);
            AssertEntry("7371f47a6f8bd23a8fa1a8b2a9479cdd76380e54", "fileBinindex", tw);
            AssertEntry("96d80cd6c4e7158dbebd0849f4fb7ce513e5828c", "fileCinfsonly", tw);
            NUnit.Framework.Assert.IsFalse(tw.Next());
        }
        public virtual void SubmoduleWithNoHead()
        {
            Git git = new Git(db);

            WriteTrashFile("file.txt", "content");
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit      id     = git.Commit().SetMessage("create file").Call();
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_345(id, path));
            editor.Commit();
            NUnit.Framework.Assert.IsNotNull(Git.Init().SetDirectory(new FilePath(db.WorkTree
                                                                                  , path)).Call().GetRepository());
            TreeWalk         walk         = new TreeWalk(db);
            DirCacheIterator indexIter    = new DirCacheIterator(db.ReadDirCache());
            FileTreeIterator workTreeIter = new FileTreeIterator(db);

            walk.AddTree(indexIter);
            walk.AddTree(workTreeIter);
            walk.Filter = PathFilter.Create(path);
            NUnit.Framework.Assert.IsTrue(walk.Next());
            NUnit.Framework.Assert.IsFalse(indexIter.IdEqual(workTreeIter));
            NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, workTreeIter.EntryObjectId);
        }
예제 #5
0
        public void CommitDiffs()
        {
            Assert.IsNull(nGit.head());
            nGit.file_Create("testFile.txt", "some Text");
            "head 1 :{0}".info(nGit.head().info());
            nGit.add_and_Commit_using_Status();
            "head 2 :{0}".info(nGit.head().info());
            nGit.file_Write("testFile.txt", "some Text changed");
            nGit.add_and_Commit_using_Status();
            var head3 = nGit.head();
            "head 3 :{0}".info(head3.info());

            var workingTreeIt = new FileTreeIterator(nGit.Repository);

            var indexDiff = new IndexDiff(nGit.Repository, Constants.HEAD, workingTreeIt);
            indexDiff.Diff();
            var result = new Status(indexDiff);
            "RESULT: {0}".info(result);

            /*OutputStream outputStream = "Sharpen.dll".assembly().type("ByteArrayOutputStream").ctor(new object[0]).cast<OutputStream>();

            var diffFormater = new DiffFormatter(outputStream);
            diffFormater.SetRepository(nGit.Repository);
            //diffFormater.Format(refLog.GetNewId(), refLog.GetOldId());
            diffFormater.Format(refLog.GetOldId(), refLog.GetNewId());*/
        }
예제 #6
0
 /// <summary>Create a new iterator to traverse a subdirectory.</summary>
 /// <remarks>Create a new iterator to traverse a subdirectory.</remarks>
 /// <param name="p">the parent iterator we were created from.</param>
 /// <param name="fs">
 /// the file system abstraction which will be necessary to perform
 /// certain file system operations.
 /// </param>
 /// <param name="root">
 /// the subdirectory. This should be a directory contained within
 /// the parent directory.
 /// </param>
 protected internal FileTreeIterator(NGit.Treewalk.FileTreeIterator p, FilePath root
                                     , FS fs) : base(p)
 {
     directory = root;
     this.fs   = fs;
     Init(Entries());
 }
        public virtual void SubmoduleNestedWithHeadMatchingIndex()
        {
            Git git = new Git(db);

            WriteTrashFile("file.txt", "content");
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit      id     = git.Commit().SetMessage("create file").Call();
            string         path   = "sub/dir1/dir2";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_412(id, path));
            editor.Commit();
            Git.CloneRepository().SetURI(db.Directory.ToURI().ToString()).SetDirectory(new FilePath
                                                                                           (db.WorkTree, path)).Call().GetRepository().Close();
            TreeWalk         walk         = new TreeWalk(db);
            DirCacheIterator indexIter    = new DirCacheIterator(db.ReadDirCache());
            FileTreeIterator workTreeIter = new FileTreeIterator(db);

            walk.AddTree(indexIter);
            walk.AddTree(workTreeIter);
            walk.Filter = PathFilter.Create(path);
            NUnit.Framework.Assert.IsTrue(walk.Next());
            NUnit.Framework.Assert.IsTrue(indexIter.IdEqual(workTreeIter));
        }
        public virtual void TestEmptyIfRootIsFile()
        {
            FilePath r = new FilePath(trash, paths[0]);

            NUnit.Framework.Assert.IsTrue(r.IsFile());
            FileTreeIterator fti = new FileTreeIterator(r, db.FileSystem, ((FileBasedConfig)db
                                                                           .GetConfig()).Get(WorkingTreeOptions.KEY));

            NUnit.Framework.Assert.IsTrue(fti.First);
            NUnit.Framework.Assert.IsTrue(fti.Eof);
        }
        public virtual void TestEmptyIfRootDoesNotExist()
        {
            FilePath r = new FilePath(trash, "not-existing-file");

            NUnit.Framework.Assert.IsFalse(r.Exists());
            FileTreeIterator fti = new FileTreeIterator(r, db.FileSystem, ((FileBasedConfig)db
                                                                           .GetConfig()).Get(WorkingTreeOptions.KEY));

            NUnit.Framework.Assert.IsTrue(fti.First);
            NUnit.Framework.Assert.IsTrue(fti.Eof);
        }
        public virtual void TestSimpleIterate()
        {
            FileTreeIterator top = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig
                                                                                )db.GetConfig()).Get(WorkingTreeOptions.KEY));

            NUnit.Framework.Assert.IsTrue(top.First);
            NUnit.Framework.Assert.IsFalse(top.Eof);
            NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE.GetBits(), top.mode);
            NUnit.Framework.Assert.AreEqual(paths[0], NameOf(top));
            NUnit.Framework.Assert.AreEqual(paths[0].Length, top.GetEntryLength());
            NUnit.Framework.Assert.AreEqual(mtime[0], top.GetEntryLastModified());
            top.Next(1);
            NUnit.Framework.Assert.IsFalse(top.First);
            NUnit.Framework.Assert.IsFalse(top.Eof);
            NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE.GetBits(), top.mode);
            NUnit.Framework.Assert.AreEqual(paths[1], NameOf(top));
            NUnit.Framework.Assert.AreEqual(paths[1].Length, top.GetEntryLength());
            NUnit.Framework.Assert.AreEqual(mtime[1], top.GetEntryLastModified());
            top.Next(1);
            NUnit.Framework.Assert.IsFalse(top.First);
            NUnit.Framework.Assert.IsFalse(top.Eof);
            NUnit.Framework.Assert.AreEqual(FileMode.TREE.GetBits(), top.mode);
            ObjectReader         reader = db.NewObjectReader();
            AbstractTreeIterator sub    = top.CreateSubtreeIterator(reader);

            NUnit.Framework.Assert.IsTrue(sub is FileTreeIterator);
            FileTreeIterator subfti = (FileTreeIterator)sub;

            NUnit.Framework.Assert.IsTrue(sub.First);
            NUnit.Framework.Assert.IsFalse(sub.Eof);
            NUnit.Framework.Assert.AreEqual(paths[2], NameOf(sub));
            NUnit.Framework.Assert.AreEqual(paths[2].Length, subfti.GetEntryLength());
            NUnit.Framework.Assert.AreEqual(mtime[2], subfti.GetEntryLastModified());
            sub.Next(1);
            NUnit.Framework.Assert.IsTrue(sub.Eof);
            top.Next(1);
            NUnit.Framework.Assert.IsFalse(top.First);
            NUnit.Framework.Assert.IsFalse(top.Eof);
            NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE.GetBits(), top.mode);
            NUnit.Framework.Assert.AreEqual(paths[3], NameOf(top));
            NUnit.Framework.Assert.AreEqual(paths[3].Length, top.GetEntryLength());
            NUnit.Framework.Assert.AreEqual(mtime[3], top.GetEntryLastModified());
            top.Next(1);
            NUnit.Framework.Assert.IsTrue(top.Eof);
        }
        public virtual void TestComputeFileObjectId()
        {
            FileTreeIterator top = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig
                                                                                )db.GetConfig()).Get(WorkingTreeOptions.KEY));
            MessageDigest md = Constants.NewMessageDigest();

            md.Update(Constants.EncodeASCII(Constants.TYPE_BLOB));
            md.Update(unchecked ((byte)' '));
            md.Update(Constants.EncodeASCII(paths[0].Length));
            md.Update(unchecked ((byte)0));
            md.Update(Constants.Encode(paths[0]));
            ObjectId expect = ObjectId.FromRaw(md.Digest());

            NUnit.Framework.Assert.AreEqual(expect, top.EntryObjectId);
            // Verify it was cached by removing the file and getting it again.
            //
            FileUtils.Delete(new FilePath(trash, paths[0]));
            NUnit.Framework.Assert.AreEqual(expect, top.EntryObjectId);
        }
예제 #12
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);
 }
예제 #13
0
		public virtual void TestDiff()
		{
			Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test");
			FilePath folder = new FilePath(db.Directory.GetParent(), "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "folder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "folder change");
			PatchIdDiffFormatter df = new PatchIdDiffFormatter();
			df.SetRepository(db);
			df.SetPathFilter(PathFilter.Create("folder"));
			DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator newTree = new FileTreeIterator(db);
			df.Format(oldTree, newTree);
			df.Flush();
			NUnit.Framework.Assert.AreEqual("1ff64e0f9333e9b81967c3e8d7a81362b14d5441", df.GetCalulatedPatchId
				().Name);
		}
        public virtual void TestIsModifiedSymlink()
        {
            FilePath f   = WriteTrashFile("symlink", "content");
            Git      git = new Git(db);

            git.Add().AddFilepattern("symlink").Call();
            git.Commit().SetMessage("commit").Call();
            // Modify previously committed DirCacheEntry and write it back to disk
            DirCacheEntry dce = db.ReadDirCache().GetEntry("symlink");

            dce.FileMode = FileMode.SYMLINK;
            DirCacheCheckout.CheckoutEntry(db, f, dce);
            FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig
                                                                                )db.GetConfig()).Get(WorkingTreeOptions.KEY));

            while (!fti.EntryPathString.Equals("symlink"))
            {
                fti.Next(1);
            }
            NUnit.Framework.Assert.IsFalse(fti.IsModified(dce, false));
        }
예제 #15
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()
         );
 }
예제 #16
0
 public virtual void TestAssumeUnchanged()
 {
     Git git = new Git(db);
     string path = "file";
     WriteTrashFile(path, "content");
     git.Add().AddFilepattern(path).Call();
     string path2 = "file2";
     WriteTrashFile(path2, "content");
     git.Add().AddFilepattern(path2).Call();
     git.Commit().SetMessage("commit").Call();
     AssumeUnchanged(path2);
     WriteTrashFile(path, "more content");
     WriteTrashFile(path2, "more content");
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(1, diff.GetAssumeUnchanged().Count);
     NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetAssumeUnchanged().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("file"));
     git.Add().AddFilepattern(".").Call();
     iterator = new FileTreeIterator(db);
     diff = new IndexDiff(db, Constants.HEAD, iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(1, diff.GetAssumeUnchanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(1, diff.GetChanged().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetAssumeUnchanged().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file"));
     NUnit.Framework.CollectionAssert.AreEquivalent(Sharpen.Collections<string>.EMPTY_SET, diff.GetUntrackedFolders
         ());
 }
예제 #17
0
		IEnumerable<string> GetDirectoryFiles (DirectoryInfo dir)
		{
			FileTreeIterator iter = new FileTreeIterator (dir.FullName, RootRepository.FileSystem, WorkingTreeOptions.KEY.Parse(RootRepository.GetConfig()));
			while (!iter.Eof) {
				var file = iter.GetEntryFile ();
				if (file != null && !iter.IsEntryIgnored ())
					yield return file.GetPath ();
				iter.Next (1);
			}
		}
예제 #18
0
		/// <summary>
		/// Run the diff operation. Until this is called, all lists will be empty
		/// </summary>
		/// <returns>true if anything is different between index, tree, and workdir</returns>
		private void UpdateDirectory (IEnumerable<string> paths, bool recursive)
		{
			RevWalk rw = new RevWalk (Repository);
			ObjectId id = Repository.Resolve (Constants.HEAD);
			var commit = id != null ? rw.ParseCommit (id) : null;
			
			TreeWalk treeWalk = new TreeWalk (Repository);
			treeWalk.Reset ();
			treeWalk.Recursive = false;

			if (commit != null)
				treeWalk.AddTree (commit.Tree);
			else
				treeWalk.AddTree (new EmptyTreeIterator());
			
			DirCache dc = Repository.ReadDirCache ();
			treeWalk.AddTree (new DirCacheIterator (dc));
			
			FileTreeIterator workTree = new FileTreeIterator (Repository.WorkTree, Repository.FileSystem, WorkingTreeOptions.KEY.Parse(Repository.GetConfig()));
			treeWalk.AddTree (workTree);

			List<TreeFilter> filters = new List<TreeFilter> ();
			filters.Add (new SkipWorkTreeFilter(1));
			
			var pathFilters = paths.Where (p => p != ".").Select (p => PathFilter.Create (p)).ToArray ();
			if (pathFilters.Length > 1) {
				filters.Add (OrTreeFilter.Create (pathFilters)); // Use an OR to join all path filters
			} else if (pathFilters.Length == 1)
				filters.Add (pathFilters[0]);

			if (filters.Count > 1)
				treeWalk.Filter = AndTreeFilter.Create(filters);
			else
				treeWalk.Filter = filters[0];
			
			while (treeWalk.Next())
			{
				AbstractTreeIterator treeIterator = treeWalk.GetTree<AbstractTreeIterator>(0);
				DirCacheIterator dirCacheIterator = treeWalk.GetTree<DirCacheIterator>(1);
				WorkingTreeIterator workingTreeIterator = treeWalk.GetTree<WorkingTreeIterator>(2);
				NGit.FileMode fileModeTree = treeWalk.GetFileMode(0);
				
				if (treeWalk.IsSubtree) {
					treeWalk.EnterSubtree ();
					continue;
				}
				
				int stage = dirCacheIterator != null ? dirCacheIterator.GetDirCacheEntry ().Stage : 0;
				if (stage > 1)
					continue;
				else if (stage == 1) {
					MergeConflict.Add(dirCacheIterator.EntryPathString);
					changesExist = true;
					continue;
				}
				
				if (treeIterator != null)
				{
					if (dirCacheIterator != null)
					{
						if (!treeIterator.EntryObjectId.Equals(dirCacheIterator.EntryObjectId))
						{
							// in repo, in index, content diff => changed
							Modified.Add(dirCacheIterator.EntryPathString);
							changesExist = true;
						}
					}
					else
					{
						// in repo, not in index => removed
						if (!fileModeTree.Equals(NGit.FileMode.TYPE_TREE))
						{
							Removed.Add(treeIterator.EntryPathString);
							changesExist = true;
						}
					}
				}
				else
				{
					if (dirCacheIterator != null)
					{
						// not in repo, in index => added
						Added.Add(dirCacheIterator.EntryPathString);
						changesExist = true;
					}
					else
					{
						// not in repo, not in index => untracked
						if (workingTreeIterator != null && !workingTreeIterator.IsEntryIgnored())
						{
							Untracked.Add(workingTreeIterator.EntryPathString);
							changesExist = true;
						}
					}
				}
				if (dirCacheIterator != null)
				{
					if (workingTreeIterator == null)
					{
						// in index, not in workdir => missing
						Missing.Add(dirCacheIterator.EntryPathString);
						changesExist = true;
					}
					else
					{
						// Workaround to file time resolution issues
						long itime = dirCacheIterator.GetDirCacheEntry ().LastModified;
						long ftime = workingTreeIterator.GetEntryLastModified ();
						if (itime / 1000 != ftime / 1000) {
							if (!dirCacheIterator.IdEqual(workingTreeIterator))
							{
								// in index, in workdir, content differs => modified
								Modified.Add(dirCacheIterator.EntryPathString);
								changesExist = true;
							}
						}
					}
				}
			}
		}
		public FileTreeIteratorWithTimeControl(FileTreeIterator p, Repository repo, TreeSet
			<long> modTimes) : base(p, repo.WorkTree, repo.FileSystem)
		{
			this.modTimes = modTimes;
		}
예제 #20
0
		public virtual void TestDiff()
		{
			Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test");
			FilePath folder = new FilePath(db.Directory.GetParent(), "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "folder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "folder change");
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			DiffFormatter df = new DiffFormatter(new BufferedOutputStream(os));
			df.SetRepository(db);
			df.SetPathFilter(PathFilter.Create("folder"));
			DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator newTree = new FileTreeIterator(db);
			df.Format(oldTree, newTree);
			df.Flush();
			string actual = os.ToString();
			string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
				 + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
				 "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
			NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
		}
예제 #21
0
		public virtual void TestEmptyIfRootIsFile()
		{
			FilePath r = new FilePath(trash, paths[0]);
			NUnit.Framework.Assert.IsTrue(r.IsFile());
			FileTreeIterator fti = new FileTreeIterator(r, db.FileSystem, ((FileBasedConfig)db
				.GetConfig()).Get(WorkingTreeOptions.KEY));
			NUnit.Framework.Assert.IsTrue(fti.First);
			NUnit.Framework.Assert.IsTrue(fti.Eof);
		}
예제 #22
0
		public virtual void SubmoduleNestedWithHeadMatchingIndex()
		{
			Git git = new Git(db);
			WriteTrashFile("file.txt", "content");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit id = git.Commit().SetMessage("create file").Call();
			string path = "sub/dir1/dir2";
			DirCache cache = db.LockDirCache();
			DirCacheEditor editor = cache.Editor();
			editor.Add(new _PathEdit_412(id, path));
			editor.Commit();
			Git.CloneRepository().SetURI(db.Directory.ToURI().ToString()).SetDirectory(new FilePath
				(db.WorkTree, path)).Call().GetRepository().Close();
			TreeWalk walk = new TreeWalk(db);
			DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator workTreeIter = new FileTreeIterator(db);
			walk.AddTree(indexIter);
			walk.AddTree(workTreeIter);
			walk.Filter = PathFilter.Create(path);
			NUnit.Framework.Assert.IsTrue(walk.Next());
			NUnit.Framework.Assert.IsTrue(indexIter.IdEqual(workTreeIter));
		}
예제 #23
0
 public FileTreeIteratorWithTimeControl(FileTreeIterator p, Repository repo, TreeSet
                                        <long> modTimes) : base(p, repo.WorkTree, repo.FileSystem)
 {
     this.modTimes = modTimes;
 }
예제 #24
0
 public virtual void TestModified()
 {
     WriteTrashFile("file2", "file2");
     WriteTrashFile("dir/file3", "dir/file3");
     Git git = new Git(db);
     git.Add().AddFilepattern("file2").AddFilepattern("dir/file3").Call();
     WriteTrashFile("dir/file3", "changed");
     Tree tree = new Tree(db);
     tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
     Tree tree2 = (Tree)tree.FindTreeMember("dir");
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
예제 #25
0
 public virtual void TestRemoved()
 {
     WriteTrashFile("file2", "file2");
     WriteTrashFile("dir/file3", "dir/file3");
     Tree tree = new Tree(db);
     tree.AddFile("file2");
     tree.AddFile("dir/file3");
     NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
     tree.FindBlobMember("file2").SetId(ObjectId.FromString("30d67d4672d5c05833b7192cc77a79eaafb5c7ad"
         ));
     Tree tree2 = (Tree)tree.FindTreeMember("dir");
     tree2.FindBlobMember("file3").SetId(ObjectId.FromString("873fb8d667d05436d728c52b1d7a09528e6eb59b"
         ));
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetRemoved().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
예제 #26
0
 public virtual void TestRemovedUntracked()
 {
     Git git = new Git(db);
     string path = "file";
     WriteTrashFile(path, "content");
     git.Add().AddFilepattern(path).Call();
     git.Commit().SetMessage("commit").Call();
     RemoveFromIndex(path);
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
     diff.Diff();
     NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains(path));
     NUnit.Framework.Assert.IsTrue(diff.GetUntracked().Contains(path));
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
예제 #27
0
 public virtual void TestUnchangedComplex()
 {
     Git git = new Git(db);
     WriteTrashFile("a.b", "a.b");
     WriteTrashFile("a.c", "a.c");
     WriteTrashFile("a/b.b/b", "a/b.b/b");
     WriteTrashFile("a/b", "a/b");
     WriteTrashFile("a/c", "a/c");
     WriteTrashFile("a=c", "a=c");
     WriteTrashFile("a=d", "a=d");
     git.Add().AddFilepattern("a.b").AddFilepattern("a.c").AddFilepattern("a/b.b/b").AddFilepattern
         ("a/b").AddFilepattern("a/c").AddFilepattern("a=c").AddFilepattern("a=d").Call();
     Tree tree = new Tree(db);
     // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
     tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
         ));
     tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
         ));
     tree.AddFile("a/b.b/b").SetId(ObjectId.FromString("8d840bd4e2f3a48ff417c8e927d94996849933fd"
         ));
     tree.AddFile("a/b").SetId(ObjectId.FromString("db89c972fc57862eae378f45b74aca228037d415"
         ));
     tree.AddFile("a/c").SetId(ObjectId.FromString("52ad142a008aeb39694bafff8e8f1be75ed7f007"
         ));
     tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
         ));
     tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
         ));
     Tree tree3 = (Tree)tree.FindTreeMember("a/b.b");
     tree3.SetId(InsertTree(tree3));
     Tree tree2 = (Tree)tree.FindTreeMember("a");
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
예제 #28
0
 public virtual void TestUnchangedSimple()
 {
     WriteTrashFile("a.b", "a.b");
     WriteTrashFile("a.c", "a.c");
     WriteTrashFile("a=c", "a=c");
     WriteTrashFile("a=d", "a=d");
     Git git = new Git(db);
     git.Add().AddFilepattern("a.b").Call();
     git.Add().AddFilepattern("a.c").Call();
     git.Add().AddFilepattern("a=c").Call();
     git.Add().AddFilepattern("a=d").Call();
     Tree tree = new Tree(db);
     // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
     tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
         ));
     tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
         ));
     tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
         ));
     tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
         ));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
예제 #29
0
		public virtual void TestIsModifiedFileSmudged()
		{
			FilePath f = WriteTrashFile("file", "content");
			Git git = new Git(db);
			// The idea of this test is to check the smudged handling
			// Hopefully fsTick will make sure our entry gets smudged
			FsTick(f);
			WriteTrashFile("file", "content");
			git.Add().AddFilepattern("file").Call();
			WriteTrashFile("file", "conten2");
			DirCacheEntry dce = db.ReadDirCache().GetEntry("file");
			FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig
				)db.GetConfig()).Get(WorkingTreeOptions.KEY));
			while (!fti.EntryPathString.Equals("file"))
			{
				fti.Next(1);
			}
			// If the fsTick trick does not work we could skip the compareMetaData
			// test and hope that we are usually testing the intended code path.
			NUnit.Framework.Assert.AreEqual(WorkingTreeIterator.MetadataDiff.SMUDGED, fti.CompareMetadata
				(dce));
			NUnit.Framework.Assert.IsTrue(fti.IsModified(dce, false));
		}
예제 #30
0
		public virtual void SubmoduleWithNoHead()
		{
			Git git = new Git(db);
			WriteTrashFile("file.txt", "content");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit id = git.Commit().SetMessage("create file").Call();
			string path = "sub";
			DirCache cache = db.LockDirCache();
			DirCacheEditor editor = cache.Editor();
			editor.Add(new _PathEdit_345(id, path));
			editor.Commit();
			NUnit.Framework.Assert.IsNotNull(Git.Init().SetDirectory(new FilePath(db.WorkTree
				, path)).Call().GetRepository());
			TreeWalk walk = new TreeWalk(db);
			DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator workTreeIter = new FileTreeIterator(db);
			walk.AddTree(indexIter);
			walk.AddTree(workTreeIter);
			walk.Filter = PathFilter.Create(path);
			NUnit.Framework.Assert.IsTrue(walk.Next());
			NUnit.Framework.Assert.IsFalse(indexIter.IdEqual(workTreeIter));
			NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, workTreeIter.EntryObjectId);
		}
예제 #31
0
 public virtual void TestConflictingFromMultipleCreations()
 {
     Git git = new Git(db);
     WriteTrashFile("a", "1\na\n3\n");
     git.Add().AddFilepattern("a").Call();
     RevCommit initialCommit = git.Commit().SetMessage("initial").Call();
     CreateBranch(initialCommit, "refs/heads/side");
     CheckoutBranch("refs/heads/side");
     WriteTrashFile("b", "1\nb(side)\n3\n");
     git.Add().AddFilepattern("b").Call();
     RevCommit secondCommit = git.Commit().SetMessage("side").Call();
     CheckoutBranch("refs/heads/master");
     WriteTrashFile("b", "1\nb(main)\n3\n");
     git.Add().AddFilepattern("b").Call();
     git.Commit().SetMessage("main").Call();
     MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
         .RESOLVE).Call();
     NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual("[]", new TreeSet<string>(diff.GetChanged()).ToString
         ());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetAdded());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetRemoved());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetMissing());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetModified());
     NUnit.Framework.Assert.AreEqual(1, diff.GetConflicting().Count());
     NUnit.Framework.Assert.AreEqual("b", diff.GetConflicting().First());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetUntrackedFolders()
         );
 }
예제 #32
0
		public virtual void IdOffset()
		{
			Git git = new Git(db);
			WriteTrashFile("fileAinfsonly", "A");
			FilePath fileBinindex = WriteTrashFile("fileBinindex", "B");
			FsTick(fileBinindex);
			git.Add().AddFilepattern("fileBinindex").Call();
			WriteTrashFile("fileCinfsonly", "C");
			TreeWalk tw = new TreeWalk(db);
			DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator workTreeIter = new FileTreeIterator(db);
			tw.AddTree(indexIter);
			tw.AddTree(workTreeIter);
			workTreeIter.SetDirCacheIterator(tw, 0);
			AssertEntry("d46c305e85b630558ee19cc47e73d2e5c8c64cdc", "a,", tw);
			AssertEntry("58ee403f98538ec02409538b3f80adf610accdec", "a,b", tw);
			AssertEntry("0000000000000000000000000000000000000000", "a", tw);
			AssertEntry("b8d30ff397626f0f1d3538d66067edf865e201d6", "a0b", tw);
			// The reason for adding this test. Check that the id is correct for
			// mixed
			AssertEntry("8c7e5a667f1b771847fe88c01c3de34413a1b220", "fileAinfsonly", tw);
			AssertEntry("7371f47a6f8bd23a8fa1a8b2a9479cdd76380e54", "fileBinindex", tw);
			AssertEntry("96d80cd6c4e7158dbebd0849f4fb7ce513e5828c", "fileCinfsonly", tw);
			NUnit.Framework.Assert.IsFalse(tw.Next());
		}
예제 #33
0
 public virtual void TestModified()
 {
     GitIndex index = new GitIndex(db);
     index.Add(trash, WriteTrashFile("file2", "file2"));
     index.Add(trash, WriteTrashFile("dir/file3", "dir/file3"));
     index.Write();
     WriteTrashFile("dir/file3", "changed");
     Tree tree = new Tree(db);
     tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
     Tree tree2 = (Tree)tree.FindTreeMember("dir");
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
 }
예제 #34
0
		public virtual void TestEmptyIfRootDoesNotExist()
		{
			FilePath r = new FilePath(trash, "not-existing-file");
			NUnit.Framework.Assert.IsFalse(r.Exists());
			FileTreeIterator fti = new FileTreeIterator(r, db.FileSystem, ((FileBasedConfig)db
				.GetConfig()).Get(WorkingTreeOptions.KEY));
			NUnit.Framework.Assert.IsTrue(fti.First);
			NUnit.Framework.Assert.IsTrue(fti.Eof);
		}
예제 #35
0
        protected void RaiseNotifyFromDiff(Repository repository)
        {
            if (repository == null)
                throw new ArgumentNullException("repository");
            var workingTreeIt = new FileTreeIterator(repository);
            var diff = new IndexDiff(repository, Constants.HEAD, workingTreeIt);

            diff.Diff();

            RaiseNotifyFromDiff(repository, diff.GetAdded(), GitNotifyAction.UpdateAdd);
            RaiseNotifyFromDiff(repository, diff.GetAssumeUnchanged(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetChanged(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetConflicting(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetMissing(), GitNotifyAction.UpdateDeleted);
            RaiseNotifyFromDiff(repository, diff.GetModified(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetRemoved(), GitNotifyAction.UpdateDeleted);
            RaiseNotifyFromDiff(repository, diff.GetUntracked(), GitNotifyAction.UpdateUpdate);
        }
예제 #36
0
파일: IndexDiffTest.cs 프로젝트: shoff/ngit
		public virtual void TestConflictingDeletedAndModified()
		{
			Git git = new Git(db);
			WriteTrashFile("a", "1\na\n3\n");
			WriteTrashFile("b", "1\nb\n3\n");
			git.Add().AddFilepattern("a").AddFilepattern("b").Call();
			RevCommit initialCommit = git.Commit().SetMessage("initial").Call();
			// create side branch and delete "a"
			CreateBranch(initialCommit, "refs/heads/side");
			CheckoutBranch("refs/heads/side");
			git.Rm().AddFilepattern("a").Call();
			RevCommit secondCommit = git.Commit().SetMessage("side").Call();
			// update a on master to generate conflict
			CheckoutBranch("refs/heads/master");
			WriteTrashFile("a", "1\na(main)\n3\n");
			git.Add().AddFilepattern("a").Call();
			git.Commit().SetMessage("main").Call();
			// merge side with master
			MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
				.RESOLVE).Call();
			NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
			FileTreeIterator iterator = new FileTreeIterator(db);
			IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
			diff.Diff();
			NUnit.Framework.Assert.AreEqual("[]", new TreeSet<string>(diff.GetChanged()).ToString
				());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetAdded().ToString());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetRemoved().ToString());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetMissing().ToString());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetModified().ToString());
			NUnit.Framework.Assert.AreEqual("[a]", diff.GetConflicting().ToString());
		}
예제 #37
0
		public virtual void TestSimpleIterate()
		{
			FileTreeIterator top = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig
				)db.GetConfig()).Get(WorkingTreeOptions.KEY));
			NUnit.Framework.Assert.IsTrue(top.First);
			NUnit.Framework.Assert.IsFalse(top.Eof);
			NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE.GetBits(), top.mode);
			NUnit.Framework.Assert.AreEqual(paths[0], NameOf(top));
			NUnit.Framework.Assert.AreEqual(paths[0].Length, top.GetEntryLength());
			NUnit.Framework.Assert.AreEqual(mtime[0], top.GetEntryLastModified());
			top.Next(1);
			NUnit.Framework.Assert.IsFalse(top.First);
			NUnit.Framework.Assert.IsFalse(top.Eof);
			NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE.GetBits(), top.mode);
			NUnit.Framework.Assert.AreEqual(paths[1], NameOf(top));
			NUnit.Framework.Assert.AreEqual(paths[1].Length, top.GetEntryLength());
			NUnit.Framework.Assert.AreEqual(mtime[1], top.GetEntryLastModified());
			top.Next(1);
			NUnit.Framework.Assert.IsFalse(top.First);
			NUnit.Framework.Assert.IsFalse(top.Eof);
			NUnit.Framework.Assert.AreEqual(FileMode.TREE.GetBits(), top.mode);
			ObjectReader reader = db.NewObjectReader();
			AbstractTreeIterator sub = top.CreateSubtreeIterator(reader);
			NUnit.Framework.Assert.IsTrue(sub is FileTreeIterator);
			FileTreeIterator subfti = (FileTreeIterator)sub;
			NUnit.Framework.Assert.IsTrue(sub.First);
			NUnit.Framework.Assert.IsFalse(sub.Eof);
			NUnit.Framework.Assert.AreEqual(paths[2], NameOf(sub));
			NUnit.Framework.Assert.AreEqual(paths[2].Length, subfti.GetEntryLength());
			NUnit.Framework.Assert.AreEqual(mtime[2], subfti.GetEntryLastModified());
			sub.Next(1);
			NUnit.Framework.Assert.IsTrue(sub.Eof);
			top.Next(1);
			NUnit.Framework.Assert.IsFalse(top.First);
			NUnit.Framework.Assert.IsFalse(top.Eof);
			NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE.GetBits(), top.mode);
			NUnit.Framework.Assert.AreEqual(paths[3], NameOf(top));
			NUnit.Framework.Assert.AreEqual(paths[3].Length, top.GetEntryLength());
			NUnit.Framework.Assert.AreEqual(mtime[3], top.GetEntryLastModified());
			top.Next(1);
			NUnit.Framework.Assert.IsTrue(top.Eof);
		}
		public FileTreeIteratorWithTimeControl(FileTreeIterator p, FilePath f, FS fs, TreeSet
			<long> modTimes) : base(p, f, fs)
		{
			this.modTimes = modTimes;
		}
예제 #39
0
		public virtual void TestComputeFileObjectId()
		{
			FileTreeIterator top = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig
				)db.GetConfig()).Get(WorkingTreeOptions.KEY));
			MessageDigest md = Constants.NewMessageDigest();
			md.Update(Constants.EncodeASCII(Constants.TYPE_BLOB));
			md.Update(unchecked((byte)' '));
			md.Update(Constants.EncodeASCII(paths[0].Length));
			md.Update(unchecked((byte)0));
			md.Update(Constants.Encode(paths[0]));
			ObjectId expect = ObjectId.FromRaw(md.Digest());
			NUnit.Framework.Assert.AreEqual(expect, top.EntryObjectId);
			// Verify it was cached by removing the file and getting it again.
			//
			FileUtils.Delete(new FilePath(trash, paths[0]));
			NUnit.Framework.Assert.AreEqual(expect, top.EntryObjectId);
		}
예제 #40
0
 public FileTreeIteratorWithTimeControl(FileTreeIterator p, FilePath f, FS fs, TreeSet
                                        <long> modTimes) : base(p, f, fs)
 {
     this.modTimes = modTimes;
 }
예제 #41
0
		public virtual void TestDirCacheMatchingId()
		{
			FilePath f = WriteTrashFile("file", "content");
			Git git = new Git(db);
			WriteTrashFile("file", "content");
			FsTick(f);
			git.Add().AddFilepattern("file").Call();
			DirCacheEntry dce = db.ReadDirCache().GetEntry("file");
			TreeWalk tw = new TreeWalk(db);
			FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig
				)db.GetConfig()).Get(WorkingTreeOptions.KEY));
			tw.AddTree(fti);
			DirCacheIterator dci = new DirCacheIterator(db.ReadDirCache());
			tw.AddTree(dci);
			fti.SetDirCacheIterator(tw, 1);
			while (tw.Next() && !tw.PathString.Equals("file"))
			{
			}
			//
			NUnit.Framework.Assert.AreEqual(WorkingTreeIterator.MetadataDiff.EQUAL, fti.CompareMetadata
				(dce));
			ObjectId fromRaw = ObjectId.FromRaw(fti.IdBuffer, fti.IdOffset);
			NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", fromRaw
				.GetName());
			NUnit.Framework.Assert.IsFalse(fti.IsModified(dce, false));
		}
예제 #42
0
		/// <summary>Resets the index to represent exactly some filesystem content.</summary>
		/// <remarks>
		/// Resets the index to represent exactly some filesystem content. E.g. the
		/// following call will replace the index with the working tree content:
		/// <p>
		/// <code>resetIndex(new FileSystemIterator(db))</code>
		/// <p>
		/// This method can be used by testcases which first prepare a new commit
		/// somewhere in the filesystem (e.g. in the working-tree) and then want to
		/// have an index which matches their prepared content.
		/// </remarks>
		/// <param name="treeItr">
		/// a
		/// <see cref="NGit.Treewalk.FileTreeIterator">NGit.Treewalk.FileTreeIterator</see>
		/// which determines which files should
		/// go into the new index
		/// </param>
		/// <exception cref="System.IO.FileNotFoundException">System.IO.FileNotFoundException
		/// 	</exception>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		protected internal virtual void ResetIndex(FileTreeIterator treeItr)
		{
			ObjectInserter inserter = db.NewObjectInserter();
			DirCacheBuilder builder = db.LockDirCache().Builder();
			DirCacheEntry dce;
			while (!treeItr.Eof)
			{
				long len = treeItr.GetEntryLength();
				dce = new DirCacheEntry(treeItr.EntryPathString);
				dce.FileMode = treeItr.EntryFileMode;
				dce.LastModified = treeItr.GetEntryLastModified();
				dce.SetLength((int)len);
				FileInputStream @in = new FileInputStream(treeItr.GetEntryFile());
				dce.SetObjectId(inserter.Insert(Constants.OBJ_BLOB, len, @in));
				@in.Close();
				builder.Add(dce);
				treeItr.Next(1);
			}
			builder.Commit();
			inserter.Flush();
			inserter.Release();
		}
예제 #43
0
		public virtual void TestIsModifiedSymlink()
		{
			FilePath f = WriteTrashFile("symlink", "content");
			Git git = new Git(db);
			git.Add().AddFilepattern("symlink").Call();
			git.Commit().SetMessage("commit").Call();
			// Modify previously committed DirCacheEntry and write it back to disk
			DirCacheEntry dce = db.ReadDirCache().GetEntry("symlink");
			dce.FileMode = FileMode.SYMLINK;
			DirCacheCheckout.CheckoutEntry(db, f, dce);
			FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig
				)db.GetConfig()).Get(WorkingTreeOptions.KEY));
			while (!fti.EntryPathString.Equals("symlink"))
			{
				fti.Next(1);
			}
			NUnit.Framework.Assert.IsFalse(fti.IsModified(dce, false));
		}