Skip to content

.gitignore: /*.yaml rule hides tracked config files when module is vendored #339

@machine424

Description

@machine424

The repository's .gitignore contains /*.yaml, but the repo ships tracked .yaml files at the root: .golangci.yaml, .ls-lint.yaml, and .yamllint.yaml. Since they are already tracked, the rule is inert in this repo. This is misleading and may appear contradictory though.

The real issue surfaces downstream. When a consumer runs go mod vendor, all files including .gitignore are copied into their vendor/ directory. There, the .yaml files are untracked, so the /*.yaml rule kicks in and hides them.

This breaks vendor consistency checks; go mod vendor then git status --porcelain --ignored will fail when files are ignored in vendor/ (go mod vendor produces files that git would silently drop)

Reproducer

mkdir /tmp/test && cd /tmp/test
git init
go mod init example.com/test
cat > main.go <<'EOF'
package main

import _ "go.yaml.in/yaml/v4"

func main() {}
EOF
go mod tidy
go mod vendor
git status --porcelain --ignored -- vendor/

Output includes:

!! vendor/go.yaml.in/yaml/v4/.golangci.yaml
!! vendor/go.yaml.in/yaml/v4/.ls-lint.yaml
!! vendor/go.yaml.in/yaml/v4/.yamllint.yaml

Suggested fix

Add negation rules for the shipped .yaml files:

/*.yaml
!/.golangci.yaml
!/.ls-lint.yaml
!/.yamllint.yaml

The change to .gitignore was introduced in aeb7877

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions