grive2 icon indicating copy to clipboard operation
grive2 copied to clipboard

.griveignore not working as expected

Open eXcuvator opened this issue 6 years ago • 7 comments

I've created an empty folder, and added the following into a .griveignore:

/*
/*/
!/database

and then initialized sync via grive -a. However, it started adding all of the directories, not only database. I thought .griveignore worked analogous to .gitignore -- what am I missing?

eXcuvator avatar Jun 05 '18 09:06 eXcuvator

This is likely the same issue as #199

shaansheikh avatar Jul 10 '18 02:07 shaansheikh

It should work if you specify just

*
!database

If your example works in git, but not in grive - it seems I didn't implement gitignore 100% identically, but the principle is still the same :)

vitalif avatar Jul 28 '18 20:07 vitalif

I also have an issue with .griveignore not working as expected.

I cannot succeed in making something like

*
!database
database/.git

work. As soon as it sees !database, grive wants to sync everything inside database including .git that should be excluded.

callegar avatar Nov 07 '18 18:11 callegar

I think that "positive" patterns get interpreted incorrectly. Saying !database gets interpreted as include database and anything inside it and the anything inside it part ends up taking precedence over the exclude pattern for database/.git. However !database should only include database. Including anything inside database should be !database/**

callegar avatar Nov 07 '18 18:11 callegar

Infact, this is the case. The way in which patterns are turned into regular expressions is wrong. I have modified the grive source code to print the ignore regular expression that is generated and if you use a .griveignore file like:

*
!database
database/.git

you get

^(?!database)([^/]*|database/\.git)$|^\.(grive|grive_state|trash)

which is obviously not correct, because the initial lookahead item (?!database) prevents matching of anything that starts with database and not just database itself. This not only means that database/.git gets included. Also anything like database23 would be incorrectly included.

callegar avatar Nov 09 '18 10:11 callegar

How about adding a \Z at the end of the lookahead pattern?

callegar avatar Nov 09 '18 11:11 callegar

Ok, sorry, my master was not up to date. This is the reason for the closed pull request #237. However, I tried with the most recent master which is a bit better and still there is a problem, which is the reason for the new pull request #238.

Basically, if you use an include pattern for database, then there is no reason for it to mean get database and everything below it. For the latter you should say !database/**. Otherwise, there is no way to include database but then exclude some directory below database.

My pull request seems to do the job, but some more testing is probably needed.

callegar avatar Nov 09 '18 17:11 callegar