deadc0de6 / dotdrop

Save your dotfiles once, deploy them everywhere
https://dotdrop.readthedocs.io
GNU General Public License v3.0
1.77k stars 105 forks source link

[bug] Negative (non-ignore) patterns refuse to match anything #388

Closed niraami closed 11 months ago

niraami commented 1 year ago

Dotdrop version: v1.13.0-1 Using dotdrop: dotdrop from AUR

Describe the bug

When using ignore patterns, I can't get the inverse ignore pattern working. Every time I add ignore for '*', all subsequent non-ignore patterns don't get applied.

Steps to Reproduce

Add the following kind of ignore pattern to a dotfile (my example is a Blender config directory):

d_blender_addons:
    src: config/blender
    dst: ~/.config/blender
    upignore:
    - '*'
    - '!*/addons/**'
    cmpignore:
    - '*'
    - '!*/addons/**'

Run dotdrop update --dry, you'll see the folders ignored (twice) anyways:

-> "d_blender_addons" ignored
-> "/home/niraami/.config/blender/3.0/scripts/addons" ignored
-> "/home/niraami/.config/blender/3.2/scripts/addons" ignored
-> "/home/niraami/.config/blender/3.3/scripts/addons" ignored
-> "/home/niraami/.config/blender/3.4/scripts/addons" ignored
-> "/home/niraami/.config/blender/3.4/scripts/sketchfab_cache" ignored
-> "/home/niraami/.config/blender/3.5/scripts/addons" ignored
-> "d_blender_addons" ignored

Expected behavior

Files that match the negative ignore pattern should not get ignored.

Additional information I've tried all sorts of other patterns, and different folders, with and/or without globs in the patterns, single and double quotes, but could not get it to work.

Dotdrop's execution with the debug logs (--verbose) with the above config:

$ dotdrop update --dry
...
[DEBUG][dotdrop.dotdrop._dotfile_compare] comparing key:"d_blender_addons", src:"/home/niraami/.dotfiles/user/config/blender", dst:"/home/niraami/.config/blender", link:"nolink", template:True
[DEBUG][dotdrop.utils.patch_ignores] ignores before patching: ['*', '!*/addons/**', '*.dotdropbak']
[DEBUG][dotdrop.utils.patch_ignores] ignores after patching: ['*', '!*/addons/**', '*.dotdropbak']
[DEBUG][dotdrop.templategen.path_is_template] is template: /home/niraami/.dotfiles/user/config/blender
[DEBUG][dotdrop.utils.must_ignore] must ignore? "['/home/niraami/.dotfiles/user/config/blender']" against ['*', '!*/addons/**', '*.dotdropbak']
[DEBUG][dotdrop.utils.must_ignore] ignore "*" match: /home/niraami/.dotfiles/user/config/blender
[DEBUG][dotdrop.utils.must_ignore] trying to match :"/home/niraami/.dotfiles/user/config/blender" with non-ignore-pattern:"*/addons/**"
[DEBUG][dotdrop.utils.must_ignore] ignoring ['/home/niraami/.dotfiles/user/config/blender']
[DEBUG][dotdrop.comparator.compare] comparing /home/niraami/.dotfiles/user/config/blender and /home/niraami/.config/blender
[DEBUG][dotdrop.comparator.compare] ignore pattern(s): ['*', '!*/addons/**', '*.dotdropbak']
[DEBUG][dotdrop.comparator.compare] /home/niraami/.dotfiles/user/config/blender is a directory
[DEBUG][dotdrop.comparator._comp_dir] compare directory /home/niraami/.dotfiles/user/config/blender with /home/niraami/.config/blender
[DEBUG][dotdrop.utils.must_ignore] must ignore? "['/home/niraami/.dotfiles/user/config/blender', '/home/niraami/.config/blender']" against ['*', '!*/addons/**', '*.dotdropbak']
[DEBUG][dotdrop.utils.must_ignore] ignore "*" match: /home/niraami/.dotfiles/user/config/blender
[DEBUG][dotdrop.utils.must_ignore] trying to match :"/home/niraami/.dotfiles/user/config/blender" with non-ignore-pattern:"*/addons/**"
[DEBUG][dotdrop.utils.must_ignore] ignoring ['/home/niraami/.dotfiles/user/config/blender', '/home/niraami/.config/blender']
[DEBUG][dotdrop.comparator._comp_dir] ignoring diff /home/niraami/.dotfiles/user/config/blender and /home/niraami/.config/blender
[DEBUG][dotdrop.dotdrop._dotfile_compare] => compare d_blender_addons: diffing with "/home/niraami/.config/blender"
[DEBUG][dotdrop.dotdrop._dotfile_compare] same file
...

Relevant documentation is here.

deadc0de6 commented 1 year ago

Thanks for reporting this, I was able to reproduce the bug and will investigate!

niraami commented 1 year ago

Hey, I'm glad to see you're still working on this, and I just wanted to mention that I appreciate it. Is there anything I could help with, like testing or small tasks - I don't have much free time, but I'm pretty well versed in Python.

deadc0de6 commented 1 year ago

Hey, sure no problem. I must admit it was more complex than I expected and while searching to solve your issue, I found bugs in negative ignore spanning across other actions (install, compare, update, import). Thanks a lot for your help, I will probably need you once I have something concrete for testing that's for sure. For now it's all good, I'll get there but I appreciate the help!

deadc0de6 commented 1 year ago

@niraami I think I have something in the bug#388 branch. Could you test your use case using that branch?

Here is a little explanation on how to do the testing: https://dotdrop.readthedocs.io/en/latest/howto/test-latest-dotdrop/ You simply then need to switch to the bug#388 branch and point dotdrop.sh to your config file.

niraami commented 1 year ago

Yep, I'll test it as soon as I can.

deadc0de6 commented 11 months ago

@niraami this was merged and is then available on the master branch. Thanks