public void AcceptShouldAcceptTheGivenFilenames()
 {
     _gitignore.Accepts("test/index.js").Should().BeTrue();
     _gitignore.Accepts("wat/test/index.js").Should().BeTrue();
     _gitignore.Accepts("/othernonexistent/blah/adsasd/whatads").Should().BeTrue();
     _gitignore.Accepts("/othernonexistent/blah/adsasd/what/foo").Should().BeTrue();
     _gitignoreNoNegatives.Accepts("test/index.js").Should().BeTrue();
 }
        private static void InternalListIncludedFiles(GitIgnoreParser ignoreParser)
        {
            if (ignoreParser == null)
            {
                ColoredConsole.Error.WriteLine("No .funcignore file");
                return;
            }

            foreach (var file in GetFiles(Environment.CurrentDirectory).Select(f => f.Replace(Environment.CurrentDirectory, "").Trim(Path.DirectorySeparatorChar).Replace("\\", "/")))
            {
                if (ignoreParser.Accepts(file))
                {
                    ColoredConsole.WriteLine(file);
                }
            }
        }
        private static Stream CreateZip(string path, GitIgnoreParser ignoreParser)
        {
            var memoryStream = new MemoryStream();

            using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, leaveOpen: true))
            {
                foreach (var fileName in GetFiles(path))
                {
                    if (ignoreParser?.Accepts(fileName.Replace(path, "").Trim(Path.DirectorySeparatorChar).Replace("\\", "/")) ?? true)
                    {
                        zip.AddFile(fileName, fileName, path);
                    }
                }
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return(memoryStream);
        }
Beispiel #4
0
        public static IEnumerable <string> GetLocalFiles(string path, GitIgnoreParser ignoreParser = null, bool returnIgnored = false)
        {
            var ignoredDirectories = new[] { ".git", ".vscode" };
            var ignoredFiles       = new[] { ".funcignore", ".gitignore", "appsettings.json", "local.settings.json", "project.lock.json" };

            foreach (var file in FileSystemHelpers.GetFiles(path, ignoredDirectories, ignoredFiles))
            {
                if (preCondition(file))
                {
                    yield return(file);
                }
            }

            bool preCondition(string file)
            {
                var fileName = file.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar).Replace("\\", "/");

                return((returnIgnored ? ignoreParser?.Denies(fileName) : ignoreParser?.Accepts(fileName)) ?? true);
            }
        }
Beispiel #5
0
        private static StreamContent CreateZip(string path, GitIgnoreParser ignoreParser)
        {
            var memoryStream = new MemoryStream();

            using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, leaveOpen: true))
            {
                foreach (var fileName in GetFiles(path))
                {
                    if (ignoreParser?.Accepts(fileName.Replace(path, "").Trim(Path.DirectorySeparatorChar).Replace("\\", "/")) ?? true)
                    {
                        zip.AddFile(fileName, fileName, path);
                    }
                }
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            var content = new StreamContent(memoryStream);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
            return(content);
        }
 public void AcceptShouldAcceptTheGivenFilenames()
 {
     _gitignore.Accepts("test/index.js").Should().BeTrue();
     _gitignore.Accepts("wat/test/index.js").Should().BeTrue();
     _gitignoreNoNegatives.Accepts("test/index.js").Should().BeTrue();
 }