예제 #1
0
        public void File_Rule_Line_Numbers_ToString()
        {
            var log = new IgnoreLog();

            var list = new IgnoreList(new string[] { "*.cs" });

            list.AddRules(_basePath + "/multiplematch.gitignore");

            var paths = new List <string> {
                "test/test1.cs", "test/test2.cs"
            };

            paths.ForEach(path => list.IsIgnored(path, true, log));

            const string expectedResult = @"test/test1.cs
    IGNORED by *.cs
    INCLUDED by !test/*.cs (line 3)
    IGNORED by test/test*.cs (line 4)

test/test2.cs
    IGNORED by *.cs
    INCLUDED by !test/*.cs (line 3)
    IGNORED by test/test*.cs (line 4)
    INCLUDED by !test/test2.cs (line 6)";

            Assert.IsTrue(log.ToString() == expectedResult);
        }
예제 #2
0
        public void Add_Rules_From_File()
        {
            var ignoreList = new IgnoreList(new string[] { "README.txt" });

            ignoreList.AddRules(_basePath + @"\loadfromfile.gitignore");
            Assert.IsTrue(ignoreList.IsIgnored("README.txt", true));
            Assert.IsFalse(ignoreList.IsIgnored("test.jpg", true));
            Assert.IsTrue(ignoreList.IsIgnored("test.cs", true));
        }
예제 #3
0
        public void Ignore_After_Dynamic_Add()
        {
            var ignoreList = new IgnoreList(new List <string> {
                "README1.txt"
            });

            ignoreList.AddRule("README2.txt");
            ignoreList.AddRules(new List <string> {
                "README3.txt", "README4.txt"
            });
            Assert.IsTrue(ignoreList.IsIgnored("README1.txt", true));
            Assert.IsTrue(ignoreList.IsIgnored("README2.txt", true));
            Assert.IsTrue(ignoreList.IsIgnored("README3.txt", true));
            Assert.IsTrue(ignoreList.IsIgnored("README4.txt", true));
        }
예제 #4
0
        public GitIgnoreService(ILogger <GitIgnoreService> logger)
        {
            try
            {
                _ignoreList = new IgnoreList();

                var gitIgnoreFiles = Directory.GetFiles(@".\Resources\GitIgnores");
                foreach (var gitIgnoreFile in gitIgnoreFiles)
                {
                    _ignoreList.AddRules(gitIgnoreFile);
                }

                _isInitialized = true;

                logger.LogInformation("GitIgnore inicializado con {Files}",
                                      gitIgnoreFiles.Length);
            }
            catch (Exception ex)
            {
                _isInitialized = false;

                logger.LogError(ex, "No fue posible inicializar GitIgnore");
            }
        }