Skip to content

add: repeated --glob includes generated DVC metadata #11086

Description

@tandede

Bug Report

Description

Running the same dvc add --glob command twice fails when the pattern also matches the .dvc files created by the first run. The first run tracks the data successfully; the second expands both the original data paths and their generated stage files, then tries to add a stage file as data.

Reproduce

git init -q repo
cd repo
dvc init -q
mkdir data
printf "one\n" > data/one
printf "two\n" > data/two

dvc add --glob "data/*"
dvc add --glob "data/*"

The second command exits with status 1:

ERROR: DVC file 'one.dvc' cannot be an output.

This also prevents the common update workflow where new files are added to the directory and the same glob command is rerun to update existing matches and add the new ones.

Expected

Wildcard expansion for dvc add --glob should ignore DVC metadata (*.dvc, dvc.yaml, and dvc.lock) because those paths cannot be DVC outputs. Explicitly passing a metadata path should remain invalid and retain the existing error.

Analysis

dvc.repo.add.find_targets() currently passes every filesystem glob match to get_or_create_stage(). On the second invocation, generated stage files are therefore treated as new output targets and rejected by output-path validation.

Environment

DVC main at 56e59829, Python 3.13, macOS arm64.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions