How to add “compare to local history” feature to any *nix system

NOTE: This refers to a Mac install. If you’re on a regular *nix box, this should work even easier w/o as many workarounds…

NOTE2: I need to edit this post. I was writing it while working on the issue and got too busy to really polish it up. When I get some free time, I’ll fix it.

There are some wonderful things about Eclipse. Plugins for just about anything. Some cool svn integration. And one item was the killer feature for me. Right click a file and you can compare to local history. It will list for you every version of the file, which gets created when you hit save.

On the downside with Eclipse, they have no word wrap after years of being asked for it. That’s a killer feature too. And perhaps worse, it’s quite heavy.

I wanted to find the local history in another tool and move to it, but there didn’t seem to be a way to achieve it….

Meantime, a friend of mine suggested trying TextMate. I tried it. Didn’t especially like it. What particularly bothered me was that I had gotten used to diff’ing local history. So I gave up.

As luck would have it, just as I started a new project, the new Eclipse PDT Helios came out. I don’t even remember which feature I “upgraded” for…but it was a disaster. I won’t go into details, but many others are having problems, so Google will tell you all about it.

Meantime, another friend told me he switched to Textmate & decided to give it a week before giving up. That convinced me to try again. And now I “get it”. The command line integration is key!

My setup for the current client project is an svn repository. So I had a bright idea! Why not use git to version every file in the project on save? Just hook Textmate’s save to a git add and commit. While I like this idea, so far I haven’t quite figured out how and the person who said he’d post a method, hasn’t gotten to it yet.

No worries, as I had a different idea that would work for any text editor and be a little more flexible. I’m marking it down here so I can remember it in the future & perhaps give some others the same idea.

Using cron, once a minute, git add and commit all files in the project. Unbeknowest to me, Apple deprecated cron on the Mac when I started writing this…and it took me a fair bit to figure out what went wrong…

Upshot, first set up a git alias like so:

git config --global alias.add-commit '!git add -A && git commit'

Then on the command line, this will git add and commit in one go, with a commit message:

git add-commit -m 'My commit message'

So on cron, I have the following command:
* * * * * (. /Users/YOU/.profile && cd /Users/YOU/Workspace/YOURPROJECT && git add-commit -m 'autocommit') > /Users/YOU/Documents/cronlogs/cronlog-autocommmit.txt 2>&1

Note, that to test the cron, “su -” (iow su to root) and run the commands. That’ll give you an idea if git is in the path, if the alias is set up correctly, etc…

I set up the git alias in both environments. You can see I’m sourcing the .profile as well so root has git in its path….

So now, cron runs every minute. Which means that any save I’ve done will get committed more than frequently enough. I can do a diff on the svn repository….or a local diff on my git repository.

It’s janky, but does the trick and makes me happy 🙂

P.S. I was planning to talk more about Textmate, SmartSVN, GitX, Araxis Merge and whatever other tool I’ll wind up integrating with git diff…however this took me WAAAY longer than I expected and I’m BEAT!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s