dvc: dvc and git does not behave the same with "!" and "**"
Consider the following project structure
- data
- data1
- file1
- file1.dvc
- data2
- file2
- file2.dvc
- data1
- .gitignore
.gitignore
is as follows:
data/**
!data/*/
!*.dvc
git status
gives:
while dvc push
gives:
I expect to git and dvc behave the same with gitignore.
- dvc: 2.8.3
- python: 3.7
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 18 (8 by maintainers)
@pmrowla Do we need to open a dulwich issue for this?
Sorry for late reply.
While in
dvc add data/data2/b
And if we change
!data/*/
to!data/**/
So I guess there are two problems:
While for the Git:
They give the same result.
add
work properly whilepush
andcommit
are not)And for the logic of gitignore, the following from the thread is quite clear I think
Git opens and reads the working tree directory. For each file or directory that is actually present here, Git checks it against the ignore rules. Some rules match only directories and others match both directories and files. Some rules say “do ignore” and some say “do not ignore”.
The last applicable rule wins.
If this is a file and the file is ignored, it’s ignored. Unless, that is, it’s in the index already, because then it’s tracked and can’t be ignored.
If this is a directory and the directory is ignored, it’s not even opened and read. It’s not in the index because directories are never in the index (at least nominally). If it is opened and read, the entire set of rules here apply recursively.
Whether it is was a bug or a bug fix, some commits reverted, and a test case added 😃
By the way, I think there is a separate issue with dvc.
In our testcase, if we re-include ‘data1’ directory by
!data/*/
, dvc ignores.dvc
files insidedata1
; but if it is done by!data/**/
, dvc behaves as expected.In either of cases,
.dvc
files insidedata1
directory are not ignored by git and thecheck-ignore
output is as follows:I used another git version, 2.17.1.
If I have understood correctly,
.dvc
files are ignored in neither of my nor dulwich’s format; but I don’t get why dvc does not see.dvc
files in my format.Here is the thread.
Not yet. However, I’ve just sent an email to git mailing list, describing the issue.