コード例 #1
0
ファイル: IgnoreList.cs プロジェクト: flcdrg/MAB.DotIgnore
        private bool IsPathIgnored(string path, bool pathIsDirectory, IgnoreLog log)
        {
            // This pattern modified from https://github.com/henon/GitSharp/blob/master/GitSharp/IgnoreRules.cs
            var ignore = false;

            foreach (var rule in _rules)
            {
                if (rule.IsMatch(path, pathIsDirectory))
                {
                    ignore = !rule.PatternFlags.HasFlag(PatternFlags.NEGATION);

                    if (log != null)
                    {
                        if (!log.ContainsKey(path))
                        {
                            log.Add(path, new List <string>());
                        }

                        var entry = string.Format(
                            "{0} by {1}",
                            (rule.PatternFlags.HasFlag(PatternFlags.NEGATION) ? "INCLUDED" : "IGNORED"),
                            rule.ToString()
                            );

                        log[path].Add(entry);
                    }
                }
            }

            return(ignore);
        }
コード例 #2
0
        /// <summary>
        /// Check if a directory path matches any of the rules in the ignore list.
        /// </summary>
        /// <param name="directory">DirectoryInfo representing the file to check.</param>
        /// <param name="log">List of strings to append log messages to.</param>
        /// <returns>True if the directory path is ignored.</returns>
        public bool IsIgnored(DirectoryInfo directory, IgnoreLog log)
        {
            if (directory is null)
            {
                throw new ArgumentNullException(nameof(directory));
            }

            return(IsIgnored(directory.FullName, true, log));
        }
コード例 #3
0
        /// <summary>
        /// Check if a directory path matches any of the rules in the ignore list.
        /// </summary>
        /// <param name="file">FileInfo representing the file to check.</param>
        /// <param name="log">List of strings to append log messages to.</param>
        /// <returns>True if the file path is ignored.</returns>
        public bool IsIgnored(FileInfo file, IgnoreLog log)
        {
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            return(IsIgnored(file.FullName, false, log));
        }
コード例 #4
0
        private bool IsPathIgnored(string path, bool pathIsDirectory, IgnoreLog log)
        {
            var logAction = (log != null) ? LogAction : NoAction;

            // This pattern modified from https://github.com/henon/GitSharp/blob/master/GitSharp/IgnoreRules.cs
            var ignore = false;

            foreach (var rule in _rules)
            {
                if (rule.IsMatch(path, pathIsDirectory))
                {
                    ignore = !rule.PatternFlags.HasFlag(PatternFlags.NEGATION);
                    logAction(path, rule, log);
                }
            }

            return(ignore);
        }
コード例 #5
0
        /// <summary>
        /// Check if a string path matches any of the rules in the ignore list
        /// </summary>
        /// <param name="path">String representing the path to check</param>
        /// <param name="pathIsDirectory">Should be set True if the path represents a directory, False if it represents a file</param>
        /// <param name="log">List of strings to append log messages to</param>
        public bool IsIgnored(string path, bool pathIsDirectory, IgnoreLog log)
        {
            var pathIgnored = IsPathIgnored(path, pathIsDirectory, log);

            if (pathIsDirectory)
            {
                return(pathIgnored);
            }

            var ancestorIgnored = IsAnyParentDirectoryIgnored(path, log);

            if (ancestorIgnored)
            {
                return(true);
            }

            return(pathIgnored);
        }
コード例 #6
0
        private bool IsAnyParentDirectoryIgnored(string path, IgnoreLog log)
        {
            var segments = Utils.NormalisePath(path).Split('/').ToList();

            segments.RemoveAt(segments.Count - 1);

            var directory = new List <string>();

            // Loop over all the path segments (moving down the directory tree)
            // and test each as a directory, returning immediately if true
            foreach (var segment in segments)
            {
                directory.Add(segment);
                if (IsPathIgnored(string.Join("/", directory.ToArray()), true, log))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #7
0
 /// <summary>
 /// Check if a directory path matches any of the rules in the ignore list
 /// </summary>
 /// <param name="file">FileInfo representing the file to check</param>
 /// <param name="log">List of strings to append log messages to</param>
 public bool IsIgnored(FileInfo file, IgnoreLog log)
 {
     return(IsIgnored(file.FullName, false, log));
 }
コード例 #8
0
 /// <summary>
 /// Check if a directory path matches any of the rules in the ignore list
 /// </summary>
 /// <param name="directory">DirectoryInfo representing the file to check</param>
 /// <param name="log">List of strings to append log messages to</param>
 public bool IsIgnored(DirectoryInfo directory, IgnoreLog log)
 {
     return(IsIgnored(directory.FullName, true, log));
 }
コード例 #9
0
ファイル: IgnoreList.cs プロジェクト: nojaf/MAB.DotIgnore
 /// <summary>
 /// Check if a directory path matches any of the rules in the ignore list.
 /// </summary>
 /// <param name="directory">DirectoryInfo representing the file to check.</param>
 /// <param name="log">List of strings to append log messages to.</param>
 /// <returns>True if the directory path is ignored.</returns>
 public bool IsIgnored(DirectoryInfo directory, IgnoreLog log) =>
 IsIgnored(directory.FullName, true, log);
コード例 #10
0
ファイル: IgnoreList.cs プロジェクト: nojaf/MAB.DotIgnore
 /// <summary>
 /// Check if a directory path matches any of the rules in the ignore list.
 /// </summary>
 /// <param name="file">FileInfo representing the file to check.</param>
 /// <param name="log">List of strings to append log messages to.</param>
 /// <returns>True if the file path is ignored.</returns>
 public bool IsIgnored(FileInfo file, IgnoreLog log) =>
 IsIgnored(file.FullName, false, log);