public virtual void Delete(string path)
        {
            var fileInfo = new FileInfo(path);

            if (fileInfo.IsFile())
            {
                fileInfo.Delete();

                return;
            }

            var directoryInfo = new DirectoryInfo(path);

            directoryInfo.Delete(true);
        }
        public void test001_Initalize()
        {
            var gitdir = new DirectoryInfo(trash.FullName + "/.git");
            var objects = new DirectoryInfo(gitdir.FullName + "/objects");
            var objects_pack = new DirectoryInfo(objects.FullName + "/pack");
            var objects_info = new DirectoryInfo(objects.FullName + "/info");
            var refs = new DirectoryInfo(gitdir.FullName + "/refs");
            var refs_heads = new DirectoryInfo(refs.FullName + "/heads");
            var refs_tags = new DirectoryInfo(refs.FullName + "/tags");
            var HEAD = new FileInfo(gitdir.FullName + "/HEAD");

            Assert.IsTrue(trash.IsDirectory(), "Exists " + trash);
            Assert.IsTrue(objects.IsDirectory(), "Exists " + objects);
            Assert.IsTrue(objects_pack.IsDirectory(), "Exists " + objects_pack);
            Assert.IsTrue(objects_info.IsDirectory(), "Exists " + objects_info);
            Assert.AreEqual(2, objects.ListFiles().Length);
            Assert.IsTrue(refs.IsDirectory(), "Exists " + refs);
            Assert.IsTrue(refs_heads.IsDirectory(), "Exists " + refs_heads);
            Assert.IsTrue(refs_tags.IsDirectory(), "Exists " + refs_tags);
            Assert.IsTrue(HEAD.IsFile(), "Exists " + HEAD);
            Assert.AreEqual(23, HEAD.Length);
        }
Exemple #3
0
        internal void PrescanTwoTrees()
        {
            var visitor = new AbstractIndexTreeVisitor
                              {
                                  VisitEntryAux = (treeEntry, auxEntry, indexEntry, file) =>
                                                   {
                                                       if (treeEntry is Tree || auxEntry is Tree)
                                                       {
                                                           throw new ArgumentException("Can't pass me a tree!");
                                                       }

                                                       ProcessEntry(treeEntry, auxEntry, indexEntry);
                                                   },

                                  FinishVisitTree = (tree, auxTree, currentDirectory) =>
                                                        {
                                                            if (currentDirectory.Length == 0) return;
                                                            if (auxTree == null) return;

                                                            if (_index.GetEntry(currentDirectory) != null)
                                                            {
                                                                Removed.Add(currentDirectory);
                                                            }
                                                        }
                              };

            new IndexTreeWalker(_index, _head, _merge, _root, visitor).Walk();

            // if there's a conflict, don't list it under
            // to-be-removed, since that messed up our next
            // section
            Removed.RemoveAll(removed => Conflicts.Contains(removed));

            foreach (string path in _updated.Keys)
            {
                if (_index.GetEntry(path) == null)
                {
                    FileSystemInfo file = new FileInfo(Path.Combine(_root.DirectoryName(), path));
                    if (file.IsFile())
                    {
                        Conflicts.Add(path);
                    }
                    else if (file.IsDirectory())
                    {
                        CheckConflictsWithFile(file);
                    }
                }
            }

            Conflicts.RemoveAll(conflict => Removed.Contains(conflict));
        }
 private static void loadIdentity(JSch sch, FileInfo priv)
 {
     if (!priv.IsFile()) return;
     try
     {
         sch.addIdentity(priv.FullName);
     }
     catch (JSchException)
     {
         // Instead, pretend the key doesn't exist.
     }
 }
 public void test002_WriteEmptyTree()
 {
     // One of our test packs contains the empty tree object. If the pack is
     // open when we Create it we won't write the object file out as a loose
     // object (as it already exists in the pack).
     //
     Core.Repository newdb = createNewEmptyRepo();
     var t = new Tree(newdb);
     t.Accept(new WriteTree(trash, newdb), TreeEntry.MODIFIED_ONLY);
     Assert.AreEqual("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.Id.Name);
     var o = new FileInfo(newdb.Directory + "/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904");
     Assert.IsTrue(o.IsFile(), "Exists " + o);
     Assert.IsTrue(o.IsReadOnly, "Read-only " + o);
 }
        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);
        }
 public void test002_WriteEmptyTree2()
 {
     // File shouldn't exist as it is in a test pack.
     //
     var t = new Tree(db);
     t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
     Assert.AreEqual("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.Id.Name);
     var o = new FileInfo(trash_git + "/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904");
     Assert.IsFalse(o.IsFile(), "Exists " + o);
 }