Exemplo n.º 1
0
        public void HonorsTopLevelIgnore()
        {
            WriteIgnore(".", "*.o");
            _handler = new IgnoreHandler(db);

            Assert.IsTrue(_handler.IsIgnored("test.o"));
        }
Exemplo n.º 2
0
        public void HonorsExcludeFile()
        {
            WriteExclude("*.html");
            _handler = new IgnoreHandler(db);

            Assert.IsTrue(_handler.IsIgnored("test.html"));
        }
Exemplo n.º 3
0
        public void HonorsConfigExcludes()
        {
            WriteConfigExcludes("ignoreHandler", "*.a");
            _handler = new IgnoreHandler(db);

            Assert.IsTrue(_handler.IsIgnored("test.a"));
        }
Exemplo n.º 4
0
        private void UpdateSingleFile(string file)
        {
            TreeEntry treeEntry = null;
            var       commit    = Repository.Head.CurrentCommit;

            _tree = commit != null ? commit.Tree : null;
            if (_tree != null)
            {
                treeEntry = _tree.FindBlobMember(file);
            }

            _index = Repository.Index.GitIndex;
            _index.RereadIfNecessary();
            GitIndex.Entry indexEntry = _index.GetEntry(file);

            TreeEntry wdirEntry = null;
            FileInfo  fileInfo  = new FileInfo(Path.Combine(Repository.WorkingDirectory, file.Replace('/', Path.DirectorySeparatorChar)));

            if (fileInfo.Exists && !IgnoreHandler.IsIgnored(file))
            {
                var tree = new Core.Tree(Repository._internal_repo);
                wdirEntry = tree.AddFile(file);
            }

            OnVisitEntry(treeEntry, wdirEntry, indexEntry, fileInfo);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Recalculates the status
        /// </summary>
        public void Update()
        {
            AnyDifferences = false;
            Added          = new HashSet <string>();
            Staged         = new HashSet <string>();
            Removed        = new HashSet <string>();
            Missing        = new HashSet <string>();
            Modified       = new HashSet <string>();
            Untracked      = new HashSet <string>();
            MergeConflict  = new HashSet <string>();
            IgnoreHandler  = new IgnoreHandler(Repository);

            if (_file_path != null)
            {
                UpdateSingleFile(_file_path);
            }
            else if (_recursive)
            {
                UpdateDirectoryRecursive(_root_path);
            }
            else
            {
                UpdateDirectoryNotRecursive(_root_path);
            }
        }
Exemplo n.º 6
0
        public void TestNegated()
        {
            WriteIgnore(".", "*.o");
            WriteIgnore("test", "!*.o");
            _handler = new IgnoreHandler(db);

            Assert.IsFalse(_handler.IsIgnored("test/test.o"));
        }
Exemplo n.º 7
0
        public void PatternsWithPathComponent()
        {
            WriteIgnore(".", "foo/bar/*.o");             // <--- should ignore all o files only in foo/bar
            _handler = new IgnoreHandler(db);

            Assert.IsFalse(_handler.IsIgnored("test.o"));
            Assert.IsFalse(_handler.IsIgnored("a/file/somewhere/down/the/hierarchy/test.o"));
            Assert.IsTrue(_handler.IsIgnored("foo/bar/down/the/hierarchy/test.o"));
            Assert.IsTrue(_handler.IsIgnored("foo/bar/baz.o"));
        }
Exemplo n.º 8
0
 internal RepositoryStatus(Repository repository, RepositoryStatusOptions options, string singleFile, string rootDir, bool recursive)
 {
     Repository = repository;
     Options    = options ?? new RepositoryStatusOptions {
         ForceContentCheck = true
     };
     IgnoreHandler = new IgnoreHandler(Repository);
     _root_path    = Repository.ToGitPath(rootDir);
     _recursive    = recursive;
     _file_path    = Repository.ToGitPath(singleFile);
     Update();
 }
Exemplo n.º 9
0
        public void MultipleIgnoreFiles()
        {
            WriteIgnore(".", "*.o");
            WriteIgnore("./foo/bar", "baz");
            _handler = new IgnoreHandler(db);

            Assert.IsTrue(_handler.IsIgnored("test.o"));
            Assert.IsTrue(_handler.IsIgnored("a/file/somewhere/down/the/hierarchy/test.o"));
            Assert.IsTrue(_handler.IsIgnored("foo/bar/down/the/hierarchy/baz"));
            Assert.IsTrue(_handler.IsIgnored("foo/bar/baz"));
            Assert.IsFalse(_handler.IsIgnored("baz"));
            Assert.IsFalse(_handler.IsIgnored("a/file/somewhere/down/the/hierarchy/baz"));
        }
Exemplo n.º 10
0
        private void UpdateDirectoryNotRecursive(string path)
        {
            _index = Repository.Index.GitIndex;

            // Tree that will hold the working dir file entries
            var wtree = new Core.Tree(Repository._internal_repo);

            // Get a list of a leaves in the path

            Tree commitTree = null;
            var  commit     = Repository.Head.CurrentCommit;

            commitTree = commit != null ? commit.Tree : null;
            if (commitTree != null)
            {
                commitTree = commitTree[path] as Tree;
            }

            Dictionary <string, Leaf> commitEntries;

            if (commitTree != null)
            {
                commitEntries = commitTree.Leaves.ToDictionary(l => l.Path);
            }
            else
            {
                commitEntries = new Dictionary <string, Leaf> ();
            }

            HashSet <string> visited = new HashSet <string> ();

            // Compare commited files and working tree files

            DirectoryInfo dir = new DirectoryInfo(Repository.FromGitPath(path));

            if (dir.Exists)
            {
                foreach (FileInfo fileInfo in dir.GetFiles())
                {
                    string file = path + "/" + fileInfo.Name;

                    Leaf lf;
                    if (commitEntries.TryGetValue(file, out lf))
                    {
                        // Remove from the collection. At the end of the loop, entries still remaining in the
                        // collection will be processed as not having a corresponding working dir file
                        commitEntries.Remove(file);
                    }

                    TreeEntry wdirEntry = null;
                    if (!IgnoreHandler.IsIgnored(file) && fileInfo.Exists)
                    {
                        wdirEntry = wtree.AddFile(file);
                    }

                    GitIndex.Entry indexEntry = _index.GetEntry(file);

                    OnVisitEntry(lf != null ? lf.InternalEntry : null, wdirEntry, indexEntry, fileInfo);
                    visited.Add(file);
                }
            }

            // Now visit entries for which a working dir file was not found

            foreach (var lf in commitEntries)
            {
                string         file       = lf.Key;
                FileInfo       fileInfo   = new FileInfo(Repository.FromGitPath(file));
                GitIndex.Entry indexEntry = _index.GetEntry(file);
                OnVisitEntry(lf.Value.InternalEntry, null, indexEntry, fileInfo);
                visited.Add(file);
            }

            // Finally, visit remaining index entries which are not in the working dir nor in the commit

            foreach (var ie in _index.Members)
            {
                string file = ie.Name;
                // Exclude entries in subdirectories of _root_path
                int    i    = file.LastIndexOf('/');
                string fdir = i != -1 ? file.Substring(0, i) : string.Empty;
                if (fdir == _root_path && !visited.Contains(file))
                {
                    OnVisitEntry(null, null, ie, new FileInfo(Repository.FromGitPath(file)));
                }
            }
        }