Wildmatch Matching and Flag Behavior in Runex

This document explains what happens when our wildmatch function is called and how it behaves with respect to different flags, especially WM_PATHNAME. We also cover WM_UNICODE and WM_CASEFOLD briefly. Finally, we discuss how this logic integrates with our core module to strictly enforce Git’s .gitignore rules.


Overview of Wildmatch

The wildmatch function (a wrapper around the recursive dowild function) is responsible for matching wildcard patterns against text (typically filenames or paths). It supports:

Our implementation also supports three key flags:


Understanding WM_PATHNAME

Git’s .gitignore Behavior

In Git, a pattern that does not contain a slash is considered a “global” pattern. For example, if your .gitignore contains:

*.txt

Git will ignore any file ending in .txt regardless of its directory. That means both files in the root and files in any subdirectory will match. For example, consider the following directory structure:

.
├── file.txt
└── subdir
    └── file.txt

With a .gitignore containing *.txt, Git ignores both file.txt and subdir/file.txt.

How Wildmatch Handles WM_PATHNAME

Why This Matters

Our core.py module uses our wildmatch logic to filter files and directories based on .gitignore rules. Git’s default behavior is to treat a pattern like *.txt as matching any .txt file anywhere in the directory tree (because Git implicitly treats such patterns as if they were prefixed by **/). Therefore, in our integration:


Example Comparison

Directory Structure

Consider the following project tree:

.
├── file.txt
├── image.png
└── docs
    ├── manual.txt
    └── readme.md

.gitignore Content

*.txt

Matching Behavior

  1. Default Behavior (WM_PATHNAME Off):
    • Pattern: *.txt
    • Matches:
      • file.txt (in the root)
      • docs/manual.txt (in a subdirectory)
    • Outcome: Both files are ignored, which is the expected Git behavior.
  2. With WM_PATHNAME Enabled:
    • Pattern: *.txt
    • Matches:
      • file.txt (in the root)
      • Does not match: docs/manual.txt because * will not match the / in docs/manual.txt.
    • Outcome: Only file.txt would be ignored, which deviates from Git’s expected behavior.

Integration with core.py

In our core.py module, when scanning the project structure against .gitignore rules:


Summary

This document should help developers understand both the internal workings of this wildmatch implementation in python and its integration with the rest of the system to enforce .gitignore rules.