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

sourceignore: make a copy of domain for pattern #512

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

darkowlzz
Copy link
Contributor

LoadIgnorePatterns() modified the domain string slice after creating ignore pattern, due to which the domain of certain patterns created below the first directory level with multiple directories at the same level resulted in the patterns to have the domain of the last directory in the same directory level.

This is fixed by making a copy of the domain before creating a pattern.

Refer https://yourbasic.org/golang/gotcha-append/ for details about this side effect of appending slices.

Refer https://github.com/hiddeco/proof/tree/different-tree for an example repository to reproduce this issue.
podinfo2/.sourceignore contains *.

Without the fix, the artifact contains

flux
flux/apps
flux/apps/staging
flux/apps/staging/tests
flux/apps/staging/tests/podinfo1
flux/apps/staging/tests/podinfo1/podinfo-deploy.yaml
flux/apps/staging/tests/podinfo2
flux/apps/staging/tests/podinfo2/.sourceignore
flux/apps/staging/tests/podinfo2/podinfo-deploy.yaml
flux/apps/staging/tests/podinfo3

With the fix, the artifact contains

flux
flux/apps
flux/apps/staging
flux/apps/staging/tests
flux/apps/staging/tests/podinfo1
flux/apps/staging/tests/podinfo1/podinfo-deploy.yaml
flux/apps/staging/tests/podinfo2
flux/apps/staging/tests/podinfo3
flux/apps/staging/tests/podinfo3/podinfo-deploy.yaml

@darkowlzz darkowlzz added the bug Something isn't working label Mar 15, 2023
@darkowlzz darkowlzz requested a review from hiddeco as a code owner March 15, 2023 11:43
@darkowlzz darkowlzz force-pushed the ignore-pattern-domain-side-effect branch from 6fd0140 to 7f650b5 Compare March 15, 2023 11:45
LoadIgnorePatterns() modified the domain string slice after creating
ignore pattern, due to which the domain of certain patterns created
below the first directory level with multiple directories at the same
level resulted in the patterns to have the domain of the last directory
in the same directory level.

This is fixed by making a copy of the domain before creating a pattern.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
@darkowlzz darkowlzz force-pushed the ignore-pattern-domain-side-effect branch from 7f650b5 to 1cf9c3b Compare March 15, 2023 12:17
@@ -222,7 +224,7 @@ func TestLoadExcludePatterns(t *testing.T) {
name: "traverse loads",
dir: tmpDir,
want: []gitignore.Pattern{
gitignore.ParsePattern("root.txt", nil),
gitignore.ParsePattern("root.txt", []string{}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the copied domain, the DeepEqual below fails when this domain is nil, even though all the components of the pattern are exactly the same.

@darkowlzz darkowlzz merged commit 9011841 into main Mar 16, 2023
@darkowlzz darkowlzz deleted the ignore-pattern-domain-side-effect branch March 16, 2023 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants