Esempio n. 1
0
        /// <summary>
        /// Requires absolute path
        /// </summary>
        /// <param name="fileName"></param>
        public void UnStageFile(string fileName)
        {
            if (!this.HasGitRepository)
            {
                return;
            }

            var fileNameRel = GetRelativeFileName(fileName);

            if (GitBash.Exists)
            {
                if (head == null)
                {
                    GitBash.Run(string.Format("rm --cached -- \"{0}\"", fileNameRel), this.GitWorkingDirectory);
                }
                else
                {
                    GitBash.Run(string.Format("reset -- \"{0}\"", fileNameRel), this.GitWorkingDirectory);
                }
            }
            else
            {
                TreeEntry treeEntry = null;
                if (commitTree != null)
                {
                    treeEntry = commitTree.FindBlobMember(fileNameRel);
                }

                //var index = repository.GetIndex();
                //index.RereadIfNecessary();

                index.Remove(repository.WorkTree, fileName);

                if (treeEntry != null)
                {
                    index.AddEntry(treeEntry);
                }
                index.Write();
            }

            this.cache.Remove(GetCacheKey(fileName));
            this.changedFiles = null;
        }
Esempio n. 2
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);
 }
Esempio n. 3
0
 public virtual void TestUnchangedSimple()
 {
     GitIndex index = new GitIndex(db);
     index.Add(trash, WriteTrashFile("a.b", "a.b"));
     index.Add(trash, WriteTrashFile("a.c", "a.c"));
     index.Add(trash, WriteTrashFile("a=c", "a=c"));
     index.Add(trash, WriteTrashFile("a=d", "a=d"));
     index.Write();
     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);
 }
Esempio n. 4
0
 public virtual void TestUnchangedComplex()
 {
     GitIndex index = new GitIndex(db);
     index.Add(trash, WriteTrashFile("a.b", "a.b"));
     index.Add(trash, WriteTrashFile("a.c", "a.c"));
     index.Add(trash, WriteTrashFile("a/b.b/b", "a/b.b/b"));
     index.Add(trash, WriteTrashFile("a/b", "a/b"));
     index.Add(trash, WriteTrashFile("a/c", "a/c"));
     index.Add(trash, WriteTrashFile("a=c", "a=c"));
     index.Add(trash, WriteTrashFile("a=d", "a=d"));
     index.Write();
     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);
 }
Esempio n. 5
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);
 }
Esempio n. 6
0
		/// <exception cref="System.IO.IOException"></exception>
		private void BuildIndex(Dictionary<string, string> indexEntries)
		{
			GitIndex index = new GitIndex(db);
			if (indexEntries != null)
			{
				foreach (KeyValuePair<string, string> e in indexEntries.EntrySet())
				{
					index.Add(trash, WriteTrashFile(e.Key, e.Value)).ForceRecheck();
				}
			}
			index.Write();
			db.GetIndex().Read();
		}