File watchers are awesome little packages. They can be setup to watch CSS or JS files and automatically merge and minimize them for production deployment. But as I recently learned, they come with their share of problems when you try to automate TOO much.
We use Mercurial for our VCS at work, and I use it personally as well. In my ~/.hgrc file, I keep a few aliases for quick commands. I have a ‘promote’ command that merges changes from my current branch to a target branch, another that tags stable branch changes and signs them with my gpg key and a few others. These aliases are great because they’re typically 3-4 commands just wrapped up into one and go really fast.
The problem I ran into recently was when using my ‘promote’ command, which in short updates to the target branch, merges from the previous branch, then commits the merge. Gulp watch was running in the background, and then the update and merge occurred, watch caught the file changes and started running in the middle of the merge commit, so I ended up with a css file that was empty and a js file that was half complete. This faulty merge made its way to the staging server and showed its ugly head so I was left scratching mine trying to figure out what the hell went wrong.
It wasn’t until I started some RDD (rubber duck debugging) with a coworker that I realized what was happening.
Lesson of the day: turn off file watchers before playing in source control!