Skip to content

fix(streamer): match .gitignore patterns against source-relative paths - #418

Open
NopeCharon wants to merge 1 commit into
shipwright-io:mainfrom
NopeCharon:fix/gitignore-relative-path
Open

NopeCharon wants to merge 1 commit into
shipwright-io:mainfrom
NopeCharon:fix/gitignore-relative-path

Conversation

@NopeCharon

Copy link
Copy Markdown

Changes

shp build upload checks every file against the .gitignore in the source directory, but it passed the file's full path on disk to MatchesPath (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:

  • a pattern matching a parent of the source directory dropped every file. With src/ in .gitignore and the project at .../src/app, the upload was empty and the build failed 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 for the .git check, so the .gitignore matcher now uses that same path, as suggested in the issue.

A new unit test builds a source directory nested under a directory named src, with src/, /build and *.log patterns. It checks that only the expected files are in the tar: sub/build/ is kept, and build/, sub/src/ and the .log files are left out. The test fails on main because nothing is uploaded there.

Related Issue

Fixes #417

Type of PR

/kind bug

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Kind label has been set
  • Release notes block has been filled in, or marked NONE

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

`shp build upload` now matches `.gitignore` patterns against paths relative to the uploaded source directory, the same way `git` does. Patterns matching a parent directory of the source no longer exclude every file, and anchored patterns like `/build` now work.

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>
@openshift-ci openshift-ci Bot added release-note kind/bug Categorizes issue or PR as related to a bug. labels Oct 24, 2026
@pull-request-size pull-request-size Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 24, 2026
@openshift-ci

openshift-ci Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign heavywombat for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. release-note size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[BUG] shp build upload matches .gitignore patterns against the full path on disk

2 participants