Implement .gitignore behavior in a shell script?

I am writing a shell script that syncs files and I want to give users the ability to exclude certain files from syncing by creating a file .syncignore

that looks like a Git file .gitignore

. According to the gitignore documentation and my own experiments, these exclusion rules are more complex than a simple glob match. Some examples:

  • If you have it foo

    in your file .gitignore

    , it excludes foo

    appearing anywhere in the path (for example ./foo

    , ./bar/foo

    and ./bar/foo/baz

    will be excluded), but not partial matches foo

    (for example ./foobar

    , ./bar/foobar/baz

    NOT excluded).
  • If you include the forward slash, then the rule applies to the current directory. For example, if you have /foo

    in your file .gitignore

    , this excludes ./foo

    , but not ./bar/foo

    .
  • You can include wildcards. For example, foo*

    excludes ./foo

    , ./foobar

    and ./bar/foobar/baz

    .

Is there an easy way to replicate the exception rules for .gitignore

in a shell script on OS X?

+3


source to share


1 answer


  • Use rsync

    to sync files. Use existing support for include / exclude. Put the rules in .rsync-filter

    and pass a flag -F

    so that it reads templates from this file.

    rsync man page

  • Just use git

    . Make sure you have git 2.3.0 or newer on both sides and use push-to-deploy .



+4


source







All Articles