Skip to content

fix(watch): respect nested ignores during initial sync - #14441

Open
ahbaqdadi wants to merge 1 commit into
docker:mainfrom
ahbaqdadi:fix/watch-initial-sync-ignore
Open

ahbaqdadi wants to merge 1 commit into
docker:mainfrom
ahbaqdadi:fix/watch-initial-sync-ignore

Conversation

@ahbaqdadi

@ahbaqdadi ahbaqdadi commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

Makes develop.watch.initial_sync respect nested develop.watch.ignore and .dockerignore paths so excluded files are not copied into the container.

Related issue

Fixes #14439

Changes made

  • Match ignore rules against full host paths and root single-file triggers at their parent directory.
  • Preserve .git, Dockerfile, and Compose file exclusions at any depth; keep walking ignored directories when a negated rule includes a child.
  • Add regression tests for nested rules, .dockerignore, negated ignore patterns, single-file triggers, and fully ignored directories.

Testing done

  • Unit tests: make test
  • E2E: DOCKER_CONTEXT=desktop-linux make e2e-compose-standalone E2E_TEST='^TestWatchLegacyXInitialSync$'
  • Lint: make lint (0 issues)
  • Format: make fmt
  • Validation: make validate in an identical standalone clone (the linked worktree's .git pointer is unavailable to its Docker vendor check)
  • Manual reproduction: both ignore sources copied an excluded file on Compose v5.6.1; the patch is covered by the tests above

Scope and follow-up

This PR aligns initial sync's develop.watch.ignore and .dockerignore handling with live watch. Initial sync still does not apply develop.watch.include; sharing the watch rule construction between the two paths is a separate follow-up.

Open PR #14217 also touches watch ignore handling and may require a rebase.

Signed-off-by: Amir Baqdadi <ahbaqdadi@gmail.com>
@ahbaqdadi
ahbaqdadi marked this pull request as ready for review November 3, 2026 09:47
@ahbaqdadi
ahbaqdadi requested review from a team as code owners November 3, 2026 09:47
@ahbaqdadi
ahbaqdadi requested review from glours and ndeloof November 3, 2026 09:47
@ndeloof

ndeloof commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for this. Aligning initial_sync with what live watch does is exactly the behavior we want: a file that watch would ignore should not be copied when the service starts either. Evaluating the full host path against develop.watch.ignore and .dockerignore is the right direction, so the changes proposed here go the right way.

One thing worth keeping in mind, though: even with this PR the two are not strictly equivalent, because the initial sync still re-implements the rules instead of sharing them. develop.watch.include is a good illustration. Live watch applies it first (watchRule.Matches, built in getWatchRules), so a file outside include is never synced. initialSync never consults trigger.Include, so with include: ["*.py"] it still copies files that watch would never have sent.

That is the same kind of mismatch as #14439, and it does not have to be solved here. It would be good to say in the description that this PR aligns the ignore / .dockerignore handling only, so the remaining gap is not mistaken for something it covers. Making the initial sync build its rules from the same place as live watch would be the durable fix, in a follow-up.

@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/compose/watch.go 75.00% 2 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
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.

[BUG] initial_sync copies files excluded by nested watch ignore rules

2 participants