Since I use Mercurial and it doesn’t have Xcode integration, I find that I’ll have added classes or whatnot and they will not have been added to the repository and I’ll forget about them come checkin time. That’s bad.
So I thought about ways to remedy this, and after describing the issue to myself, the issue was clear. “When I add new files to the directory, it should run hg add on the files.” Well, when when we need to do something when a directory changes, we use launchd yes? Yes.
So I made a launchd item that ran a script any time my specific repository changed. Since this is just for yourself, it can go in ~/Library/LaunchAgents. The item should set the current and working directories to the repository so the context of the hg commands is proper. Then run the following commands in a script:
hg st | grep '^?' | cut -c'3-258' | xargs hg add
So we get the files that HG hasn’t committed yet (and this excludes files from .hgignore properly), look for files not in the repo, trim the filename off the end, then run hg add on them.
Ta da! New files are automatically added to the repository. Ensure your .hgignore is properly setup and this should always work for you.
Of course you could do this with Subversion with minor changes. I leave that as an exercise to the reader (or a generous commenter).
svn st | grep ‘^?’ | cut -c’8-258’ | xargs svn add
Doesn’t handle files with spaces in their names. Maybe run through
perl -pe 's/\n/\000/'"?Like this:
| grep '^?' \
| cut -c'3-258' \
| perl -pe 's/\n/\000/' \
| xargs -0 hg add