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")); }
public void HonorsTopLevelIgnore() { WriteIgnore(".", "*.o"); _handler = new IgnoreHandler(db); Assert.IsTrue(_handler.IsIgnored("test.o")); }
public void HonorsConfigExcludes() { WriteConfigExcludes("ignoreHandler", "*.a"); _handler = new IgnoreHandler(db); Assert.IsTrue(_handler.IsIgnored("test.a")); }
public void HonorsExcludeFile() { WriteExclude("*.html"); _handler = new IgnoreHandler(db); Assert.IsTrue(_handler.IsIgnored("test.html")); }
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); }
public void TestNegated() { WriteIgnore(".", "*.o"); WriteIgnore("test", "!*.o"); _handler = new IgnoreHandler(db); Assert.IsFalse(_handler.IsIgnored("test/test.o")); }
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")); }
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))); } } }