Protecting the master branch from you

An ounce of prevention is worth a pound of cure. – Benjamin Franklin

Eighteen new commits on master with questionable commit messages. Yay.

One of the most critical things you do when working with remote git repositories is pushing your changes to master. Once that is done, everyone else can see what you’ve done. And, if you mess that up, everyone sees your mistakes, and fixing it swiftly becomes a trial requiring team-wide coordination and the ugly push --force command. A couple of months ago finally messed that up one too many times, so I decided to use Git’s pre-push hook to protect the master branch from my own mistakes.

Essentially, I wanted Git to put up roadblocks to me pushing to master. The pre-push hook can perform checks and reject a push attempt purely on the client side, so it’s a perfect spot for implementing those roadblocks. I took a hook from this useful page and augmented it. While the original hook merely asks if you’re sure you want to push, I added two more checks, neither of which can be overridden interactively.

  1. A file named “ok-to-push” must exist. If it doesn’t, the hook rejects the push. This forces me to stop for a moment and not sweep right into pushing.
  2. No more than one commit can be pushed. Pushing multiple commits at once is a dead giveaway that I merged in a work-in-progress branch, instead of the polished and tested final branch that should be distributed. There is no way around this check except to do one commit at a time.

I posted the hook as a gist.

Everyone makes mistakes, but this is one mistake I’m happy to make less often. The hook is enforcing a higher level of discipline, and hopefully, in the end, will become obsolete as I adopt better habits.


The Java logging quagmire

I’ve started working on a new Java project, and it uses the popular SLF4J logging framework. I’ve never really had the opportunity to use it before; I’m mostly a Log4j guy with the occasional foray into Apache Commons Logging. SLF4J is highly similar to both of those other frameworks, but I got a bit confused because a dependency of this project, Apache HTTPClient, uses Commons Logging, and so there was this weird JAR to bridge them in there, and then Logback was around too. It was then that I fully realized what a mess the Java logging ecosystem is. This post attempts to detangle it.

Continue reading

Kicking off background jobs over SSH

I needed this information yesterday, as I was trying to use SSH from one machine to start a shell script running in the background on another.

You’re probably using the OpenSSH server, and started a background process on the server which you intended to continue after logging out of the SSH session. Fix: redirect the background process stdin/stdout/stderr streams (e.g. to files, or /dev/null if you don’t care about them).

Works perfectly. So, not this:

ssh remotehost " &"

but this:

ssh remotehost "nohup < /dev/null >script.out 2>script.err &"

This is also needed for pssh.

pssh -h remotehosts.txt "nohup < /dev/null >script.out 2>script.err &"

Programming Font: Inconsolata

Time for another of my favorite programming fonts: Inconsolata.

Inconsolata specimen

Inconsolata specimen from

As its creator states, it bears a resemblance to the Consolas font that ships with more recent Windows versions, and which isn’t all that bad either. This one has a bit of an edge in my opinion: it’s freely available so I’m good to go on my Mac with it.

It’s a bit sharper and bolder than Droid Sans Mono, and the letters are a bit more spaced out. So, based on your mood, I could see using either one. For some reason it also reminds me warmly of the monospaced font Sun would use in their old Java books in the 90’s – probably Vera Sans Mono.

From Dropbox to BitTorrent Sync

I’ve been a fan of Dropbox for years, mainly due to how dead-simple it is to use and how well It Just Works. Lately, Amazon and Google have been trying to move in on the cloud storage game with their own offerings, and of course there’s Box, Ubuntu One, and other systems already competing. Obviously, the ability to sync files across your machines is super-handy.

My main problem with Dropbox has always been how little space you can get. Right now I have 4.42 GB of space in my personal account, over and above the standard free amount due to several referrals and uploading photos and trying Dropquest 2012. It’s a decent amount of space, but … Google Drive kicks you off with 15 GB right away, and Amazon even starts at 5 GB. Box starts you with 10 GB. Dropbox still starts you with just 2 GB.

I would have figured that Dropbox would start bumping things up with the growing competition, but instead their latest announcement was for some sort of photo gallery thing. I mean, I guess they have the whole file sync thing down pat so they need to branch out, but I don’t get how a gallery app is a logical next step. I really want more gigabytes. I could start using the storage in new broad ways.

A while back a friend of mine had me set up BitTorrent Sync in order to transfer some files. Unlike all of those other systems I mentioned, this one has no central server. Instead, your files are shared democratically across all computers you have linked using the same shared secret. As a bonus, all files are encrypted during transport, so that plus the lack of a central server means your files are better protected from anyone who might like to see them without your permission. That’s all fine and good, but what I really care about is that the space is unlimited, since you bring the storage.

So, I’m transitioning from Dropbox to BT Sync. Right now I have two Dropbox accounts, one for work and one for personal use. I’ll have the work one switched over relatively quickly, and the personal one before much longer. I’ll leave the personal one alive for a few isolated items, and as an alternative for cases where BT Sync isn’t as convenient (e.g., web access). Plus, I worked hard for those extra 2.42 GB, dangit.

I have an Ubuntu machine at home, and I installed BT Sync there to take the place of the central server in my scheme. If nothing else, it serves as a backup location for the files in my Sync folders. Although the system really doesn’t need an anchor like that, it helps me transition over. A better option would be to sync to a trusted friend’s systems, which would give me offsite backup. If there were a way to encrypt those copies, it’d be just about perfect.