Fri, 11 May 2012

git diff for Salesforce static resources

Static Resources in Salesforce are often zip files containing multiple files. If you're keeping static resource under version control using git, here's how to get useful diffs for them whether they are zip files or single text files.

Create a shell script which will identify whether a file is a zip file or not. If so, it should unzip the contents to stdout; otherwise, it should just output the contents of the file. I called it resource-conv.

#!/bin/bash

file -b --mime-type $1 | grep application/zip && unzip -c -a $1 || cat $1

Tell git to use this conversion utility for a new "resource" diff driver:

$ git config [--global] diff.resource.textconv resource-conv

Tell your repo that .resource files should use the "resource" diff driver by adding the following to your .gitattributes:

*.resource diff=resource

tech » salesforce | Permanent Link

The state is that great fiction by which everyone tries to live at the expense of everyone else. - Frederic Bastiat