Exclude everything under folder *but* certain filetypes (at any nesting level)

Viewed 231

Using version 2.51.2 (ocaml 4.04.0).

Trying to exclude a folder at the root (called build), but include any files ending in .err and .out at any depth underneath it.

Structure looks like

build/a/b/c/test/1.0/test.out
build/a/d/whatever/2.0/whatever.err
build/a/test.err

I tried

ignore = Path build
ignorenot = Regex·arnold-build\/(.*).(err|out)⬎

... this coughs up a "Malformed pattern" error. Also tried just to sync an entire subdir explicitly with this:

ignorenot = Path a/b/c/test/

But the "test" folder still doesn't sync.

How do I get just all the .err/.out files to sync, while ignoring everything else?

1 Answers

Unison's "ignorenot" preference is somewhat counterintuitive

https://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html#ignore

If a directory is ignored, all its descendents are ignored too, everything below that tree will be ignored and not checked anymore.

Ignorenot only blocks ignores at the same level, so you must cover all the tree, up to the ignorenot you want to apply, with pairs of ignore and ignorenot. For example, in the case you cited above, if you want to ignore everything in build, except build/a/b/c/test, build/a/d/whatever, and everything inside them, your preferences profile should include:

ignore = Path build/*
ignorenot = Path build/a
ignore = Path build/a/*
ignorenot = Path build/a/b
ignorenot = Path build/a/d
ignore = Path build/a/b/*
ignore = Path build/a/d/*
ignorenot = Path build/a/b/c
ignorenot = Path build/a/d/whatever
ignore = Path build/a/b/c/*
ignorenot = Path build/a/b/c/test

This way Unison will ignore everything in the build folder, except for build/a/d/whatever and build/a/b/c/test

Related