Skip to content

dvc init fails when .dvc directory is git-ignored #3738

@simongoertzen

Description

@simongoertzen

Tested on Windows (binary & pip install) in Windows Terminal (Powershell) and in Git Bash.

Issue
I tried to run "dvc init" in a repository that had an ".*" entry in its .gitignore. With -v flag, it fails with the following message:

Traceback (most recent call last):
  File "dvc\main.py", line 49, in main
  File "dvc\command\init.py", line 21, in run
  File "dvc\repo__init.py", line 155, in init
  File "dvc\repo\init.py", line 108, in init
  File "dvc\scm\git__init.py", line 194, in add
  File "site-packages\git\index\base.py", line 740, in add
  File "site-packages\git\util.py", line 68, in wrapper
  File "site-packages\git\index\util.py", line 91, in set_git_working_dir
  File "site-packages\git\index\base.py", line 626, in _entries_for_paths
  File "site-packages\git\index\base.py", line 587, in _store_path
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden: '.dvc\.gitignore'

Steps to reproduce:

  1. mkdir example
  2. cd example
  3. git init
  4. echo ".*" >> .gitignore
  5. dvc init -v # this fails!
    this is how I fixed it:
  6. echo "!.dvc" >> .gitignore
  7. dvc init -fv

What's confusing is that after step 5, .dvc exists and has a few items in there. .dvc/config is even committed to git. That's why I didn't consider that my .gitignore could have anything to do with it. I only figured out the reason with the help of skshetry in Discord (thanks!). It would have been helpful if there was a better error message, or the documentation would mention that ".dvc" can't be under .gitignore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDid we break something?enhancementEnhances DVCp3-nice-to-haveIt should be done this or next sprintuiuser interface / interaction

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions