Skip to content

fix: file target bug with searchpattern and matchpattern#7614

Closed
josill wants to merge 5 commits intoupdatecli:mainfrom
josill:fix/file-target-bug
Closed

fix: file target bug with searchpattern and matchpattern#7614
josill wants to merge 5 commits intoupdatecli:mainfrom
josill:fix/file-target-bug

Conversation

@josill
Copy link
Contributor

@josill josill commented Jan 26, 2026

Fix #1860

Fix inconsistent behavior when using searchpattern: true with matchpattern where no files match the content pattern.

Changes

  • Fixed: When searchpattern: true is used with matchpattern and all files are filtered out (no matches), the target now returns an error instead of silently skipping
  • Consistency: Both searchpattern: false and searchpattern: true now fail consistently when no files match the pattern

Test

To test this pull request, you can run the following commands:

cd pkg/plugins/resources/file
go test -v

Additional Information

Tradeoff

The change modifies behavior for users who relied on the previous silent skip when no files matched with searchpattern: true. However, this was inconsistent with the behavior when searchpattern: false, and the issue maintainer confirmed this was a bug that should be fixed.

Potential improvement

A future enhancement could add a matchatleast parameter to allow specifying a minimum number of files that must match before the operation succeeds, providing more flexibility for users who need partial matching scenarios.

@olblak olblak changed the title Fix/file target bug fix: file target bug with searchpattern and matchpattern Jan 27, 2026
@olblak olblak added bug Something isn't working resource-file Resource of kind File labels Jan 27, 2026
@olblak olblak requested a review from Copilot January 27, 2026 16:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses an inconsistent behavior in the file target when using searchpattern: true with matchpattern, where no files match the content pattern. The PR also includes unrelated changes to add new pipeline commands.

Changes:

  • Fixed file target to return an error instead of silently skipping when searchpattern: true is used with matchpattern and all files are filtered out
  • Added new pipeline apply and pipeline diff commands as alternatives to the existing apply and diff commands
  • Deprecated existing apply and diff commands with warning messages

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/plugins/resources/file/target.go Changed to return error instead of SKIPPED result when no files match criteria with SearchPattern enabled
pkg/plugins/resources/file/target_test.go Added test cases for the bug fix and updated test infrastructure to support SearchPattern tests
cmd/pipeline.go New parent command for pipeline subcommands
cmd/pipeline_apply.go New command implementing pipeline apply functionality
cmd/pipeline_diff.go New command implementing pipeline diff functionality
cmd/apply.go Added deprecation warning and updated Short description
cmd/diff.go Added deprecation warning and updated Short description
cmd/root.go Integrated new pipeline commands into switch cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +517 to +530
// Update mockedContents to use temp directory paths
updatedContents := make(map[string]string)
for fileName, content := range tt.mockedContents {
updatedContents[filepath.Join(tempDir, fileName)] = content
}
tt.mockedContents = updatedContents
// Update wantedContents to use temp directory paths
if tt.wantedContents != nil {
updatedWantedContents := make(map[string]string)
for fileName, content := range tt.wantedContents {
updatedWantedContents[filepath.Join(tempDir, fileName)] = content
}
tt.wantedContents = updatedWantedContents
}
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test setup mutates the test table struct (tt) directly by modifying tt.mockedContents and tt.wantedContents. This is problematic because it can lead to unexpected behavior and makes tests harder to understand. Instead, create new local variables for the modified paths and use those when setting up the test. This also avoids potential issues if tests are run in parallel in the future.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +12
package cmd

import (
"github.com/spf13/cobra"
)

var (
pipelineCmd = &cobra.Command{
Use: "pipeline",
Short: "pipeline executes specific pipeline tasks such as diff or apply",
}
)
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR includes unrelated changes to add new pipeline commands (pipeline apply and pipeline diff) and deprecate existing commands. These changes should be in a separate PR as they are not related to the file target bug fix described in the PR title and description. The PR should focus solely on fixing the file target bug with searchpattern and matchpattern.

Copilot uses AI. Check for mistakes.
// Create the files that will be matched by the pattern
for fileName := range tt.files {
filePath := filepath.Join(tempDir, fileName)
if err := os.WriteFile(filePath, []byte(""), 0644); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err := os.WriteFile(filePath, []byte(""), 0644); err != nil {
if err := os.WriteFile(filePath, []byte(""), 0600); err != nil {

@josill josill marked this pull request as draft January 29, 2026 08:41
eugenestarchenko and others added 4 commits January 29, 2026 10:52
…ecli#7506)

* fix(terragrunt): add missing username for token authentication

  Fix token-only authentication by providing username default for go-git.

  PR updatecli#7359 added token support but token-only auth fails because go-git
  requires non-empty username for HTTP BasicAuth. This fix adds:

  - Username *string field to Spec with oauth2 default
  - getUsername() method matching GitHub SCM plugin behavior
  - Updated manifest template to include username field
  - Test coverage for getUsername()

  Fixes token authentication added in updatecli#7359

* fix(terragrunt):Fixes test failure introduced by adding username support

* fix(terragrunt): only include username when token is configured

* fix(terragrunt): return empty username when token not configured

---------

Co-authored-by: Olivier Vernin <[email protected]>
…#7571)

Made with ❤️️ by updatecli

Co-authored-by: updateclibot[bot] <92153806+updateclibot[bot]@users.noreply.github.com>
@josill josill force-pushed the fix/file-target-bug branch from 9aed10e to 43ea63d Compare January 29, 2026 08:53
@josill josill closed this Jan 29, 2026
@josill josill deleted the fix/file-target-bug branch January 29, 2026 08:55
@josill josill restored the fix/file-target-bug branch January 29, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working resource-file Resource of kind File

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent behaviour of file target

4 participants