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

Conversation

c032
Copy link

@c032 c032 commented Apr 9, 2023

I tried doing #138 to pass time. Most explanation is in the commit message.

But for a quick skim, start at the diff for internal/cmd/module/local_preview.go or internal/cmd/stack/local_preview.go. Specifically at the matchFn function.

I cannot test this because I don't have an account, and the free account sounds like a 14-day trial.

Also I'm probably missing a lot of context from the project so it's likely I'm overcomplicating this.

I hope this PR is at least a bit helpful, but if not, feel free to reject.


Also, I could not build the project at first because the required version of github.com/marcinwyszynski/graphql didn't exist (!?). I had to fix it before I could even build the main branch.

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
Copy link
Author

c032 commented May 11, 2023

Abandoning.

@c032 c032 closed this May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant