Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert .gitignore to rsync merge filter include file? (with sed or awk)

Tags:

git

sed

awk

rsync

I tried using rsync --filter=':+ .gitignore' (-/exclude works but not include) to no avail.

Basically i just want to include the .ignore file in a script and upload everything in it with rsync to the remote.

If anyone would have the skills to sed or awk .gitignore into a file suitable for include with --filter='merge file' etc it would me much appreciated!

Or alternatively a way just to make rsync understand .gitignore for inclusion.

https://www.kernel.org/pub/software/scm/git/docs/gitignore.html 'PATTERN FORMAT'

http://linux.die.net/man/3/fnmatch

https://git.samba.org/?p=rsync.git;a=blob_plain;f=wildtest.txt;hb=HEAD

https://git.samba.org/?p=rsync.git;a=blob_plain;f=wildtest.c;hb=HEAD

Some Issues are in rsync bla/ means just that dir, bla/* means just the files in that dir, bla/** means just everything under that dir (including subdirs) and bla/*** finally means bla and all it's contents but all git might have is bla/

But exclude rules seem compatible.

like image 504
sabgenton Avatar asked Nov 13 '22 04:11

sabgenton


2 Answers

Perhaps something like this: (Again, untested)

git ls-files -oz | rsync --include-from=- --from0
like image 161
Arafangion Avatar answered Nov 15 '22 05:11

Arafangion


I recommend using gsync rather than rsync. I wrote it because:

I have a project with the following characteristics:

  • The .gitignore in the root directory is 60+ lines long
  • There are 4 subdirectories that have with their own .gitignore
  • Some .gitignore files include lines with !-style exceptions

I tried the methods in other answers. Some were promising but ultimately I hit the discarding over-long filter error. So I wrote gsync as a wrapper script for rsync to properly handle .gitignore files (in subdirs, with support for !-style exceptions. I think you'll find it helpful.

like image 41
cobbzilla Avatar answered Nov 15 '22 05:11

cobbzilla