Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use all relevant ignore files in archive matcher #139

Closed
wants to merge 1 commit into from

Commits on Apr 9, 2023

  1. Use all relevant ignore files in archive matcher

    The main idea is that there's a struct that knows about:
    
     -  The project root directory.
    
     -  All ignore files in the project.
    
    This is the `Project` struct defined in `internal/project.go`.
    
    Then, this project has an `UpdateIgnoreFiles` method, and an
    `ArchiveMatcher` method.
    
    The `UpdateIgnoreFiles` method walks from the root of the project, and
    tries to find all ignore files. When it finds one, it "registers" it in
    the `project` struct.
    
    The `ArchiveMatcher` method returns a closure that receives a path, and
    returns `false` if the path is ignored, or `true` otherwise.
    
    The `ArchiveMatcher` method expects a path as an argument (a "reference
    path"), indicating that the closure will receive paths relative to this
    reference path.
    
    This is needed because the ignore files (`.gitignore`,
    `.terraformignore`) can only match paths relative to their same
    directory, or below, but we have no guarantee that the closure will
    receive paths that are either absolute, or relative to the project root;
    so that's why we can't just have an `ArchiveMatcher` that receives no
    arguments, because we need to know the location of the file relative to
    the ignore file.
    
    `internal/ignorefiles.go`
    =========================
    
    Defines `IgnoreFile` interface and its `gitignoreFile` implementation.
    
    `internal/local_preview.go`
    ===========================
    
    Remove unused `GetIgnoreMatcherFn` function, replaced with the
    `*Project.ArchiveMatcher` method.
    
    `internal/paths.go`
    ===================
    
    Contains only convenience methods.
    
    `internal/project.go`
    =====================
    
    Contains the `Project` struct.
    
    I considered making it an interface, but it seemed like a premature
    optimization.
    
    NOTE: The methods of the `Project` struct are NOT thread-safe.
    c032 committed Apr 9, 2023
    Configuration menu
    Copy the full SHA
    609c747 View commit details
    Browse the repository at this point in the history