Repository navigation
Conversation
`dvc stage add --force` only added the new stage's outputs to .gitignore. Outputs the overwritten stage had but the new one doesn't stayed ignored. Load the stage being replaced and un-ignore the outputs that are gone. Fixes treeverse#6036 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Fixes #6036
Bug
dvc stage add --force(anddvc run --force) replaces a stage indvc.yaml, but the outputs the old stage had and the new one doesn't stay in.gitignore:I reproduced this on current
mainwith the Python API (repo.stage.add(..., force=True)).Cause
StageLoad.adddumps the new stage and callsstage.ignore_outs()for its outputs only. The stage it overwrites is never looked at, so its dropped outputs are never un-ignored.dvc removedoes un-ignore them (viaOutput.ignore_remove).Fix
When
forceis set and the stage being written already exists indvc.yaml, load the old stage before it is overwritten. After the new stage is dumped, callignore_remove()on every old output whose path is not an output of the new stage. Only pipeline stages (dvc.yaml) are handled, since the issue is aboutdvc stage add. Without--forcenothing changes.Tests
New
test_stage_add_force_drops_replaced_outs_from_gitignoreintests/func/test_stage.py. It fails onmainand passes with this change.tests/func/test_stage.pyandtests/func/test_run.pypass locally (76 passed).ruff checkandruff format --checkare clean.❗ I have followed the Contributing to DVC checklist.
📖 If this PR requires documentation updates, I have created a separate PR (or issue, at least) in dvc.org and linked it here. (No docs change needed.)
🤖 Generated with Claude Code