I've been running across the problem of keeping a package's "proper" code in lib/ alongside dependencies.
I'd like to check in only my own package code and not vendor deps, using smlpkg sync to pull them on-demand.
It took me quite a long time fighting with git's ignore logic, but I managed to figure out a way to autogenerate a sequence of gitignore directives that let me ignore everything in lib/ apart from the package-proper code.
This is the awk script I use:
printf "lib/github.com/myname/mypackage | awk -F/ '
{ p=$1; for (i=2;i<NF+1;i++) {
p=(p "/" $i);
print "!"p"/";
if (i==NF) print "!"p"/**"
else print p"/*"
}}'
which prints out this sequence of directives:
!lib/github.com/
lib/github.com/*
!lib/github.com/myname/
lib/github.com/myname/*
!lib/github.com/myname/mypackage/
!lib/github.com/myname/mypackage/**
This sequence, when preceded by lib/*, does what I want it to do. Now, even if I issue the command:
it will only add the directory lib/github.com/myname/mypackage and all its contents, but no other children of lib/, at any level of the tree.
I figured this is probably a pattern folks are going to encounter. Would it make sense to add a generator to smlpkg itself to create this list? Perhaps something like:
$ cat sml.pkg
package github.com/myname/mypacakge
require {
github.com/myname/otherpackage 1.2.3
github.com/someorg/somepackage 3.2.1
}
$ smlpkg ignore-lib
lib/*
!lib/github.com/
lib/github.com/*
!lib/github.com/myname/
lib/github.com/myname/*
!lib/github.com/myname/mypackage/
!lib/github.com/myname/mypackage/**
$ smlpkg ignore-lib >> .gitignore
I've been running across the problem of keeping a package's "proper" code in
lib/alongside dependencies.I'd like to check in only my own package code and not vendor deps, using
smlpkg syncto pull them on-demand.It took me quite a long time fighting with git's ignore logic, but I managed to figure out a way to autogenerate a sequence of gitignore directives that let me ignore everything in
lib/apart from the package-proper code.This is the awk script I use:
which prints out this sequence of directives:
This sequence, when preceded by
lib/*, does what I want it to do. Now, even if I issue the command:it will only add the directory
lib/github.com/myname/mypackageand all its contents, but no other children oflib/, at any level of the tree.I figured this is probably a pattern folks are going to encounter. Would it make sense to add a generator to
smlpkgitself to create this list? Perhaps something like:$ cat sml.pkg package github.com/myname/mypacakge require { github.com/myname/otherpackage 1.2.3 github.com/someorg/somepackage 3.2.1 } $ smlpkg ignore-lib lib/* !lib/github.com/ lib/github.com/* !lib/github.com/myname/ lib/github.com/myname/* !lib/github.com/myname/mypackage/ !lib/github.com/myname/mypackage/** $ smlpkg ignore-lib >> .gitignore