Skip to content

Feature request: Exclude files based on .gitignore from anywhere in git repo #536

@HastD

Description

@HastD

Problem

Suppose $root is the root directory of a git repository, and a .gitignore file exists at $root/.gitignore. If ugrep is run from $root with the --ignore-files option, it will exclude files in accordance with this .gitignore, consistent with how git excludes those files. However, if ugrep is run from a subdirectory of $root, since the .gitignore file is no longer in the working directory, ugrep doesn't take it into account, which means search results from files that should be ignored will show up.

(For a concrete example: a repository with Python code will often end up with a bunch of scattered __pycache__ directories and .pyc files that are usually included in the .gitignore, and these can clutter search results.)

Proposed solution

It would be nice for ugrep to have an option to search for .gitignore patterns using the same rules as git itself, in particular:

Patterns read from a .gitignore file in the same directory as the path, or in any parent directory (up to the top-level of the working tree), with patterns in the higher level files being overridden by those in lower level files down to the directory containing the file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions