Repository navigation
fix(streamer): match .gitignore patterns against source-relative paths - #418
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
The tar helper used by `shp build upload` compared every file against the `.gitignore` found in the source directory using the file's full path on disk, e.g. `/home/me/work/src/app/main.go`, instead of its path inside the source directory, `main.go`. Git evaluates patterns relative to the directory holding the `.gitignore`, so this caused two problems: - a pattern matching a parent directory of the source directory dropped every file, e.g. `src/` with the project at `.../src/app` resulted in an empty upload and a build failing with `DockerfileNotFound`; - anchored patterns such as `/build` or `/dist` never matched, so those top-level directories were always uploaded. skipPath already computes the source-relative path to detect `.git` path components, so reuse it for the `.gitignore` matcher as well. Add a unit test that creates a source directory nested in a directory named `src` and checks that only the expected files end up in the tar. Fixes shipwright-io#417 Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
shp build uploadchecks every file against the.gitignorein the source directory, but it passed the file's full path on disk toMatchesPath(e.g./home/me/work/src/app/main.go) rather than the path inside the source directory (main.go). Git evaluates patterns relative to the directory holding the.gitignore, so:src/in.gitignoreand the project at.../src/app, the upload was empty and the build failed withDockerfileNotFound./buildor/distnever matched, so those top-level directories were always uploaded.skipPathalready computes the source-relative path for the.gitcheck, so the.gitignorematcher now uses that same path, as suggested in the issue.A new unit test builds a source directory nested under a directory named
src, withsrc/,/buildand*.logpatterns. It checks that only the expected files are in the tar:sub/build/is kept, andbuild/,sub/src/and the.logfiles are left out. The test fails onmainbecause nothing is uploaded there.Related Issue
Fixes #417
Type of PR
/kind bug
Submitter Checklist
The existing docs already describe the intended behavior, so no docs change is needed.
See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.
Release Notes